Question

I used the following command to build boost-1.53.0 on Win7 Pro with VS 2013 Pro (VC12.0, 18.00.21005.1):

b2 stage toolset=msvc link=shared runtime-link=shared threading=multi --without-graph --without-graph_parallel --without-mpi --without-wave --without-python

And before that, I patched my source code as per this patch: #8750 for_vs2013.patch.

Finally I got the files under $BOOST_ROOT/stage/lib like these:

boost_atomic-vc120-mt-1_53.dll
boost_atomic-vc120-mt-1_53.lib
boost_atomic-vc120-mt-gd-1_53.dll
boost_atomic-vc120-mt-gd-1_53.lib
...
boost_thread-vc120-mt-1_53.dll
boost_thread-vc120-mt-1_53.lib
boost_thread-vc120-mt-gd-1_53.dll
boost_thread-vc120-mt-gd-1_53.lib
...
// only theses four files have "lib" prefix
libboost_exception-vc120-mt-1_53.lib
libboost_exception-vc120-mt-gd-1_53.lib
libboost_test_exec_monitor-vc120-mt-1_53.lib
libboost_test_exec_monitor-vc120-mt-gd-1_53.lib

I failed building boost::signals library. Since I don't know whether it's relative to this issue, I clarify it here.

I wrote a very simple demo to learn boost::thread according a tutorial just now. But the compiler gives me a link error: LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc120-mt-gd-1_53.lib'. I searched around and I have a question. I'm sure I've set Project Properties > C/C++ > Code Generation > Runtime Library to /MDd. But why the compiler still tries to link the static library libboost_thread-vc120-mt-gd-1_53.lib when I rebuild the project? I also tried to use some relative solutions that I found, such as using BOOST_ALL_DYN_LINK or BOOST_DYN_LINK precompile directive. But it's not working. I found such a snippet in auto-link.hpp:

//
// select linkage opt:
//
#if (defined(_DLL) || defined(_RTLDLL)) && defined(BOOST_DYN_LINK)
#  define BOOST_LIB_PREFIX
#elif defined(BOOST_DYN_LINK)
#  error "Mixing a dll boost library with a static runtime is a really bad idea..."
#else
#  define BOOST_LIB_PREFIX "lib"
#endif

It should work but I can't get the result I want :(

BTW, should I rebuild the boost libraries with link=static option?

demo code

// c++ std libraries
#include <iostream>
// c++ boost libraries
#include <boost/thread.hpp>
#include <boost/date_time.hpp>

// #define BOOST_ALL_DYN_LINK
// #define BOOST_DYN_LINK

void WorkerFunc()
{
    boost::posix_time::seconds worktime(3);
    std::cout << "Worker: running..." << std::endl;

    // Pretend to do sth. useful...
    boost::this_thread::sleep(worktime);

    std::cout << "Worker: finished." << std::endl;
}


int main()
{
    std::cout << "main: startup." << std::endl;
    // Create a worker thread.
    boost::thread worker_thread(WorkerFunc);

    std::cout << "main: waiting for thread..." << std::endl;
    worker_thread.join();

    std::cout << "main: done." << std::endl;

    return 0;
}
Was it helpful?

Solution

From inside visual studio: go to your project and right click it to get the context menu. Go to properties. In the properties dialog go to:

Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions

Try putting BOOST_ALL_DYN_LINK (or BOOST_THREAD_USE_DLL) in the Preprocessor Definitions list.

Then rebuild your demo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top