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. how to access member functions and variables in another project without .lib

how to access member functions and variables in another project without .lib

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++graphicshelptutorial
8 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.
  • K Offline
    K Offline
    kamal1977
    wrote on last edited by
    #1

    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; }

    D L L 3 Replies Last reply
    0
    • K kamal1977

      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; }

      D Offline
      D Offline
      Daniel Pfeffer
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • K kamal1977

        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; }

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You have declared the classes as dllimport so you must add the .lib file to your linker section in your build.

        K 1 Reply Last reply
        0
        • L Lost User

          You have declared the classes as dllimport so you must add the .lib file to your linker section in your build.

          K Offline
          K Offline
          kamal1977
          wrote on last edited by
          #4

          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 ?

          L 1 Reply Last reply
          0
          • D Daniel Pfeffer

            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

            K Offline
            K Offline
            kamal1977
            wrote on last edited by
            #5

            Thank you Daniel for the thoughts.. I am exploring other option due to the order I build the .lib gives linker error...if other option does not pan out I will go with your suggestion.. This was helpful..!

            1 Reply Last reply
            0
            • K kamal1977

              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 ?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              That makes no sense at all. Build the lib project first or waste your time.

              L 1 Reply Last reply
              0
              • L Lost User

                That makes no sense at all. Build the lib project first or waste your time.

                L Offline
                L Offline
                leon de boer
                wrote on last edited by
                #7

                I think he is trying to tell you he has got a circular dependancy problem.

                In vino veritas

                1 Reply Last reply
                0
                • K kamal1977

                  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; }

                  L Offline
                  L Offline
                  leon de boer
                  wrote on last edited by
                  #8

                  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

                  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