How do I add a library from another branch in VS - c++

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.

Related

How do I add linker commands to Microsoft Visual Studio project?

I am writing a short program that uses the MPIR (Multiple Precision Integers and Rationals) library. In the manual it states that your program must link against the following library, and that the command would look something like this on a typical Unix system:
g++ mycxxprog.cc -lmpirxx -lmpir
How do I do this for Microsoft Visual Studio 2019? Is there something simple in the Linker project settings where I can just add a command like this? Sorry if this has been asked before, but it's just too technical for me to understand at this point, and I'm just trying to do some homework. I also can't find any tutorials explaining this.
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)
For more details I suggest you could refer to the link: https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-static-library-cpp?view=msvc-160&viewFallbackFrom=vs-2019#UseLibInApp

Linking .lib and .h files (OpenJDK 1.8)

I have a project, that includes jni.h and jvmti.h files
here
theese files are stored in jdk8 folder (already installed on my pc)
here
but the main problem - i dont know how can i correctly link jdk libs and .h files to my visual studio prj
I suggest you could follow the following steps to link the static library:
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)

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.

Cannot open lib unless I manually copy it in my project

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.

Where is Visual Studio source file directory change option

I've been trying for hours to change the source path. I couldn't find anything on project properties, and I couldn't find anything on the internet either.
I want to put all my source files in a directory named "src"
like $mysolution-path)/src and I also want to put library files in the /lib directory, but I can't do it.
Where is this option? Is there an option like this. I want to keep my work clean and tidy, but it seems like it's impossible in Visual Studio unlike in IntelliJ IDE.
One way of doing it:
remove your files from the VS project
move the files in explorer
add the files to the VS project
In Project properties -> Configuration Properties -> C/C++ -> General there is the voice: "Additional Include Directories". You can specify there all the folders you are using for your project, thus you just need to create the folders you need manually and then add the paths there.
About lib files, under Project properties -> Configuration Properties -> Linker -> General there is the voice: Additional Library Directories. Just add there the paths to the lib folders.