Build boost + ICU under Windows VC++ 2010 static linking - c++

I tried now almost a week to build a reliable boost + ICU libraries under Windows and VC++ as STATIC libraries under x86 system (so I won't need any runtime dll's when). I mostly need boost regex with Unicode support and boost.locale.icu.
Couldn't find all over the web any reliable solution (not on boost site or ICU) for doing this. Tried building with VC++, Cygwin + VC++ but no success so far. Any help from experience? Or, the worse scenario, any pre-build ICU static + boost static packages?
After I built ICU static, configured under Cygwin:
bash runConfigureICU --enable-debug --disable-release Cygwin/MSVC --prefix=/cygdrive/c/icu/dist --enable-static --disable-shared
got the following static libraries:
02/17/2014 12:57 AM 23,505,784 sicudt.lib
02/17/2014 12:56 AM 7,922,572 sicuin.lib
02/17/2014 12:56 AM 101,218 sicuio.lib
02/17/2014 12:56 AM 1,507,686 sicule.lib
02/17/2014 12:56 AM 157,632 siculx.lib
02/17/2014 12:56 AM 190,472 sicutest.lib
02/17/2014 12:56 AM 1,749,872 sicutu.lib
02/17/2014 12:56 AM 4,584,154 sicuuc.lib
I built boost as static against ICU libraries:
bjam --toolset=msvc-10.0 --build-dir="C:\local\build" address-model=32 threading=multi link=static runtime-link=static -sHAVE_ICU=1 -sICU_PATH="C:\icu" -sICU_LINK="/LIBPATH:C:\icu\lib sicuuc.lib sicuin.lib sicudt.lib"
then, when trying a simple code I get unresolved symbols, so something is wrong with my compiled libs:
cl.exe /MT /EHsc /O2 /I C:\local
\boost_1_55_0 uniregboost.cpp /I C:\icu\include /link /SUBSYSTEM:CONSOLE advapi3
2.lib sicuuc.lib sicuin.lib sicudt.lib /libpath:"C:\local\boost_1_55_0\stage\lib
" /libpath:"C:\icu\lib"
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
uniregboost.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:uniregboost.exe
/SUBSYSTEM:CONSOLE
advapi32.lib
sicuuc.lib
sicuin.lib
sicudt.lib
/libpath:C:\local\boost_1_55_0\stage\lib
/libpath:C:\icu\lib
uniregboost.obj
MSVCRT.lib(MSVCR100.dll) : error LNK2005: _memmove already defined in LIBCMT.lib
(memmove.obj)
MSVCRT.lib(MSVCR100.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(
malloc.obj)
MSVCRT.lib(MSVCR100.dll) : error LNK2005: _realloc already defined in LIBCMT.lib
(realloc.obj)
MSVCRT.lib(MSVCR100.dll) : error LNK2005: _free already defined in LIBCMT.lib(fr
ee.obj)
MSVCRT.lib(MSVCR100.dll) : error LNK2005: _wcslen already defined in LIBCMT.lib(
wcslen.obj)
MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strtoul already defined in LIBCMT.lib
(strtol.obj)
MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_in
fo(class type_info const &)" (??0type_info##AAE#ABV0##Z) already defined in LIBC
MT.lib(typinfo.obj)
MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall
type_info::operator=(class type_info const &)" (??4type_info##AAEAAV0#ABV0##Z) a
lready defined in LIBCMT.lib(typinfo.obj)
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; us
e /NODEFAULTLIB:library
uniregboost.obj : error LNK2019: unresolved external symbol "private: class boos
t::basic_regex<int,class boost::icu_regex_traits> & __thiscall boost::basic_rege
x<int,class boost::icu_regex_traits>::do_assign(int const *,int const *,unsigned
int)" (?do_assign#?$basic_regex#HVicu_regex_traits#boost###boost##AAEAAV12#PBH0
I#Z) referenced in function "public: class boost::basic_regex<int,class boost::i
cu_regex_traits> & __thiscall boost::basic_regex<int,class boost::icu_regex_trai
ts>::assign(int const *,int const *,unsigned int)" (?assign#?$basic_regex#HVicu_
regex_traits#boost###boost##QAEAAV12#PBH0I#Z)
uniregboost.obj : error LNK2019: unresolved external symbol "public: class std::
vector<int,class std::allocator<int> > __thiscall boost::re_detail::icu_regex_tr
aits_implementation::do_transform(int const *,int const *,class icu_52::Collator
const *)const " (?do_transform#icu_regex_traits_implementation#re_detail#boost#
#QBE?AV?$vector#HV?$allocator#H#std###std##PBH0PBVCollator#icu_52###Z) reference
d in function "public: class std::vector<int,class std::allocator<int> > __thisc
all boost::re_detail::icu_regex_traits_implementation::transform(int const *,int
const *)const " (?transform#icu_regex_traits_implementation#re_detail#boost##QB
E?AV?$vector#HV?$allocator#H#std###std##PBH0#Z)
uniregboost.obj : error LNK2019: unresolved external symbol "public: bool __this
call boost::icu_regex_traits::isctype(int,unsigned __int64)const " (?isctype#icu
_regex_traits#boost##QBE_NH_K#Z) referenced in function "private: bool __thiscal
l boost::re_detail::perl_matcher<class boost::u8_to_u32_iterator<class std::_Str
ing_const_iterator<char,struct std::char_traits<char>,class std::allocator<char>
>,int>,class std::allocator<struct boost::sub_match<class boost::u8_to_u32_iter
ator<class std::_String_const_iterator<char,struct std::char_traits<char>,class
std::allocator<char> >,int> > >,class boost::icu_regex_traits>::match_word_bound
ary(void)" (?match_word_boundary#?$perl_matcher#V?$u8_to_u32_iterator#V?$_String
_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std##H#boost##V?$alloca
tor#U?$sub_match#V?$u8_to_u32_iterator#V?$_String_const_iterator#DU?$char_traits
#D#std##V?$allocator#D#2##std##H#boost###boost###std##Vicu_regex_traits#2##re_de
tail#boost##AAE_NXZ)
uniregboost.exe : fatal error LNK1120: 3 unresolved externals
I didn't forget to add the static flag for ICU in my code:
#define U_STATIC_IMPLEMENTATION
UPDATE:
rebuilt all ICU and Boost static, now I have only one error linking:
cl.exe /MT /EHsc /O2 /I C:\lib\b
oost-1.55.0-vs2010\include\boost-1_55 uniregboost.cpp /I C:\lib\icu-52.1-vs2010\
include /link /SUBSYSTEM:CONSOLE advapi32.lib sicuuc.lib sicuin.lib sicudt.lib s
icuuc.lib /libpath:"C:\lib\boost-1.55.0-vs2010\lib" /libpath:"C:\lib\icu-52.1-vs
2010\lib"
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
uniregboost.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:uniregboost.exe
/SUBSYSTEM:CONSOLE
advapi32.lib
sicuuc.lib
sicuin.lib
sicudt.lib
sicuuc.lib
/libpath:C:\lib\boost-1.55.0-vs2010\lib
/libpath:C:\lib\icu-52.1-vs2010\lib
uniregboost.obj
Creating library uniregboost.lib and object uniregboost.exp
libboost_regex-vc100-mt-s-1_55.lib(icu.obj) : warning LNK4217: locally defined s
ymbol ??0Locale#icu_52##QAE#ABV01##Z (public: __thiscall icu_52::Locale::Locale(
class icu_52::Locale const &)) imported in function "public: class icu_52::Local
e __thiscall boost::re_detail::icu_regex_traits_implementation::getloc(void)cons
t " (?getloc#icu_regex_traits_implementation#re_detail#boost##QBE?AVLocale#icu_5
2##XZ)
libboost_regex-vc100-mt-s-1_55.lib(icu.obj) : warning LNK4217: locally defined s
ymbol ??0Locale#icu_52##QAE#XZ (public: __thiscall icu_52::Locale::Locale(void))
imported in function "public: class icu_52::Locale __thiscall boost::icu_regex_
traits::getloc(void)const " (?getloc#icu_regex_traits#boost##QBE?AVLocale#icu_52
##XZ)
libboost_regex-vc100-mt-s-1_55.lib(icu.obj) : warning LNK4217: locally defined s
ymbol ??1Locale#icu_52##UAE#XZ (public: virtual __thiscall icu_52::Locale::~Loca
le(void)) imported in function "public: __thiscall boost::re_detail::icu_regex_t
raits_implementation::~icu_regex_traits_implementation(void)" (??1icu_regex_trai
ts_implementation#re_detail#boost##QAE#XZ)
libboost_regex-vc100-mt-s-1_55.lib(icu.obj) : error LNK2019: unresolved external
symbol "__declspec(dllimport) public: static class icu_52::Collator * __cdecl i
cu_52::Collator::createInstance(class icu_52::Locale const &,enum UErrorCode &)"
(__imp_?createInstance#Collator#icu_52##SAPAV12#ABVLocale#2#AAW4UErrorCode###Z)
referenced in function "public: __thiscall boost::re_detail::icu_regex_traits_i
mplementation::icu_regex_traits_implementation(class icu_52::Locale const &)" (?
?0icu_regex_traits_implementation#re_detail#boost##QAE#ABVLocale#icu_52###Z)
uniregboost.exe : fatal error LNK1120: 1 unresolved externals

I'm not allowed to comment yet, so I'm giving my comment as an answer (sorry for the inconvenience), for I'm struggling with exactly the same issue. I detected following test file:
<boost>\libs\locale\build\has_icu_test.cpp
with these lines of code:
#if defined(_MSC_VER) && !defined(_DLL)
#error "Mixing ICU with a static runtime doesn't work"
#endif
Maybe (at least on Windows) a static boost with ICU compilation is not possible?

You are building the right way. The problem is that the Boost.Locale build system does not seem to have any code to detect the static ICU libraries and therefore even if you set all the correct parameters it does not pick up the libraries as expected. If you inspect these files:
libs\locale\build\Jamfile.v2
libs\regex\build\Jamfile.v2
you will notice that there seems to be no code to probe for sicuXX.XXX files. I think this may be the problem.
There is a feature request for this on the boost bug tracker: https://svn.boost.org/trac/boost/ticket/9685
It may help if more people show their interest in this being implemented.

edit M:\work\code\qt\icu4c-68_2\icu4c\source\runConfigureICU
find Cygwin/MSVC
replace -MD -MDt to -MT -MTd

Related

Static library not linking correctly

sorry to bother you.
I know this is a commonly asked question and this is probably annoying to get again but I'm just completely stuck and not sure what I'm doing wrong.
I'm following learnopengl.com and trying to add assimp to my CLion project.
I created a new project quickly just so I know nothing is interfering.
I have a folder on my C drive where I placed in assimp library.
I downloaded it by following https://github.com/assimp/assimp/blob/master/Build.md with git and doing
cd assimp
cmake CMakeLists.txt
but changing the BUILD_SHARED_LIBS to OFF
Then I build the library with visual studio 2022 Using "Release x64" and the "Visual Studio 2022 (v143)" toolset
I link to the library with CMake as below.
I don't get an error message so I know that CMake finds the library.
I also have the location to the library setup in the PATH.
cmake_minimum_required(VERSION 3.22)
project(lemmefixbroken)
set(CMAKE_CXX_STANDARD 20)
set(LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
add_executable(lemmefixbroken main.cpp)
# assimp
include_directories("C:/dev/libraries/assimp/include")
find_library(ASSIMP_LOCATION NAMES "assimp-vc143-mt" REQUIRED)
message(${ASSIMP_LOCATION})
target_link_libraries(${PROJECT_NAME} "${ASSIMP_LOCATION}")
My compiler settings are as below:
(Using the compiler located in Visual Studio 2022 and using the architecture amd64)
I've tried all the different architectures but none work.
The message returns "C:/dev/libraries/assimp/lib/Release/assimp-vc143-mt.lib" which is where its located
My code is:
#include <iostream>
#include "assimp/Importer.hpp"
int main()
{
std::cout << "Hello, World!" << std::endl;
Assimp::Importer import;
return 0;
}
When I build the code I get this error:
"C:\Program Files\JetBrains\CLion 2022.1.1\bin\cmake\win\bin\cmake.exe" --build C:\Users\charl\CLionProjects\lemmefixbroken\cmake-build-release --target all -j 9
[1/2] Building CXX object CMakeFiles\lemmefixbroken.dir\main.cpp.obj
[2/2] Linking CXX executable lemmefixbroken.exe
FAILED: lemmefixbroken.exe
cmd.exe /C "cd . && "C:\Program Files\JetBrains\CLion 2022.1.1\bin\cmake\win\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\lemmefixbroken.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\mt.exe --manifests -- C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1433~1.316\bin\Hostx64\x64\link.exe /nologo CMakeFiles\lemmefixbroken.dir\main.cpp.obj /out:lemmefixbroken.exe /implib:lemmefixbroken.lib /pdb:lemmefixbroken.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console C:\dev\libraries\assimp\lib\Release\assimp-vc143-mt.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1433~1.316\bin\Hostx64\x64\link.exe /nologo CMakeFiles\lemmefixbroken.dir\main.cpp.obj /out:lemmefixbroken.exe /implib:lemmefixbroken.lib /pdb:lemmefixbroken.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console C:\dev\libraries\assimp\lib\Release\assimp-vc143-mt.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:lemmefixbroken.exe.manifest" failed (exit code 1120) with the following output:
assimp-vc143-mt.lib(AssbinLoader.obj) : error LNK2019: unresolved external symbol uncompress referenced in function "public: virtual void __cdecl Assimp::AssbinImporter::InternReadFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct aiScene *,class Assimp::IOSystem *)" (?InternReadFile#AssbinImporter#Assimp##UEAAXAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##PEAUaiScene##PEAVIOSystem#2##Z)
assimp-vc143-mt.lib(Compression.obj) : error LNK2019: unresolved external symbol inflate referenced in function "public: unsigned __int64 __cdecl Assimp::Compression::decompress(void const *,unsigned __int64,class std::vector<char,class std::allocator<char> > &)" (?decompress#Compression#Assimp##QEAA_KPEBX_KAEAV?$vector#DV?$allocator#D#std###std###Z)
assimp-vc143-mt.lib(unzip.obj) : error LNK2001: unresolved external symbol inflate
assimp-vc143-mt.lib(Compression.obj) : error LNK2019: unresolved external symbol inflateEnd referenced in function "public: bool __cdecl Assimp::Compression::close(void)" (?close#Compression#Assimp##QEAA_NXZ)
assimp-vc143-mt.lib(unzip.obj) : error LNK2001: unresolved external symbol inflateEnd
assimp-vc143-mt.lib(Compression.obj) : error LNK2019: unresolved external symbol inflateSetDictionary referenced in function "public: unsigned __int64 __cdecl Assimp::Compression::decompressBlock(void const *,unsigned __int64,char *,unsigned __int64)" (?decompressBlock#Compression#Assimp##QEAA_KPEBX_KPEAD1#Z)
assimp-vc143-mt.lib(Compression.obj) : error LNK2019: unresolved external symbol inflateReset referenced in function "public: unsigned __int64 __cdecl Assimp::Compression::decompressBlock(void const *,unsigned __int64,char *,unsigned __int64)" (?decompressBlock#Compression#Assimp##QEAA_KPEBX_KPEAD1#Z)
assimp-vc143-mt.lib(Compression.obj) : error LNK2019: unresolved external symbol inflateInit_ referenced in function "public: bool __cdecl Assimp::Compression::open(enum Assimp::Compression::Format,enum Assimp::Compression::FlushMode,int)" (?open#Compression#Assimp##QEAA_NW4Format#12#W4FlushMode#12#H#Z)
assimp-vc143-mt.lib(Compression.obj) : error LNK2019: unresolved external symbol inflateInit2_ referenced in function "public: bool __cdecl Assimp::Compression::open(enum Assimp::Compression::Format,enum Assimp::Compression::FlushMode,int)" (?open#Compression#Assimp##QEAA_NW4Format#12#W4FlushMode#12#H#Z)
assimp-vc143-mt.lib(unzip.obj) : error LNK2001: unresolved external symbol inflateInit2_
assimp-vc143-mt.lib(unzip.obj) : error LNK2019: unresolved external symbol crc32 referenced in function unzReadCurrentFile
assimp-vc143-mt.lib(unzip.obj) : error LNK2019: unresolved external symbol get_crc_table referenced in function unzOpenCurrentFile3
lemmefixbroken.exe : fatal error LNK1120: 9 unresolved externals
ninja: build stopped: subcommand failed.
I've tried compiling the library more times than I would like to count. I've tried using the 2019 compiler and nothing. I still get all the same errors.
I have no clue what I'm doing wrong but hopefully someone here will know.
I've also tried using shared libraries with no success.
I've updated Visual Studio 2022 and restarted my computer then compiling again and still nothing changes.
Those are all zlib symbols that are missing, which means you didn't link against that. Asset-Importer lists several dependencies:
zlib
zip-lib
unzip
pugi-xml
rapijson
clipper
draco
gtest
stb_image
utf8cpp
poly2tri
openddlparser
Since Findassimp.cmake uses an old path-based interface instead of the newer style of defining virtual targets that can have PUBLIC dependencies, you will need to link against those yourself. They're all in the library's source tree, but having never used the library I don't know if they get built as part of its build scripts of if you would need to do that yourself.
As you can see in the error messages, what failed is the linking process, not the compiling process.
I think your linker could not find the assimp library's '.lib' files.
Did you specify the path to the assimp library's '.lib' files in the project setting?
You could do this in 'VC++ Directories' or 'Linker/Input', though I'm not sure since I'm not using my computer at the moment.

VTK - Migrating from 6.1 to 8.2 [2]

Please see this post:
VTK - Migrating from 6.1 to 8.2
I setup all settings, and I get only 3 errors, and I cannot get rid of them for days:
1>------ Build started: Project: MyApp, Configuration: Debug x64 ------
1> Creating library F:\MyApp\x64\Debug\MyApp.lib and object F:\MyApp\x64\Debug\MyApp.exp
1>MyAppView.obj : warning LNK4217: locally defined symbol ??0vtkMFCWindow##QEAA#PEAVCWnd###Z (public: __cdecl vtkMFCWindow::vtkMFCWindow(class CWnd *)) imported in function "protected: __int64 __cdecl CMyAppView::OnPostInit(unsigned __int64,__int64)" (?OnPostInit#CMyAppView##IEAA_J_K_J#Z)
1>MyAppView.obj : warning LNK4217: locally defined symbol ??1vtkMFCWindow##UEAA#XZ (public: virtual __cdecl vtkMFCWindow::~vtkMFCWindow(void)) imported in function "public: virtual void * __cdecl vtkMFCWindow::`scalar deleting destructor'(unsigned int)" (??_GvtkMFCWindow##UEAAPEAXI#Z)
1>VTKView.obj : warning LNK4217: locally defined symbol ?DrawDC#vtkMFCWindow##QEAAXPEAVCDC###Z (public: void __cdecl vtkMFCWindow::DrawDC(class CDC *)) imported in function "public: virtual void __cdecl CVTKView::OnDraw(class CDC *)" (?OnDraw#CVTKView##UEAAXPEAVCDC###Z)
1>vtkRenderingOpenGL2-8.2.lib(vtkOpenGLState.obj) : error LNK2019: unresolved external symbol __imp_SymGetLineFromAddr64 referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getProgramStack(void)" (?getProgramStack##YA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>vtkRenderingOpenGL2-8.2.lib(vtkOpenGLState.obj) : error LNK2019: unresolved external symbol __imp_SymInitialize referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getProgramStack(void)" (?getProgramStack##YA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>vtkRenderingOpenGL2-8.2.lib(vtkOpenGLState.obj) : error LNK2019: unresolved external symbol __imp_SymFromAddr referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getProgramStack(void)" (?getProgramStack##YA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>F:\MyApp\x64\Debug\MyApp.exe : fatal error LNK1120: 3 unresolved externals
1>Done building project "MyApp.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
cand you give a hint to gt away of these links errors ?
Link your binary with dbghelp.lib
e.g. add something like the following line into your CMakeLists.txt if you are using CMake
target_link_libraries(${project_name} PRIVATE dbghelp.lib)
or add it into into project (Linker/Input/Additional Dependencies) if you are not using CMake
or the add the following into main.cpp somewhere below includes
#pragma comment(lib, "dbghelp.lib") //untested
Possibly turning off VTK error logging in VTK CMake may help as well (not sure)
VTK_REPORT_OPENGL_ERRORS [ ]

Linker errors when attempting to link boost::filesystem to debug MSVC11 project

I'm attempting to use boost::filesystem in my project, but I've run into linker errors:
Error 14 error LNK1169: one or more multiply defined symbols found C:\Users\Developer\Desktop\mandala3d\Debug\mandala.exe 1 1 mandala
Error 5 error LNK2005: "public: __thiscall std::bad_cast::bad_cast(char const *)" (??0bad_cast#std##QAE#PBD#Z) already defined in MSVCRTD.lib(MSVCR110D.dll) C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(stdexcpt.obj) mandala
Error 4 error LNK2005: "public: __thiscall std::bad_cast::bad_cast(class std::bad_cast const &)" (??0bad_cast#std##QAE#ABV01##Z) already defined in MSVCRTD.lib(MSVCR110D.dll) C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(stdexcpt.obj) mandala
Error 12 error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception#std##QAE#ABQBD#Z) already defined in LIBCMT.lib(stdexcpt.obj) C:\Users\Developer\Desktop\mandala3d\mandala\MSVCRTD.lib(MSVCR110D.dll) mandala
Error 6 error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception#std##QAE#ABV01##Z) already defined in MSVCRTD.lib(MSVCR110D.dll) C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(stdexcpt.obj) mandala
Error 7 error LNK2005: "public: __thiscall std::exception::exception(void)" (??0exception#std##QAE#XZ) already defined in MSVCRTD.lib(MSVCR110D.dll) C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(stdexcpt.obj) mandala
Error 8 error LNK2005: "public: virtual __thiscall std::bad_cast::~bad_cast(void)" (??1bad_cast#std##UAE#XZ) already defined in MSVCRTD.lib(MSVCR110D.dll) C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(stdexcpt.obj) mandala
Error 9 error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception#std##UAE#XZ) already defined in MSVCRTD.lib(MSVCR110D.dll) C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(stdexcpt.obj) mandala
Error 13 error LNK2005: "public: virtual char const * __thiscall std::exception::what(void)const " (?what#exception#std##UBEPBDXZ) already defined in LIBCMT.lib(stdexcpt.obj) C:\Users\Developer\Desktop\mandala3d\mandala\MSVCRTD.lib(MSVCR110D.dll) mandala
Error 10 error LNK2005: __invalid_parameter already defined in MSVCRTD.lib(MSVCR110D.dll) C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(invarg.obj) mandala
Error 11 error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR110D.dll) C:\Users\Developer\Desktop\mandala3d\mandala\LIBCMT.lib(invarg.obj) mandala
I am building boost with the following commands:
bootstrap
.\b2
And I am pointing to $BOOSTDIR\stage\lib for the library include directory and my compiler is Visual Studio 2012 (v110).
I have tried directly linking the debug libraries that are generated in the $BOOSTDIR\lib\* directories but ran into other errors. I also suspect that that is not the standard or intended way to statically link the libraries.
What am I doing wrong here?
You're mixing both C runtime library linkages and debug/release binaries.
libcmt is the release version of the static C runtime library, while msvcrtd is the debug version of the dynamic C runtime library. You have both showing up in your errors, meaning that you're trying to mix them, which you can't do.
You need to rebuild Boost to use the same version of the C runtime as your project, or rebuild your project to use the same version as Boost. However, the fact that you currently have debug and release libraries mixed is usually a sign that something else is really wrong with your settings.
If you look in your project's properties and go to C/C++ -> Code Generation, you'll see a 'Runtime Library' field. You can change this to specify how your project should link to the C runtime. /MDd will link msvcrtd.dll, while /MT will link libcmt.lib.

Building a static library for glut 3.7 on Windows

I've been trying to compile glut as a static library without having to link with glut32.dll on runtime. I downloaded the glut windows source code but when I try to compile (default), I keep getting:
Making in glut subdirectory...
link /INCREMENTAL:NO /NOLOGO -entry:_DllMainCRTStartup#12 -dll -out:glut32.dll -def:glut.def glut_8x13.obj glut_9x15.obj glut_bitmap.obj glut_bwidth.obj glut_cindex.obj glut_cmap.obj glut_cu
rsor.obj glut_dials.obj glut_dstr.obj glut_event.obj glut_ext.obj glut_fullscrn.obj glut_gamemode.obj glut_get.obj glut_hel10.obj glut_hel12.obj glut_hel18.obj glut_init.obj glut_input.obj glut_joy.ob
j glut_key.obj glut_keyctrl.obj glut_keyup.obj glut_mesa.obj glut_modifier.obj glut_mroman.obj glut_overlay.obj glut_roman.obj glut_shapes.obj glut_space.obj glut_stroke.obj glut_swap.obj glut_swidth.
obj glut_tablet.obj glut_teapot.obj glut_tr10.obj glut_tr24.obj glut_util.obj glut_vidresize.obj glut_warp.obj glut_win.obj glut_winmisc.obj win32_glx.obj win32_menu.obj win32_util.obj win32_winproc.o
bj win32_x11.obj opengl32.lib glu32.lib winmm.lib kernel32.lib ws2_32.lib mswsock.lib advapi32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib
LINK : fatal error LNK1104: cannot open file 'glut32.lib'
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\link.EXE"' : return code '0x450'
Stop.
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\nmake.EXE"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\nmake.EXE"' : return code '0x2'
Stop.
From what I understand, glut32.lib should be compiled and created in {source}\lib\glut\ but it's not there.
Any help compiling a static library for glut would be appreciated.
Edit:
In Makefile.win
Changed:
$(link) $(LFLAGS) -out:$(GLUTDLL) -def:glut.def $(OBJS) $(LIBS)
to
lib $(OBJS) $(LIBS)
It generated \lib\glut\glut_8x13.lib not sure what the 8x13 is about but when I tried to link with it, I got some unresolved externals:
GPURenderer_test.obj : error LNK2019: unresolved external symbol __imp__glutCreateWindow#4 referenced in function "protected: __thiscall GlobalDecl::OpenGLConte
xt::OpenGLContext(unsigned int,unsigned int)" (??0OpenGLContext#GlobalDecl##IAE#II#Z)
GPURenderer_test.obj : error LNK2019: unresolved external symbol __imp__glutInitWindowSize#8 referenced in function "protected: __thiscall GlobalDecl::OpenGLCon
text::OpenGLContext(unsigned int,unsigned int)" (??0OpenGLContext#GlobalDecl##IAE#II#Z)
GPURenderer_test.obj : error LNK2019: unresolved external symbol __imp__glutInitWindowPosition#8 referenced in function "protected: __thiscall GlobalDecl::OpenG
LContext::OpenGLContext(unsigned int,unsigned int)" (??0OpenGLContext#GlobalDecl##IAE#II#Z)
GPURenderer_test.obj : error LNK2019: unresolved external symbol __imp__glutInitDisplayMode#4 referenced in function "protected: __thiscall GlobalDecl::OpenGLCo
ntext::OpenGLContext(unsigned int,unsigned int)" (??0OpenGLContext#GlobalDecl##IAE#II#Z)
GPURenderer_test.obj : error LNK2019: unresolved external symbol __imp__glutInit#8 referenced in function "protected: __thiscall GlobalDecl::OpenGLContext::Open
GLContext(unsigned int,unsigned int)" (??0OpenGLContext#GlobalDecl##IAE#II#Z)
GPURenderer_test.obj : error LNK2019: unresolved external symbol __imp__glutSwapBuffers#0 referenced in function "protected: void __thiscall GlobalDecl::OpenGLC
ontext::_executeTest(class GlobalDecl::UnitTest &)" (?_executeTest#OpenGLContext#GlobalDecl##IAEXAAVUnitTest#2##Z)
Thanks,
Ryan
It looks to me like you have something pretty badly munged up in your build setup (or you're using the wrong build setup completely, such as trying to build some samples before you've built the library they use).
To build a static library, you shouldn't be running link at all. For a static library, you compile your object files, then use lib to put them together into a library. You'd use link to build a dynamic library (DLL) or an executable, but not a static library.

Cannot compile a simple Qt program in MT mode as opposed to MD in Visual Studio 2010

I'm trying to compile using MTd in Visual Studio 2010 instead of MDd (so that the dll's are packaged in and i won't need to distribute them with my exe), but I keep getting "fatal error LNK1169: one or more multiply defined symbols found" during compilation. MDd compiles fine but does not work without MSVCP100.dll on other computers.
I'm using a static build of Qt and I'm trying to build the default Qt program that comes with the VS add-in.
Is there another way to force the linker to compile statically? All I'm trying to do is distribute a Qt program as an exe without dll's.
Here is the build log:
1>ClCompile:
1> All outputs are up-to-date.
1> cooltest1.cpp
1> moc_cooltest1.cpp
1> main.cpp
1> Generating Code...
1> All outputs are up-to-date.
1> qrc_cooltest1.cpp
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception#std##QAE#ABQBD#Z) already defined in LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception#std##UAE#XZ) already defined in LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception#std##QAE#ABV01##Z) already defined in LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _memmove already defined in LIBCMT.lib(memmove.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strncmp already defined in LIBCMT.lib(strncmp.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _isupper already defined in LIBCMT.lib(_ctype.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _isalpha already defined in LIBCMT.lib(_ctype.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _isdigit already defined in LIBCMT.lib(_ctype.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _isspace already defined in LIBCMT.lib(_ctype.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _free already defined in LIBCMT.lib(free.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __control87 already defined in LIBCMT.lib(_ieee87_.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __clearfp already defined in LIBCMT.lib(_ieee87_.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strncpy_s already defined in LIBCMT.lib(strncpy_s.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strcpy_s already defined in LIBCMT.lib(strcpy_s.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _realloc already defined in LIBCMT.lib(realloc.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &,int)" (??0exception#std##QAE#ABQBDH#Z) already defined in LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _exit already defined in LIBCMT.lib(crt0dat.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __errno already defined in LIBCMT.lib(dosmap.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _abort already defined in LIBCMT.lib(abort.obj)
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>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>c:\users\username\documents\visual studio 2010\Projects\CoolTest1\\CoolTest1.exe : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.
This is a standard linker error when you tinker with /MT. You are now linking some code that was compiled with /MT and thus has a dependency on the CRT code in libcmt.lib with some code that was compiled with /MD and thus has a dependency on the CRT code in msvcrt.lib. This is not allowed, there can be only one CRT linked into your program.
You'll need to find the code that is still compiled with /MD. This code may well exist in a .lib, like the runtime support code for QT. If QT doesn't have a .lib that supports statically linking the CRT then you're stuck with /MD. That's not uncommon, writing code that lives in DLLs that can deal with /MT is difficult.
you may rebuild QT to use static VC libraries. Go to ${QtDir}\mkspecs\win32-msvc2010\qmake.conf, and replace
QMAKE_CFLAGS_RELEASE = -O2 -MD
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
QMAKE_CFLAGS_DEBUG = -Zi -MDd
with
QMAKE_CFLAGS_RELEASE = -O2 -MT
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi
QMAKE_CFLAGS_DEBUG = -Zi -MTd
after that clean reconfigure and rebuild qt
You are linking your program statically and linking against libcmt, but at the same time, linking in code from the Qt DLLs, which are, as the name already says, dynamically linked against msvcrt.lib.
You will need to either link dynamically or recompile Qt from source as static, which isn't hard, but time-consuming.