Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Unresolved external symbol in a DLL

Unresolved external symbol in a DLL

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
23 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Stuart Dootson

    I have an awful lot of deployed code that uses this mechanism - here's a sample: #if!defined(COMMONLIB_API) #ifdef COMMONLIB_EXPORTS #define COMMONLIB_API __declspec(dllexport) #else #define COMMONLIB_API __declspec(dllimport) #endif #endif namespace MyAppLibrary { class MessageReporter { public: //ctor COMMONLIB_API MessageReporter(); //Add new reporting function COMMONLIB_API static void AddReportFunction(ReportFnPtr func); //Set MessageReporter Level on or off COMMONLIB_API static void SetReporterLevel(Level lev, bool on); //Set all levels to on COMMONLIB_API static void AllLevelsOn() {repLevels=~0;} //Set all levels to off COMMONLIB_API static void AllLevelsOff() {repLevels=0;} }; }; Is it possible you haven't exported necessary constructors?

    G Offline
    G Offline
    George_George
    wrote on last edited by
    #21

    But if you only expose class not expose methods, the methods could not be found when linking the client of the DLL (link error, unresolved symbols related to the methods). Could you have a try? I have tried. regards, George

    S 1 Reply Last reply
    0
    • G George_George

      But if you only expose class not expose methods, the methods could not be found when linking the client of the DLL (link error, unresolved symbols related to the methods). Could you have a try? I have tried. regards, George

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #22

      DLL interface defined in a.h

      a.h

      #if !defined(__A_H__) #define __A_H__ #if!defined(A_API) #ifdef A_EXPORTS #define A_API __declspec(dllexport) #else #define A_API __declspec(dllimport) #endif #endif class A_API A { public: A(); A(int a); void DoSomething(int b); int Result() const; private: int a_; }; #endif // !defined(__A_H__) DLL implemented in a.cpp and built with cl -EHsc -LD a.cpp

      a.cpp

      #include <windows.h> #define A_EXPORTS #include "a.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } A::A() : a_(0) {} A::A(int a) : a_(a) {} void A::DoSomething(int b) { a_ += b; } int A::Result() const { return a_; }
      DLL used in b.cpp, built with cl -EHsc b.cpp a.lib:

      b.cpp

      #include <iostream> #include "a.h" int main(int argc, char** argv) { A a(argc); a.DoSomething(3); std::cout << a.Result() << std::endl; } Builds fine, runs OK and even produces the right result...which is nice.

      modified on Saturday, December 20, 2008 6:19 AM

      G 1 Reply Last reply
      0
      • S Stuart Dootson

        DLL interface defined in a.h

        a.h

        #if !defined(__A_H__) #define __A_H__ #if!defined(A_API) #ifdef A_EXPORTS #define A_API __declspec(dllexport) #else #define A_API __declspec(dllimport) #endif #endif class A_API A { public: A(); A(int a); void DoSomething(int b); int Result() const; private: int a_; }; #endif // !defined(__A_H__) DLL implemented in a.cpp and built with cl -EHsc -LD a.cpp

        a.cpp

        #include <windows.h> #define A_EXPORTS #include "a.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } A::A() : a_(0) {} A::A(int a) : a_(a) {} void A::DoSomething(int b) { a_ += b; } int A::Result() const { return a_; }
        DLL used in b.cpp, built with cl -EHsc b.cpp a.lib:

        b.cpp

        #include <iostream> #include "a.h" int main(int argc, char** argv) { A a(argc); a.DoSomething(3); std::cout << a.Result() << std::endl; } Builds fine, runs OK and even produces the right result...which is nice.

        modified on Saturday, December 20, 2008 6:19 AM

        G Offline
        G Offline
        George_George
        wrote on last edited by
        #23

        Cool, Stuart! regards, George

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups