Ehsan Khodarahmi
Ehsan Khodarahmi

Reputation: 4922

How compile a DLL which is using boost library?

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?

Upvotes: 3

Views: 4422

Answers (3)

KulaGGin
KulaGGin

Reputation: 1242

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.

Upvotes: 0

Igor R.
Igor R.

Reputation: 15075

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

Upvotes: 3

Shmil The Cat
Shmil The Cat

Reputation: 4668

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

enter image description here

Upvotes: 1

Related Questions