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. Referencing lib file

Referencing lib file

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcsharpvisual-studiotesting
8 Posts 3 Posters 1 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.
  • C Offline
    C Offline
    Christian Flutcher
    wrote on last edited by
    #1

    I have downloaded a unit testing framework which is written in standard C++. I have the source as well as a "lib" file. Is it possible to use that "lib" file in my CPP file instead of copying that framework source to my application directory. I have added the "lib" file path in the visual studio's directory search path, but still it is complaining that the header files are missing. This error will disappear if I copy the framework's source files to my application directory. So is there any way to use the lib file in my project? Any help would be great

    M 1 Reply Last reply
    0
    • C Christian Flutcher

      I have downloaded a unit testing framework which is written in standard C++. I have the source as well as a "lib" file. Is it possible to use that "lib" file in my CPP file instead of copying that framework source to my application directory. I have added the "lib" file path in the visual studio's directory search path, but still it is complaining that the header files are missing. This error will disappear if I copy the framework's source files to my application directory. So is there any way to use the lib file in my project? Any help would be great

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      The lib file may have the compiled object code from the source code, but you will need to #include the header files in any of your source modules that use code from the library. That doesn't mean you have to copy source into your project folder. You can use a path in your #include directives. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      C 1 Reply Last reply
      0
      • M Mark Salsbery

        The lib file may have the compiled object code from the source code, but you will need to #include the header files in any of your source modules that use code from the library. That doesn't mean you have to copy source into your project folder. You can use a path in your #include directives. Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        C Offline
        C Offline
        Christian Flutcher
        wrote on last edited by
        #3

        Yes that helped a lot. I solved the problem. It happened because of my lack of knowledge on how linker works. To solve this, I have taken "Project Properties -> Linker -> Input" and added my library name in "Additional dependencies". Header file is written like the following

        #include "c:\somepath\someheader.h"

        I can copy the someheader.h to my application directory, but this file is a facade header file which contains includes to several other files. So compiler is complaining about those missing ones. Is it a good practice to give fully qualified path for the includes? Thanks Mark for helping me. Have a great week ahead. :)

        M J 2 Replies Last reply
        0
        • C Christian Flutcher

          Yes that helped a lot. I solved the problem. It happened because of my lack of knowledge on how linker works. To solve this, I have taken "Project Properties -> Linker -> Input" and added my library name in "Additional dependencies". Header file is written like the following

          #include "c:\somepath\someheader.h"

          I can copy the someheader.h to my application directory, but this file is a facade header file which contains includes to several other files. So compiler is complaining about those missing ones. Is it a good practice to give fully qualified path for the includes? Thanks Mark for helping me. Have a great week ahead. :)

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Christian Flutcher wrote:

          Is it a good practice to give fully qualified path for the includes?

          I personally don't like fully qualified pathnames because it may cause a problem when I move a project to another computer or a different drive. I also don't like copying third-party source to my project's folder. I like to arrange my project folders so I can use relative paths, something like

          SolutionFolder
          ProjectAFolder
          ProjectBFolder
          ProjectCFolder
          ThirdPartyLibFolder

          Then if a source file in project A needs to reference a ThirdPartyLib header file:

          #include "..\ThirdPartyLibFolder\someheader.h"

          That way the entire solution folder tree can be freely moved around without having to change source code. You can also use relative paths to reference the .lib :)

          Christian Flutcher wrote:

          Have a great week ahead.

          Thank you! You too!

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          C 1 Reply Last reply
          0
          • M Mark Salsbery

            Christian Flutcher wrote:

            Is it a good practice to give fully qualified path for the includes?

            I personally don't like fully qualified pathnames because it may cause a problem when I move a project to another computer or a different drive. I also don't like copying third-party source to my project's folder. I like to arrange my project folders so I can use relative paths, something like

            SolutionFolder
            ProjectAFolder
            ProjectBFolder
            ProjectCFolder
            ThirdPartyLibFolder

            Then if a source file in project A needs to reference a ThirdPartyLib header file:

            #include "..\ThirdPartyLibFolder\someheader.h"

            That way the entire solution folder tree can be freely moved around without having to change source code. You can also use relative paths to reference the .lib :)

            Christian Flutcher wrote:

            Have a great week ahead.

            Thank you! You too!

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            C Offline
            C Offline
            Christian Flutcher
            wrote on last edited by
            #5

            Mark Salsbery wrote:

            I also don't like copying third-party source to my project's folder.

            Yeah. But looks like we can't avoid copying them to the solution folder.

            M 1 Reply Last reply
            0
            • C Christian Flutcher

              Mark Salsbery wrote:

              I also don't like copying third-party source to my project's folder.

              Yeah. But looks like we can't avoid copying them to the solution folder.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Christian Flutcher wrote:

              can't avoid

              "Can't"? I guess if you don't mind someone else's code mixed in with yours... Whatever works for you :) I also use some SDKs from Microsoft, which aren't installed in my solution folder tree. For those I add the appropriate paths to the Visual Studio project directories settings so they are available to all projects. My main goal is to not have absolute paths in source code - it's a pain to change them later....not good for maintainability.

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              1 Reply Last reply
              0
              • C Christian Flutcher

                Yes that helped a lot. I solved the problem. It happened because of my lack of knowledge on how linker works. To solve this, I have taken "Project Properties -> Linker -> Input" and added my library name in "Additional dependencies". Header file is written like the following

                #include "c:\somepath\someheader.h"

                I can copy the someheader.h to my application directory, but this file is a facade header file which contains includes to several other files. So compiler is complaining about those missing ones. Is it a good practice to give fully qualified path for the includes? Thanks Mark for helping me. Have a great week ahead. :)

                J Offline
                J Offline
                Jijo Raj
                wrote on last edited by
                #7

                Christian Flutcher wrote:

                I can copy the someheader.h to my application directory, but this file is a facade header file which contains includes to several other files. So compiler is complaining about those missing ones. Is it a good practice to give fully qualified path for the includes?

                You should not use hardcoded path in your source. Assume if you go to another machine and there the headers exist in another directory, either you've to edit the source or copy the headers to hardcoded path. Well, the solutions are as follows. Solution 1 1) Include the header by just filename - #include "someheader.h" 2) Declare an environment variable - SOME_HEADER_PATH with path as C:\Somepath. 3) Restart visual studio IDE for making the new env var in effect. 4) Take Visual Studio project settings, C/C++ tab, Preprocessor settings category. 5) In "Additional include directories" add - $(SOME_HEADER_PATH). 6) Now recompile the project. Here you've moved the directory dependency to an external env var. And if you move to some other machine, just make sure that the env var in that machine holds the right path to your Somepath. Solution 2 1) Include the header by just filename - #include "someheader.h" 2) Take menu, Tools > Options > Directories tab. 3) Now add C:\somepath to the include directory search list. 4) you are done. Well, depends on your requirement choose the best. Well, I recommend the first. :) Regards, Jijo.

                _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

                C 1 Reply Last reply
                0
                • J Jijo Raj

                  Christian Flutcher wrote:

                  I can copy the someheader.h to my application directory, but this file is a facade header file which contains includes to several other files. So compiler is complaining about those missing ones. Is it a good practice to give fully qualified path for the includes?

                  You should not use hardcoded path in your source. Assume if you go to another machine and there the headers exist in another directory, either you've to edit the source or copy the headers to hardcoded path. Well, the solutions are as follows. Solution 1 1) Include the header by just filename - #include "someheader.h" 2) Declare an environment variable - SOME_HEADER_PATH with path as C:\Somepath. 3) Restart visual studio IDE for making the new env var in effect. 4) Take Visual Studio project settings, C/C++ tab, Preprocessor settings category. 5) In "Additional include directories" add - $(SOME_HEADER_PATH). 6) Now recompile the project. Here you've moved the directory dependency to an external env var. And if you move to some other machine, just make sure that the env var in that machine holds the right path to your Somepath. Solution 2 1) Include the header by just filename - #include "someheader.h" 2) Take menu, Tools > Options > Directories tab. 3) Now add C:\somepath to the include directory search list. 4) you are done. Well, depends on your requirement choose the best. Well, I recommend the first. :) Regards, Jijo.

                  _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

                  C Offline
                  C Offline
                  Christian Flutcher
                  wrote on last edited by
                  #8

                  Jijo, That was brilliant answer. It helped a lot. I followed the solution 1 and it worked like a charm! :) Appreciate your help.

                  Jijo raj wrote:

                  http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

                  WOW! great blog. I like the images you added there.

                  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