How compile a DLL which is using boost library? - visual-studio-2010

I'm working on a DLL project in VS 2010, I want to use boost mutex in some part of my code. but when I compile project to release final DLL, I get this linkage error:
LINK : fatal error LNK1104: cannot open file 'libboost_date_time-vc100-mt-1_49.lib'
I've already compiled boost with this command:
bjam install --toolset=msvc variant=release link=static threading=multi runtime-link=static
& I've a file named libboost_date_time-vc100-mt-s-1_49.lib, when I change configuration type of my project from Dynamic Linked Library (DLL) to Static Library, the project builds successfully, but I need to release only as a DLL file (& my final DLL CAN NOT have any dependency to other external DLLs). I know the problem causes by compilation of boost, but I don't know how should I recompile it
Any guideline?

Check that you link the runtime-library statically (Configuration properties-->C/C++-->Code generation-->Runtime library: Multi-threaded (/MT).
Otherwise, link CRT and boost dynamically. For this purpose build boost like this:
bjam --toolset=msvc variant=release link=shared threading=multi runtime-link=shared

IMO, you built the boost library just fine : you used link=static which means you would like to emit static library (and not a DLL) and since you would like to have standalone deployment , you specified runtime-link=static meaning you link against MS C/C++ run time as static libraries (e.g. the code for printf() will be embedded in your final library and not be referenced to msvcr100.dll)
Please take a look at the picture below, make sure to set the full path of the directory where your boost library resides under Additional Library Dependencies

I fixed my error "Error LNK1104 cannot open file 'libboost_locale-vc142-mt-gd-x32-1_73.lib'" in a DLL project, which I described in this issue on boost' github by installing the boost library using vcpkg.
Install vcpkg. Then write .\vcpkg install boost. You can see how it's done in the video: https://youtu.be/b7SdgK7Y510 . He's not installing the boost library but the process is exactly the same.
This is all for Windows and Visual Studio's toolset, of course.

Related

install wxWidget as static library by Vcpkg

I'm using Visual studio 2019
I followed this link to install wxWidget using vcpkg install wxwidgets
https://www.wxwidgets.org/blog/2019/01/wxwidgets-and-vcpkg/
and read this link
https://computingonplains.wordpress.com/using-visual-studio-2017-to-build-wxwidgets/
and this
https://devblogs.microsoft.com/cppblog/vcpkg-updates-static-linking-is-now-available/
the problem after installing wxWidget using vcpkg the result build is Dynamic library and I want to compile my project as static library to run exe file on other users pc .
I want to change from Dynamic lib compilation to static due to :
users on another PCs get VCRUNTIME error so they have to install VC++ runtime library as I read in
How to fix a missing vcruntime140 clr 400 dll error
Summary of the problem :
vcpkg installation wxwidgets result is dynamic lib configuration and I need to install static one .
Instead of just doing vcpkg install wxwidgets
use vcpkg install wxwidgets:x64-windows-static
This will install wxwidgets and all it dependencies with static runtime and library linkage.
You can also define your custom triplet if you want to customize your build setup (see https://github.com/microsoft/vcpkg/blob/master/docs/users/triplets.md)
#MohmmedAlaa,
You are better off compiling the library yourself.
There is a big difference between compiling the project with wxWidgets being dynamic vs static and VC++ RT dynamic vs static.
Also, keep in mind that some VC++ RT is not licensed to be distributable.
So all in all - get the wxWidgets sources, install MSVC, build static libraries (possibly with the compiler switch to use "static RT) and compile your software.

Building boost 1.70 with icu support

I am trying to build boost 1.70 with ICU support. For this, I built ICU (version 61.1) some time ago. In our internal system, I have this sort of directory structure for ICU and I cannot change it quickly because several components using this library and expecting the libraries from this directory structure:
...\icu\lib (for x86 version of lib files)
...\icu\bin (for x86 version of dll files)
...\icu\lib64 (for x64 version of lib files)
...\icu\bin64 (for x64 version of dll files)
...\icu\include (include headers files for icu)
So, after building ICU, I put the files into their respective directory.
Now I want to build boost 1.70 with ICU support, so I used this build command in a self written batch script (here, 32bit as an example):
set "PATH_TO_ICU=.....\icu"
...
if not exist "%PATH_TO_ICU%" (
echo "Error: Could not find path to icu. Was looking in '%PATH_TO_ICU%'"
pause
exit /b 1
)
...
:: debug 32bit / static
b2 --build-type=complete toolset=msvc-14.1 variant=debug threading=multi link=static -sICU_PATH="%PATH_TO_ICU%" -sICU_LINK="%PATH_TO_ICU%\lib" include="%PATH_TO_ICU%\include"
But the output during build is showing me this
- has_icu builds : no
...
- icu : no
- icu (lib64) : no
Additional Information: I am building this with Visual Studio 2017.
So, what I am missing here?
Edit
I looked into the file boost_root\bin.v2\config.log and saw this sort of lines
Line 132: LINK : fatal error LNK1181: cannot open input file '....\icu\lib.obj'
which maybe explains why b2 could not see ICU correctly.
For windows, I would investigate Microsoft VCPKG. I used to build Boost from scratch with both zlib and bzip2 support but I have found that vcpkg is far easier. You don't need to keep vcpkg around either. After building boost or any of the other 3rd party libraries, export boost (using the vcpkg export command) and you'll have copy that you can use most anywhere. Vcpkg can build 32 or 64 bit packages and static and shared. I actually adjust the vcpkg triplets to generate a static library that links against the shared crt so I don't worry about DLL's. The point is that vcpkg can handle all of your needs. In fact for boost, you can build just the components you want if you so desire.

Boost VS2017 linking to the wrong DLL

I have a CMake file which does this:
find_package(Boost COMPONENTS system filesystem)
add_library(MyModule MODULE main.cpp)
target_include_directories(MyModule PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(MyModule Boost::system Boost::filesystem)
I'm using VS 2017 as my generator. When I generate the project file with cmake, it finds boost_system-vc141-mt-1_63.lib and I can see that it is in the linking rules of the vcxproj. However, when I try to compile I get this error:
LINK : fatal error LNK1104: cannot open file 'libboost_system-vc140-mt-1_63.lib
Note the different generators (vc140 vs vc141). I know my compiler has output the right values because I built boost from source, so I tried to just rename vc141 to vc140, but the error stayed the same. I also confirmed that vc140 is not referenced in the project file.
What's going on? How can I force boost to link to the correct version?
When building with Visual Studio, boost has some pragma statements which do the linking for you. This is called "Auto-linking" and it over-rides any command-line arguments you may be passing to the linker.
The solution is to define BOOST_ALL_NO_LIB. This can be done in two ways:
In source code before including boost headers as #define BOOST_ALL_NO_LIB.
It could be added to your cmake file as: add_definitions("-DBOOST_ALL_NO_LIB").
As of CMake 3.5: Use the disable_autolinking imported target:
target_link_libraries(MyModule Boost::system Boost::filesystem Boost::disable_autolinking)

boost library 1.47.1 build 'lib' prefix causing LNK1104 error

I'm having difficulties generating the correct boost .lib file to compile with a VS project I've been given. It appears that after performing the complete build installation using 'b2.exe' from VS2010 command prompt I'm only able to generate the boost library files that contain the 'lib' prefix.
When I come to compile my project I'm getting the following error message:
"error LNK1104: cannot open file 'boost_signals-vc90-mt-1_47.lib'"
After going through the lib folder I can see that my boost build has only generated 'libboost_signals-vc90-mt-1_47.lib'
The boost documentation gives the following information about the lib prefix:
lib
Prefix: except on Microsoft Windows, every Boost library name begins with this string. On Windows, only ordinary static libraries use the lib prefix; import libraries and DLLs do not.
So far I've attempted the following build options for the msvc-9.0 toolset:
'build-type=complete'
'link=static,shared'
Any advice on how I may be able to generate the required .lib file would be greatly appreciated.
Many Thanks.
link=static should be used whenever you're linking to static version of boost library.
link=shared - should be used whenever you're linking dynamically to boost. It will add extra dependencies on boost dll's.
You can also use link=static,shared to build both versions - static and dynamic.
Define 'BOOST_ALL_DYN_LINK' in project controls how you link to boost.
If it's defined - it's dynamic linking, if not defined - it's static linking.

Boost linker Multi-threaded build issue

I've been using a successfully built boost library version 1.55.0 for a few weeks now but I ran into error LNK1140 cannot open file 'libboost_filesystem-vc120-mt-sgd-1_55.lib when I try using Multi-threaded(/MT) rather than /MD. I've been searching through forums and it seems that I need to statically link the library so I tried running .\b2 --with-thread variant=release link=static threading=multi runtime-link=static but that didn't work either. I have C:/Boost/1.55.0/VC/12.0 in VC++ Directories->Include Directories and C:\Boost\1.55.0\VC\12.0\stage\lib in Linker->General->Additional Library Directories. Any ideas?

Resources