Geowil
Geowil

Reputation: 680

Boost 1.57.0 Program Options MSVS 2013 Linker Error

I am attempting to update my code and libraries for use in Visual Studio 2013 but I am having problems with Boost 1.57.0. For whatever reason MSVC 12.0 refuses to properly compile program_options due to two linker errors (either building a project with program_options being used or attempt to build the library itself).

I have tried building the library but these linker errors were preventing it. I also get these errors using the pre-built SourceForge binaries located here: http://sourceforge.net/projects/boost/files/boost-binaries/1.57.0/

These are the linker errors I am getting:

error LNK2001: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > boost::program_options::arg" (?arg@program_options@boost@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A)

error LNK2001: unresolved external symbol "public: static unsigned int const boost::program_options::options_description::m_default_line_length" (?m_default_line_length@options_description@program_options@boost@@2IB)

I have been Googling this problem for the last three hours but I have found no solutions to this problem (several previously posted solutions for very old versions of Boost have not worked for me).

Some other information:

library name: libboost_program_options-vc120-mt-1_57 RT Library: Multi-threaded DLL (/MD)

If you need any other info let me know and I will add it to the o. post.

Upvotes: 3

Views: 1305

Answers (2)

L&#225;szl&#243; Papp
L&#225;szl&#243; Papp

Reputation: 53165

You can define this to solve the issue:

BOOST_PROGRAM_OPTIONS_DYN_LINK=1

If you use cmake, you can write this:

add_compile_definitions("BOOST_PROGRAM_OPTIONS_DYN_LINK=1")

Upvotes: 1

Hardik Jain
Hardik Jain

Reputation: 155

You have to link to the static library. Try linking to boost_program_options-vc100-mt-sgd-1_47.lib instead of libboost_program_options-vc120-mt-gd-1_57.lib.

The s indicates the static version of the library. You can check Boost Library Namingfor more details about the naming conventions.

To fix the multiple definition linker errors, change the Visual Studio Runtime Library option in Configuration Properties >> C/C++ >> Code Generation >> Runtime Library from Multi-threaded Debug DLL (/MDd) to Multi-threaded Debug (/MTd).

Upvotes: 4

Related Questions