I created a static library (designated A) in Visual Studio that includes some header files from another library (designated B). Because that is a static library I didn't need to worry about the .lib file from A. When I created a console app (designated C) and added the .lib and header files from B as well as the header and .lib files from A. When I try to compile C it comes up with unresolved externals, not related to A, but to B.
I created two more test projects, a static library and a console app. The static library still used A and the console app still used A and the new static library, and it managed to compile fine, even without the header files of A.
I've run through all differences and I can't see any that would stop C from compiling. The only difference is the folder the projects are stored in. I have double-verified the locations of header files and .lib files and they are all there. How would I go about fixing the LNK2001 errors?
EDIT: I realised my post doesn't make much sense but when I try to use my library in another project it won't link at all and I can't see a reason why.
To link with a .lib file, you just need to:
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)
If this issue couldn't be resolved, I suggest you could refer to the Doc:Linker Tools Error LNK2001
Related
I created a c++ library with VS2019
my other projects see and use that library fine, they compile fine
but my library itself cannot be compiled as it complains about missing entry points for a depending lib
I want to add that .lib file, like I did for my other projects
but in the library project settings, there is no linker option, so I cannot tell it to use the missing .lib dependency
how do I resolve this ?
thanks for helping me on this
[edit] strangly enough SDL libraries dont cause any problem (becos of dll's ?) while nfd.lib has no dll
maybe the reason I cannot link my library with static libraries ?
image
but my library itself cannot be compiled as it complains about missing entry points for a depending lib
The library project can only be built but not compiled. After you finish building the .lib project, you will get a .lib file like this in the debug folder. And then you could add it to your C++ project.
According to your description, If you want to add a .lib to a .lib project? If so, I suggest you could try to add the name of the .lib file with its extension to Additional Dependencies. Librarian -> General -> Additional Dependencies. Here is the equivalent of linker input. And then add the path to the .lib file to the Additional Library Directories. Librarian -> General -> Additional Library Directories.Here is the equivalent of linker General.
I would like to use Gurobi in a C++ project I have in Eclipse. I tried multiple manuals/tutorials (including THIS on how to do the same in Visual Studio) to add the hook up the Gurobi files with Eclipse/GCC, but I just couldn't make it work. I feel like I don't understand enough how these things should work in the first place.
In my Gurobi folder I have 3 folders, that in my opinion are important: include (with .h files), lib (with .lib files and NO .so or .a files) and src (with .cpp & .h files).
include: I added the path to this folder to C/C++ Build -> Settings -> GCC C++ Compiler -> Includes -> Include paths, I guess this is for the compiler to see the .h files. I also added it to C/C++ General -> Paths and Symbols -> Includes -> Include directories, I guess this is for the linker to see the .h files.
lib: I first added the folder path to C/C++ Build -> Settings -> MinGW C++ Linker -> Libraries -> Libraries (-l), however after searching online it seems to me this option only works for libraries with standard names and extensions. It also gave me the error ld.exe: cannot find -lc:/gurobi900/win64/lib/, so I deleted it and added the two .lib file paths separately to Miscellanous -> Other objects.
I got to the point where #include "gurobi_c++.h" works, however, already Eclipse underlines a line where I am defining a GRBEnv() object, that is declared in include/gurobi_c++.h, but defined in src/cpp/Env.cpp. Also if I try to compile, I get undefined reference errors. This means neither the Linker nor the Compiler can see the definition of GRBEnv().
Is there a way to tell the linker/compiler where the .cpp files are? Is it happening automatically, based on the path of the include folder? Am I supposed to link the .lib or the .cpp files?
I would greatly appreciate even if someone just pointed out mistakes in my understanding.
I would like to use Gurobi in a C++ project I have in Eclipse. I tried multiple manuals/tutorials (including THIS on how to do the same in Visual Studio) to add the hook up the Gurobi files with Eclipse/GCC, but I just couldn't make it work. I feel like I don't understand enough how these things should work in the first place.
In my Gurobi folder I have 3 folders, that in my opinion are important: include (with .h files), lib (with .lib files and NO .so or .a files) and src (with .cpp & .h files).
include: I added the path to this folder to C/C++ Build -> Settings -> GCC C++ Compiler -> Includes -> Include paths, I guess this is for the compiler to see the .h files. I also added it to C/C++ General -> Paths and Symbols -> Includes -> Include directories, I guess this is for the linker to see the .h files.
lib: I first added the folder path to C/C++ Build -> Settings -> MinGW C++ Linker -> Libraries -> Libraries (-l), however after searching online it seems to me this option only works for libraries with standard names and extensions. It also gave me the error ld.exe: cannot find -lc:/gurobi900/win64/lib/, so I deleted it and added the two .lib file paths separately to Miscellanous -> Other objects.
I got to the point where #include "gurobi_c++.h" works, however, already Eclipse underlines a line where I am defining a GRBEnv() object, that is declared in include/gurobi_c++.h, but defined in src/cpp/Env.cpp. Also if I try to compile, I get undefined reference errors. This means neither the Linker nor the Compiler can see the definition of GRBEnv().
Is there a way to tell the linker/compiler where the .cpp files are? Is it happening automatically, based on the path of the include folder? Am I supposed to link the .lib or the .cpp files?
I would greatly appreciate even if someone just pointed out mistakes in my understanding.
Somehow, even after going through a lot of materials, I could not understand one thing. I have a c++ library project in Visual Studio 2013. When I build it, it creates *.lib file. Now, there is another project where I need to link the .lib file. I created a folder called lib, dumped the .lib file in there and set the path of the lib folder to Properties->Linker->General->Additional Library Directories. Next I added the library file name *.lib in Properties->Linker->Input->Additional Dependencies. Now, building the project throws huge list of linker errors with message unresolved external symbol .... What is that I need to do more for linking the library?
I'm not sure what's the language your "another project" used, anyway, you should specifically set your *.lib file in Linker->Input->Additional Dependencies if you didn't explicitly load it in code.
If the both projects reside in the same solution the simplest option is to right-click of the project, go to to Properties, there go to Common Properties and in Framework and References add a reference to that library project. This will set the linker to link the .lib and adds a build dependency so the lib is always compiled before the executable.
I am a beginner on C++ and trying to learn about including libraries, and I haven't found documentation about it.
What are the ways of including libraries to a C++ project (Visual Studio). How do I implement them and which is the best way?
I was trying to include the SQLite library to a project. I tried to:
Include the header file in the include folder of the Visual Studio installation folder. It did appear in the External dependencies of my project, so I can do #include <sqlite3.h> without problems, but I don't know where I should put the implementation (a C file) and how to link it (is it in the linker>Input>Additional dependencies?).
Is it necessary that in order to include a library the file should be a .lib? Because I can't find the .lib for SQLite 3, do I have to include it in the lib folder of my Visual Studio installation?
Note: I am interested on the management of including a library in general. The SQLite 3 part is only because I took it as an example in order to learn how to add them.
A library is added in two steps
Adding headers path to the project
Adding .lib reference
In the first step, you must specify in the project where library headers are header. Usually, the path is specified in the project properties -> C++ -> Additional include directories, and them including files with relative paths.
In the second step you must specify in properties->linker the path where libraries (.lib) are located and the name of the library. With this Visual Studio is able to link the project properly.
go to project add existing item you must then select from the browse screen the .lib file you wish to add. and BINGO it is there!
best wishes
david