LNK1104 for unneeded library - c++

I am trying to include the Boost Library in my OpenFrameworks project, in particular it is
When I add the boost root directory to the Additional Include Directories of a new project, I see the error LNK1104 cannot open file 'libboost_filesystem-vc141-mt-gd-x32-1_72.lib', although I don't even need the filesystem library.
However, when I added the boost root directory to the Additional Include Directories of a freshly create c++ console project, the error does not show, and I can make use of the library without problems.
Runtime Library is /MDd.
What might cause this problem? A broken build of boost?
One

Taken from the comments to the question. Although this is unusual it could be that a header in one of the dependencies of your project has the same name as a header in the filesystem library. And since you put boost first in the Additional Include Directories the boost header was included instead of a header from a different library. By default with Visual Studio boost automatically inserts link commands using a #pragma comment(lib, libname) so including this header will cause a link dependency.
A solution to try in this case is to move boost to the end of the Additional Include Directories so when the compiler searches for the header it will find the one from the previous dependency first.

Related

How do I include libraries to a project in Visual Studio?

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

How do I include Boost libraries?

I'm trying to incorporate the Boost libraries into my program, specifically lexical_cast and geometry. I include them using #include"boost/boost/geometry.hpp" and #include"boost/boost/lexical_cast/lexical_cast_old.hpp".
When I run the code I get the fatal error "Cannot open include file: 'boost/geometry/geometry.hpp': No such file or directory" which leads me to another .hpp file in the Boost library which includes another library, but uses #include<...> instead of #include"...".
When I replace it for "..." the error for this one goes, but it is replaced with the next library included using #include<...> instead of #include"...".
I feel like this could lead me down a rabbit hole of replacing nearly all instances of #include<...> with #include"..." which would take ages. Is there a setting I can change or a piece of code I could include that would sort this out?
Or could I just get rid of all the other unnecessary libraries and change the ones I need (I know that, that would still be a lot as they seem to rely on each other).
I have Boost library version 1.58.0.
First you should read about the difference between #include "filepath" and #include <filepath> here.
Personally, I'm working with Boost from Visual Studio as follows:
Go to Project properties → C/C++ → General → Additional Include Directories, and add a path to the boost library root (in my case C:\Program Files (x86)\Boost_1_53).
Include a .hpp file in your sources, like #include <boost/lexical_cast/lexical_cast_old.hpp>
If you're using non headers-only libraries you should also add path to Boost libraries in Project properties → Linker → General → Additional Libraries Directories.
In Visual Studio 2012, right-click on your project and select "Properties".
In the properties dialog, select "Configuration Properties" and then "VC++ Directories".
You will need to add the Boost include path to the "Include Directories" list.
If you're using all header-only libraries then you're done. Otherwise, you will need to add the Boost library path to "Library Directories".
For example:
Boost library - c:\boost\boost_1_58_0 (run booststrap.bat and b2 as administrator).
Add strings $(THIRD_PARTY)\boost\boost_1_58_0\include and $(THIRD_PARTY)\boost\boost_1_58_0\ to VC++ Directories → Include Directories

Having trouble when trying to include boost.serialization into my VS project

So i want to get Boost.serialization into my project but i just want that library from the boost package that you get. I built the boost thing so got i got access to the .lib files for the serialization library.
The ones i got are;
libboost_serialization-vc100-mt-1_55
libboost_serialization-vc100-mt-gd-1_55
libboost_wserialization-vc100-mt-1_55
libboost_wserialization-vc100-mt-gd-1_55
I took these and put them into a new folder and linked my VS project to these files to the additional lib directory.
I also took serialization folder from the boost package and put it in my include folder that is linked to my project.
When i now try to build my app i get these errors;
IntelliSense: cannot open source file "boost/config.hpp"
IntelliSense: cannot open source file "boost/operators.hpp"
IntelliSense: namespace "boost" has no member class "totally_ordered1"
How should i go about to fix these errors? Do i need to add all the .hpp files that the library wants or is there another way around this?
Thanks :)
You mentioned that you built boost and then moved some of the headers into your project. The latter is not advisable - leave the boost includes and libraries where you've installed them and built boost.
In Project ⇒ Properties ⇒ Configuration Properties, add
The toplevel boost directory to the Include Directories (eg., c:\boost)
The directory with the built boost libraries to the Library Directories (eg., c:\boost\lib)
If you still get IntelliSense errors after that add
The "$(ProjectDir)" to the Reference Directories

Issues with including headers from static library

I may be just missing something, but I'm trying to include a MongoDB C++ driver library build into my DLL project. I'm trying to follow this guide
I've tried including the folder in Configuration Properties->Linker->General->Additional Library Directories, and the .lib file in Linker->Input->Additional Dependencies. I've also added the /MT command-line option.
Now here comes my problem - how do I use the files? Do I just use #include "mongo/client/dbclient.h", because this doesn't seem to work (Cannot open source file). I can't find much of any helpful documentation on this subject.
Any ideas?

How to add prebuilt library to a VC++ solution?

It's pretty easy to use a library in VC++ 2008 if you create a project for it and build it alongside the other projects in your solution, but what if the library has too complex of a build process and must be compiled separately via makefile?
My library is like that, and while I've had no problem compiling it on the command line, I have no clue what to do with the resulting header files and .lib file. I've put them all in one directory and added its path to my main project's Additional Include Directories, so it finds the header files just fine. I've also added the relevant info to Additional Library Directories and Additional Dependencies.
Perhaps there's another setting I'm forgetting to set besides these three? I'd appreciate all the help I can get. Thanks.
EDIT Here are the syntax errors I'm getting:
http://pastebin.com/m72ece684
Okay, based on those errors, it has nothing to do with finding your .lib files, it's choking on the header files.
Edit:
It looks like somewhere in windows.h, there is a macro definition for X942_DH_PARAMETERS which is breaking your dl_group.h.
Instead of putting your botan headers at top, but windows.h at top, and then right before you #include the botan headers add this line:
#undef X942_DH_PARAMETERS
Or as I just discovered, that macro is defined in wincrypt.h, and if you add NOCRYPT to your preprocessor definitions it won't include that file. Since you're using a third party crypto library you probably don't need wincrypt.
While I can't exactly say what your problem is I can offer some advice as to how to find a solution. I suggest creating a simple library that contains a single method and a single class, build it, and then try to successfully link it to your project. Once you get that done on a smaller scale, try repeating the steps with your original library.
For msvc compiler you can add
#pragma comment(lib, "MYLIBNAME.lib")
in your header. This will automatically make the linker look for "MYLIBNAME.lib" in the "Additional Library Directories".
If no longer an error occures
Can't find header ...
Can't find MYLIBNAME.lib
the problem is probably related to some other stuff like wrong C runtime, debug release mismatch, ...
P.S.: If the lib is in the solution tree just setting the dependency on the lib, will cause VS to add the targetpath to the libfolder and the libname to the libraries.