Error Linking Boost Libraries With Quantlib

喜欢而已 提交于 2019-12-13 00:44:01

问题


I am trying to build Quantlib using Boost Libraries.

I followed the instructions here: and also on the Quantlib website.

I downloaded and unzipped boost_1_57_0 into C:\program files

I then used the Visual Studio 2013 x64 Native prompt to go to the boost directory and ran

bootstrap.bat

and then

b2 --toolset=msvc --build-type=complete architecture=x86 address-model=64 stage

Then I opened Quantlib_vc12.sln in Visual Studio 2013.

Picked "Release" and "x64", opened "Quantlib" in Property Manager and set the VC++ Directories.

In the include directories I added C:\Programm Files\boost_1_57_0

In the Library Directories I added C:\Program Files\boost_1_57_0\stage\lib

Then I went to the Solution Explorer and right clicked and chose build.

I got one LNK1104 error.

LNK1104: cannot open file 'libboost_unit_test_framework-vc120-mt-1_57.lib

Please see attached screenshot:

I have no idea how to fix this and I would really appreciate some help. I had successfully installed this at work using an admin account but was not able to access Quantlib using my user account. I have since deleted and attempted installations atleast 15 times but it's not working. I am worried that all these attempts at installing may have messed something else up, like some registry (I have no idea how that works but I only know to be afraid). Please help! Thanks.

UPDATE: Still get the same error after adding BOOST_AUTO_LINK_NOMANGLE define to project.

UPDATE2: I am getting these messages on the screen while running b2 to build boost. Is this an error I need to fix?


回答1:


This is exactly what I warned you about in another related question/answer. What's happening here is that the boost headers you are including in this quantlib are (through macros) detecting that you're using MSVC, detecting the version, then automatically linking the required DLL files to build quantlib using #pragma comment(lib....). So even though under Project Settings -> C/C++ -> Linker there are no external DLL's or Lib's specified, they're still being linked by these pragma statements.

So when these macros are detecting your compiler and so on, they're dynamically building a string name of what they think the required libraries would be named on your system. Remember when you built boost, you specified the -layout option. This the naming layout of your boost libraries. Well by default, that layout is something like this:

LIB_LIBRARY_NAME_COMPILER_VERSION_SingleOrMultiThreaded_BOOST_VERSION.LIB

Which in practice looks like this:

libboost_unit_test_framework-vc120-mt-1_57.lib

This is boost "mangling" the name of your library to be as descriptive as possible about how the libraries were build so that, just by glancing at the file name, you know. What we do with -layout=system is tell the boost build system NOT to mangle the names, but to name them according to what option we gave to "layout". Since we chose layout=system, boost is going to name our libraries like this:

LIB_LIBRARY_NAME.LIB

Which in practice will produce:

libboost_unit_test_framework.lib

So when we start using boost after doing this (with MSVC only does this happen), these dynamically generated linker statements don't give a rip about or know about what -layout option you built boost with. They will attempt to link in required libraries using the fully mangled naming format, which is why you get the error:

cannot open file 'libboost_unit_test_framework-vc120-mt-1_57.lib

.. because you don't have a file named that! That's the mangled name! You have a file named libboost_unit_test_framework.lib. See the difference! So, you need to tell these stupid macros to stop mangling the library names when auto-linking required libraries. You do that by adding the following preprocessor definition to your Quantlib project:

BOOST_AUTO_LINK_NOMANGLE

You add that in Project Settings -> C/C++ -> Preprocessor -> Preprocessor definitions.

If you'd rather avoid this headache and don't care about the long and (imo ugly) mangling that boost does to library names, you can build boost omitting the -layout option and it will default to this mangled naming convention, where you shouldn't get stuck on this error at all anymore. I personally put out the effort to keep nice short/clean library names but it's all about preference.

Edit
Since you have the same error after fixing the NO_MANGLE problem, then the only possible reason that you're getting this particular link error is that you do not have whatever file the linker is complaining about missing stored in any of the directories supplied to the linker.

Verify the folders/paths you provide to the linker and verify that the file the linker is looking for is in one of the directories that you're providing to the linker. You have to provide directories to the linker because you're telling the linker "you can look in all of these places for the libraries my project needs". If you specify none, it's got nowhere to look. :(

Example:



来源:https://stackoverflow.com/questions/30060166/error-linking-boost-libraries-with-quantlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!