Cannot open lib unless I manually copy it in my project - c++

When trying to import an external library from a different drive I keep getting error LNK1104 "cannot open foo.lib"
I set up the correct paths in:
Properties -> Configuration Properties -> VC++ Directories -> Include Directories
Properties -> Configuration Properties -> VC++ Directories -> Library Directories
Properties -> Configuration Properties -> C/C++ -> General -> Additional Include Directories
Properties -> Configuration Properties -> Linker -> General -> Additional Library Directories
And the correct .lib filename including extension in:
Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies
This still gives me the error and the only way I have found to fix it is to manually copy the .lib (or .dll) file inside my project, by copying it the linker can find it and link it correctly.
Pretty much all the questions I have found on SO say to set the correct paths and filename of the .lib like I did, why this is not working and I have to directly copy the .lib file inside my project directory to have it work?

According to the Error LNK1104, as far as I'm concerned the cause of this issue is that the compiler couldn't search the directory of the .lib file.
To fix a path issue, we should verify that the LIB environment variable is set and contains all the directories for the libraries you use, for every configuration you build. In the IDE, the LIB variable is set by the Library Directories property on the VC++ Directories Property Page.
If the static library is not part of the solution,In the VC++ Directories property page, I suggest you should try to add the path to the directory where the .lib file is located in Library Paths.
For more details ,I suggest you could refer to the link.

Related

How do I add a library from another branch in VS

My task is to make myself familiar with a given code which also includes a dll and a lib file. I tried the advice given in this post : How to add additional libraries to Visual Studio project? but apparently the lib file I included cannot be opened. I tried to include it at the linker, as suggested in the other post and then tried the file name as well as the entire path at "additional dependencies" but neither of them worked. Any suggestions?
For more details about how to link the .lib, I suggest you could follow the following steps:
1,Add the path to the header file to the Additional Include Directories(property - >c/c++ -> General -> Additional Include Directories)
2,Add the path to the .lib file to the Additional Library Directories (property -> linker -> General -> Additional Library Directories)
3,Add the name of the .lib file with its extension to Additional Dependencies (property -> linker -> input -> Additional Dependencies)
You also need to make sure that you add the configuration properties to the correct build target and platform for your code.
For example:
I suggest you could select "All Platforms" for the platform and select "All Configurations" for the Configuration when changing the properties.

VS2019 linux cannot find additional dependencies

I am doing a remote C++ build from VS2019 to a machine with Centos. When I input the library to the option additional dependencies, the vs2019 always shows g++ : error : libTest.a: No such file or directory , the file libTest.a is a library I wrote to test my solution.
You should properly configure you VSLinux environment.
First, add additional include directory on Properties -> C/C++ -> General -> Additional include directory. Add paths of directories for additional header files for your library.
Second, add additional library directory on Properties -> Linker -> General -> Additional library directory. Add directories where your static/shared libraries are.
Third, put your name of libraries on Properties -> Linker -> Input -> Library dependency. Add the name of your library. Remember, you should remove prefix lib and the extension of the library.
The exact name of the option may differ since I'm not using VS2019 in English.

Linking errors when adding LibXML2 to project

I'm trying to add libxml2 to my c++ project in visual studio but when I attempt to build the project I get about 30 or so linking errors like the following
I know this is a pretty vague question, but can anyone point out what direction I should look to solve these errors?
Have you pointed the linker to the libxml2.lib file?
In Visual Studio it can be done in the project properties -
Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies.
The path for the lib file can be specified in -
Project -> Properties -> Configuration Properties -> Linker -> General -> Additional Library Directories.
I strongly doubt you downloaded the libxml2 for linux not for windows, please double check that.
In
Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies
you have to add the
.dll.a
files ONLY, no .a, .dll or .la files.
Then in the execution directory, the .dll files must be present. (Or SymLink'ed.)

Cannot open file 'glew32.lib'

I have downloaded glew-1.9.0.zip built the projects under C:\glew-1.9.0\build\vc6 and C:\glew-1.9.0\build\vc10 and am unable to build after setting visual studio's paths to the glew include and lib paths. The lib directory does NOT have glew32.lib after building glew. What must I do in order to be able to build an opengl project?
You could download binary pack (32 bit or 64 bit) and find already compiled version of glew32.lib in lib folder and all includes?:)
In your OpenGL project open Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies -> add glew32.lib.
Also you must include #include <GL/glew.h> in your sources;
For that add path to your glew folder: Project -> Properties -> Configuration Properies -> General -> VC++ Directories -> Include Directories and Library Directories;

How do files get into the External Dependencies in Visual Studio C++?

I wonder why one of my projects has VDSERR.h listed under "External Dependencies" and another hasn't and gives me an "undefined symbol" compiler error about a symbol which is defined in there. How can I include this file in the other project as well?
The External Dependencies folder is populated by IntelliSense: the contents of the folder do not affect the build at all (you can in fact disable the folder in the UI).
You need to actually include the header (using a #include directive) to use it. Depending on what that header is, you may also need to add its containing folder to the "Additional Include Directories" property and you may need to add additional libraries and library folders to the linker options; you can set all of these in the project properties (right click the project, select Properties). You should compare the properties with those of the project that does build to determine what you need to add.
To resolve external dependencies within project. below things are important..
1. The compiler should know that where are header '.h' files located in workspace.
2. The linker able to find all specified all '.lib' files & there names for current project.
So, Developer has to specify external dependencies for Project as below..
1. Select Project in Solution explorer.
2 . Project Properties -> Configuration Properties -> C/C++ -> General
specify all header files in "Additional Include Directories".
3. Project Properties -> Configuration Properties -> Linker -> General
specify relative path for all lib files in "Additional Library Directories".