Visual Studio 2005
I am linking with boost libraries release 1_33_1.
I keep getting this link error.
libboost_thread-vc80-mt-sgd-1_33_1.lib(once.obj) :error LNK2001: unresolved external symbol "public: void __thiscall std::_String_base::_Xran(void)const " (?_Xran#_String_base#std##QBEXXZ)
Does anyone have any suggestions?
Many thanks,
Edit ======
After recompiling the boost libraries using these switches:
C:\boost_1_42_0>bjam --build-dir=d:\boost_1_42 --build-type-complete --toolset=msvc-8.0 address-model=32 architecture=x86
I am getting some of the following errors:
1>msvcrtd.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info##AAEAAV0#ABV0##Z) already defined in LIBCMTD.lib(typinfo.obj)
1>msvcrtd.lib(MSVCR80D.dll) : error LNK2005: __wassert already defined in LIBCMTD.lib(wassert.obj)
Anyone have any ideas?
Many thanks,
First of all you don't have to set address-model and architecture explicitly if building 32 bit. Also your call has an error: --build-type-complete should be --build-type=complete. If I'm not wrong your call builds absolutely all libs, including filesystem, regex etc.
Obviously you need boost::thread only, so I would recommend to try this call:
C:\boost_1_42_0>bjam --build-dir=d:\boost_1_42 --build-type=complete --toolset=msvc-8.0 --with-thread
But I don't think that will solve your prob but you could give it a try.
My guess is that you somehow mixed /MD and /MT in the project settings.
See these links: First, second
What is probably happening is that your project is linking to the static debug version of the C++ runtime, which causes the static debug boost thread library to be linked and is also linking to another static library which was dynamically linked to the C++ runtime.
The sgd tag in libboost_thread-vc80-mt-sgd-1_33_1.lib means that the boost thread library you're linking with was built against the static debug version of the C++ runtime.
Related
I am building Field3D which links to Boost's thread library. The building environment is listed as follows:
Windows 10 version 1803 64bit
Visual Studio 2015 Update 3
CMake 3.11.4
Release x64 DLL mode in VS
Field3D source package is downloaded from master branch of https://github.com/imageworks/Field3D
Boost is pre-compiled binary of version 1.67.0 for VS2015 (v14.0) 64bit, downloaded from https://sourceforge.net/projects/boost/files/boost-binaries and installed under C:\local\boost_1_67_0 directory.
Doxygen and HDF5 installed properly.
The CMake command line to set up VS2015 is:
cmake -DCMAKE_CONFIGURATION_TYPES=Release -DBUILD_SHARED_LIBS=ON
-DCMAKE_INSTALL_PREFIX=C:...\Field3D-master\install -DDOXYGEN_EXECUTABLE="C:\Program Files\doxygen\bin\doxygen.exe" -DHDF5_ROOT="C:\Program Files\HDF_Group\HDF5\1.10.2" -DBOOST_ROOT=C:\local\boost_1_67_0 -DBOOST_INCLUDEDIR=C:\local\boost_1_67_0\boost -DBOOST_LIBRARYDIR=C:\local\boost_1_67_0\lib64-msvc-14.0 -DIlmbase_Base_Dir=C:...\openexr-develop\IlmBase\install_ -G"Visual Studio 14 2015 Win64" ..
Then I open the generated field3d.sln in VS2015 and try to build Field3D project. Errors are reported as below:
1>------ Build started: Project: Field3D, Configuration: Release x64 ------
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "public: virtual __cdecl boost::detail::thread_data_base::~thread_data_base(void)" (??1thread_data_base#detail#boost##UEAA#XZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "public: void __cdecl boost::thread::detach(void)" (?detach#thread#boost##QEAAXXZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "class boost::thread::id __cdecl boost::this_thread::get_id(void)" (?get_id#this_thread#boost##YA?AVid#thread#2#XZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "public: class boost::thread::id __cdecl boost::thread::get_id(void)const " (?get_id#thread#boost##QEBA?AVid#12#XZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "bool __cdecl boost::this_thread::interruptible_wait(void *,struct boost::detail::mono_platform_timepoint const &)" (?interruptible_wait#this_thread#boost##YA_NPEAXAEBUmono_platform_timepoint#detail#2##Z) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "private: bool __cdecl boost::thread::join_noexcept(void)" (?join_noexcept#thread#boost##AEAA_NXZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "public: bool __cdecl boost::thread::joinable(void)const " (?joinable#thread#boost##QEBA_NXZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "private: bool __cdecl boost::thread::start_thread_noexcept(void)" (?start_thread_noexcept#thread#boost##AEAA_NXZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1> Creating library C:/.../Field3D-master/build/Release/Field3D.lib and object C:/.../Field3D-master/build/Release/Field3D.exp
1>C:\...\3rd-parties\Field3D-master\build\Release\Field3D.dll : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
The cause of these errors, as far as I can see, is that the line 46 of Field3D's CMakeLists.txt
FIND_PACKAGE (Boost COMPONENTS regex thread)
specifies linking boost's thread component, which in turn leads to linking import library C:\local\boost_1_67_0\lib64-msvc-14.0\boost_thread-vc140-mt-x64-1_67.lib, as can be checked in Project Properties -> Linker -> Input -> Additional Dependencies in VS. But somehow Field3D insists on additionally linking to the static library of Boost's thread component which is libboost_thread-vc140-mt-x64-1_67.lib (you can see it in the error messages), thus causing name conflicts. If I temporarily remove "thread" from the FIND_PACKAGE's COMPONENTS list to let Field3D link to the static library as it insists, the Field3D project can build correctly.
Because I wanna build Field3D based on the dynamic DLL of Boost library, my question is: Why does Field3D insist on linking to the static boost library "libboost_thread-vc140-mt-x64-1_67.lib"? Where is this rule introduced? How to suppress linking static thread library of Boost? I have checked CMakeLists.txt, and variables like Boost_LIBRARY_DIRS, Boost_LIBRARIES and Field3D_BIN_Libraries therein but they do not contain static library filename libboost_thread-vc140-mt-x64-1_67.lib. I know that #pragma comment (linker, ...) can also require linking to some user-defined library, but there is no such directive in Field3D source package whatsoever. So I am at my wit's end and post this question here in hope that someone can help me figure out where on earth the linking postulation to the static library of Boost's thread component comes from. Some minor modification may be needed to reproduce the issue but I think the information provided above should cover most of the build for a veteran. If you need any other info to troubleshoot this problem please let me know. Thank you.
After another bunch of hours to check Field3D's building process, I believe the problem is Field3D's failure to make use of Boost's mechanism to disable automatic linking and to enable dynamic linking on Windows. An issue ticket is submitted in hope that the developers of Field3D can fix it in future: https://github.com/imageworks/Field3D/issues/96. Briefly, add the following two commands to copy INTERFACE_COMPILE_DEFINITIONS property of Boost::disable_autolinking and Boost::dynamic_linking import targets to Field3D project
TARGET_COMPILE_DEFINITIONS( Field3D PRIVATE $<TARGET_PROPERTY:Boost::disable_autolinking,INTERFACE_COMPILE_DEFINITIONS> )
TARGET_COMPILE_DEFINITIONS( Field3D PRIVATE $<TARGET_PROPERTY:Boost::dynamic_linking,INTERFACE_COMPILE_DEFINITIONS> )
after line 189 of CMakeLists.txt.
Please point out if I have made any mistake.
I'm using Visual Studio 2010 and I've installed openmpi and boost. I've successfully managed to build the boost mpi libraries but when I try to run their example hello_world program I get linking errors like:
Error 16 error LNK2001: unresolved external symbol "public: void __cdecl boost::mpi::communicator::send(int,int,class boost::mpi::packed_oarchive const &)const " (??$send#Vpacked_oarchive#mpi#boost###communicator#mpi#boost##QEBAXHHAEBVpacked_oarchive#12##Z) C:\Dropbox\mpi_tess\MPITess\hello_world.obj
I've included the build lib files into the linker path. Any ideas what's wrong?
Thanks for the help,
Elad
I'm getting the following (and many more) errors when attempting to link my project statically with boost.log on MSVC 10.0:
1>libboost_log-vc100-mt-gd-1_53.lib(attribute_name.obj) : error
LNK2001: unresolved external symbol "**__declspec(dllimport)** public:
__thiscall std::_Container_base::~_Container_base(void)" (__imp_??1_Container_base#std##QAE#XZ)
1>libboost_log-vc100-mt-gd-1_53.lib(text_file_backend.obj) : error
LNK2001: unresolved external symbol "**__declspec(dllimport)** public:
__thiscall std::_Container_base::~_Container_base(void)" (__imp_??1_Container_base#std##QAE#XZ)
Note that the project is linking also to boost system, filesystem, and thread libraries.
1> Searching ../lib/\libboost_system-vc100-mt-gd-1_53.lib:
1> Searching ../lib/\libboost_date_time-vc100-mt-gd-1_53.lib:
1> Searching ../lib/\libboost_regex-vc100-mt-gd-1_53.lib:
1> Searching ../lib/\libboost_thread-vc100-mt-gd-1_53.lib:
1> Searching ../lib/\libboost_chrono-vc100-mt-gd-1_53.lib:
1> Searching ../lib/\libboost_log-vc100-mt-gd-1_53.lib:
1> Searching ../lib/\libboost_filesystem-vc100-mt-gd-1_53.lib:
My project does not define the BOOST_ALL_DYN_LINK or BOOST_LOG_DYN_LINK macros, so I was not expecting to see the __declspec signatures, which I am thinking is the ultimate problem. Am I missing something required to properly link this library statically?
Update
I removed precompiled headers on my project and performed a "clean", and everything linked fine. Is it possible that precompiled headers were somehow causing the project to link statically to CRT?
You may need link log_setup firstly and then log before filesystem and so on, this was boost link code in my CMakeLists.txt:
set(USED_BOOST_LIBS ${Boost_LOG_SETUP_LIBRARY} ${Boost_LOG_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY} ${Boost_DATE_TIME_LIBRARY}
${Boost_THREAD_LIBRARY} ${Boost_REGEX_LIBRARY}
)
...
target_link_libraries(myexe ${USED_BOOST_LIBS})
It works fine with me both on MSVC 14.0 and gcc 4.8.You can try it.
I develop addons for a space flight simulator called Orbiter: http://orbit.medphys.ucl.ac.uk/
It accepts plugins as dll files. I recently made a plugin which uses the Bullet physics library as well. Its statically linked to the dll, so the bullet library is itself not a dll but compiled right into the plugin. Bullet is compiled with Multi-threaded (/MT) option for the release and Multi-threaded Debug (/MTd) for debug
Now I want to use threads from Boost. So I installed the static Boost libraries by choosing the 2 static options from the Boost Pro installer. I was able to successfully create a Win 32 application with these static libraries. The application used Multi-threaded (/MT) as well. So I know that there is no mismatch on the flags.
Yet, when I add Boost to my Orbiter dll plugin project, which also has Bullet, I get a link error :
1>------ Build started: Project: Bump, Configuration: Release Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(990,5): warning MSB8012: TargetPath(F:\Orbiter\Orbitersdk\samples\BumpThreaded\Release\Bump.dll) does not match the Linker's OutputFile property value (F:\Orbiter\Modules\Plugin\Bump.dll). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info##AAE#ABV0##Z) already defined in LIBCMT.lib(typinfo.obj)
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info##AAEAAV0#ABV0##Z) already defined in LIBCMT.lib(typinfo.obj)
1> Creating library F:\Orbiter\Orbitersdk\samples\BumpThreaded\Release\Bump.lib and object F:\Orbiter\Orbitersdk\samples\BumpThreaded\Release\Bump.exp
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>......\Modules\Plugin\Bump.dll : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 3 up-to-date, 0 skipped ==========
From what I read on other questions, this can be due to mismatched flags for 2 libraries being used within an application. But thats not the case here. Both Bullet and Boost are compiled with /MT.
Also boost works ok with a normal win 32 application, so why the problem when linking it statically to output a dll ?
I use visual studio 2010 express and have a windows 7 64 bit system.
Thanks for any help in advance :)
If you're only using Boost and Bullet, and these are both definitely compiled with /MT, then it must be your Bump dll itself which is using /MD.
I am creating a static library in Visual Studio 2010. This library will be statically linked with another of my applications to produce the .exe. The thing is that I want my .exe to be statically linked against C adn C++ library (don't want dependency on msvcp100.dll and msvcr100.dll). But what ever I do I can't get it working.
If I link my static library with static C and C++ libs then I can't compile the .exe - Linker complains about "already defined symbols".
If I link my static library with C and C++ DLL then my .exe ends up having dependency on msvcp100.dll and msvcr100.dll.
How do I tell VS to link my static library with static C and C++ libs only when it's being linked in my .exe?
EDIT
Here are a fre linker errors when both static lib and .exe user /MT (i.e. static linking of runtime library):
1>msvcrt.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info##AAE#ABV0##Z) already defined in LIBCMT.lib(typinfo.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: class std::locale::facet * __thiscall std::locale::facet::_Decref(void)" (?_Decref#facet#locale#std##QAEPAV123#XZ) already defined in re2_release.lib(regexp.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "protected: virtual class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::setbuf(char *,__int64)" (?setbuf#?$basic_streambuf#DU?$char_traits#D#std###std##MAEPAV12#PAD_J#Z) already defined in re2_release.lib(regexp.obj)
1>msvcrt.lib(MSVCR100.dll) : error LNK2005: _strtoul already defined in LIBCMT.lib(strtol.obj)
1>LIBCMT.lib(crt0init.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
If I set /NODEFAULTLIB:LIBCMT then errors from mscvrt.lib disappear, but msvcprt.lib errors remain.
I had this problem, and libriks solution solved it. I will quote him here for those who skips reading the comments:
Some module is not using static linking of the runtime library, because your linker errors >show "msvcrt.lib" which is the import library for the DLL version. Look more carefully >through your project settings, and any other libraries you link to, making sure EVERYTHING is >using /MT.