Referencing lib file
-
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
-
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
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:
-
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:
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. :) -
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. :)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
ThirdPartyLibFolderThen 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:
-
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
ThirdPartyLibFolderThen 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:
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.
-
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.
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:
-
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. :)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 asC:\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 addC:\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.
-
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 asC:\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 addC:\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.
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.