how to access member functions and variables in another project without .lib
-
Hi All , I have the below declaration in say abc.h and implementation of the member function in abc.cpp in Project A. How can I call/access some of this member functions in project B and Project C without including the A.lib in Project B and Project C? As is I am getting linker error from project B and C class __declspec(dllimport) B { public: B(); static B* Ptr1(); static int fn1(D* ptr2); D * fn2(); private: static int Result; static map map1; }; class __declspec(dllimport) C { public: C(); static C* Ptr1(); static int Fn4(const string& str1); static int Fn6(const string &str3, B* ptr4); static B* Fn7(string &str4); static bool isBoolEnabled() { return Boolean;} static void SetBoolean(bool bArg) {Boolean = bArg; } private: static map map3 ; static map map4; static bool Boolean; }; class __declspec(dllimport) D { vector Token1; vector Token2; vector Token3; }
-
Hi All , I have the below declaration in say abc.h and implementation of the member function in abc.cpp in Project A. How can I call/access some of this member functions in project B and Project C without including the A.lib in Project B and Project C? As is I am getting linker error from project B and C class __declspec(dllimport) B { public: B(); static B* Ptr1(); static int fn1(D* ptr2); D * fn2(); private: static int Result; static map map1; }; class __declspec(dllimport) C { public: C(); static C* Ptr1(); static int Fn4(const string& str1); static int Fn6(const string &str3, B* ptr4); static B* Fn7(string &str4); static bool isBoolEnabled() { return Boolean;} static void SetBoolean(bool bArg) {Boolean = bArg; } private: static map map3 ; static map map4; static bool Boolean; }; class __declspec(dllimport) D { vector Token1; vector Token2; vector Token3; }
Assuming that you are using Windows and that the code to be called is in a DLL, look at the LoadLibrary () and the GetProcAddress () APIs.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill
-
Hi All , I have the below declaration in say abc.h and implementation of the member function in abc.cpp in Project A. How can I call/access some of this member functions in project B and Project C without including the A.lib in Project B and Project C? As is I am getting linker error from project B and C class __declspec(dllimport) B { public: B(); static B* Ptr1(); static int fn1(D* ptr2); D * fn2(); private: static int Result; static map map1; }; class __declspec(dllimport) C { public: C(); static C* Ptr1(); static int Fn4(const string& str1); static int Fn6(const string &str3, B* ptr4); static B* Fn7(string &str4); static bool isBoolEnabled() { return Boolean;} static void SetBoolean(bool bArg) {Boolean = bArg; } private: static map map3 ; static map map4; static bool Boolean; }; class __declspec(dllimport) D { vector Token1; vector Token2; vector Token3; }
-
You have declared the classes as
dllimport
so you must add the .lib file to your linker section in your build. -
Assuming that you are using Windows and that the code to be called is in a DLL, look at the LoadLibrary () and the GetProcAddress () APIs.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill
-
Thank you Richard !.. The order I am compiling the different projects(.lib) cannot be changed. First project referencing member functions from other project that was not even compiled..so other than getprocaddress() , no better option ?
-
I think he is trying to tell you he has got a circular dependancy problem.
In vino veritas
-
Hi All , I have the below declaration in say abc.h and implementation of the member function in abc.cpp in Project A. How can I call/access some of this member functions in project B and Project C without including the A.lib in Project B and Project C? As is I am getting linker error from project B and C class __declspec(dllimport) B { public: B(); static B* Ptr1(); static int fn1(D* ptr2); D * fn2(); private: static int Result; static map map1; }; class __declspec(dllimport) C { public: C(); static C* Ptr1(); static int Fn4(const string& str1); static int Fn6(const string &str3, B* ptr4); static B* Fn7(string &str4); static bool isBoolEnabled() { return Boolean;} static void SetBoolean(bool bArg) {Boolean = bArg; } private: static map map3 ; static map map4; static bool Boolean; }; class __declspec(dllimport) D { vector Token1; vector Token2; vector Token3; }
How to solve circular dependency in linker is shown here Library order in static linking - Eli Bendersky's website[^] The trick is to organize the library files as shown and link them twice which is perfectly valid. I assume that is the reason you are trying to avoid including the library file.
In vino veritas