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.
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 have a running project in Visual Studio 2010 using OpenCV 2.49 and Point Cloud Library 1.6 . I am trying to make a standalone executable so I don´t need to install OpenCV and PCL in other computers to make it run.
OpenCV and PCL were installed using the precompiled binaries, and PCL also included boost (1.49) and vtk (5.8) libraries, among others.
For making the static build, I changed the Runtime Library in VS to /MT. Then, some Boost static libraries were missing, so I installed boost again (version 1.56, I believe I needed the libs with the 's').
Then I had errors like:
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)
so I added msvcrt.lib, msvcprt.lib to the section "Ignore Specific Defaul Libraries".
Now I have errors like:
1>vtkCommon.lib(vtkVoidArray.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(void const *)" (__imp_??6?$basic_ostream#DU?$char_traits#D#std###std##QAEAAV01#PBX#Z)
1>vtkCommon.lib(vtkVariantArray.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(void const *)" (__imp_??6?$basic_ostream#DU?$char_traits#D#std###std##QAEAAV01#PBX#Z)
1>vtkCommon.lib(vtkTimerLog.obj) : error LNK2001: unresolved external symbol __imp__strncpy
1>vtkCommon.lib(vtkMath.obj) : error LNK2001: unresolved external symbol __imp__modf
1>vtksys.lib(SystemTools.obj) : error LNK2001: unresolved external symbol __imp___utime64
1>OLDNAMES.lib(unlink.obi) : error LNK2001: unresolved external symbol __imp__unlink
The vtk library is included exactly the same way as in the non-static release build. And, if I understood it correctly, .lib is an extension for a static libray.
What am I doing wrong?
EDIT: I tried using CMake, but I am getting the same kind of errors (There are a lot more):
2>vtksys.lib(SystemTools.obj) : error LNK2019: unresolved external symbol __imp___time64 referenced in function _time
2>vtkCommon.lib(vtkVariant.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_istream<char,struct std::char_traits<char> > & __thiscall std::basic_istream<char,struct std::char_traits<char> >::operator>>(short &)" (__imp_??5?$basic_istream#DU?$char_traits#D#std###std##QAEAAV01#AAF#Z) referenced in function "short __cdecl vtkVariantStringToNumeric<short>(class vtkStdString,bool *,short *)" (??$vtkVariantStringToNumeric#F##YAFVvtkStdString##PA_NPAF#Z)
This is my CMakeList.txt:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(3DVisualizerCM)
set(BUILD_SHARED_LIBS OFF)
SET(CMAKE_EXE_LINKER_FLAGS "/NODEFAULTLIB:msvcrt.lib
/NODEFAULTLIB:msvcprt.lib")
find_package(PCL 1.4 REQUIRED)
find_package(OpenCV REQUIRED)
include_directories(${PCL_INCLUDE_DIRS} )
link_directories(${PCL_LIBRARY_DIRS} )
add_definitions(${PCL_DEFINITIONS} )
add_executable (3D_v4
3D_v4.cpp
C3DVisualizer.cpp
C3DVisualizerMultiple.cpp
C3DVisualizerSingle.cpp
CCameraParameters.cpp
CImageTrack.cpp
CImg.cpp
CImgMultiple.cpp
CImgSingle.cpp
helpers.cpp
)
target_link_libraries (3D_v4 ${PCL_LIBRARIES} ${OpenCV_LIBS})
The precompiled vtk libraries you are using from PCL must have been compiled using /MD flag (Multithreaded DLL) in Visual Studio. You need to recompile them using the /MT flag (Multithreaded static link).
I use CS106 library in the university.After changing Visual Studio 2008 with Visual Studio 2010, I have problems with building new projects or the old ones.I think that new Visual studio is not compatible with CS106 library.Can anyone tell how to fix this problem?
This is the output:
1>------ Build started: Project: Blank, Configuration: Debug Win32 ------
1>Build started 3/15/2011 2:03:21 PM.
1>InitializeBuildStatus:
1> Touching "Debug\Blank.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1>CS106CPPLib.lib(strutils.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran#_String_base#std##SAXXZ)
1>CS106CPPLib.lib(simpio.obj) : error LNK2019: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran#_String_base#std##SAXXZ) referenced in function "public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::assign(class std::basic_string,class std::allocator > const &,unsigned int,unsigned int)" (?assign#?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##QAEAAV12#ABV12#II#Z)
1>CS106CPPLib.lib(genlib.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran#_String_base#std##SAXXZ)
1>CS106CPPLib.lib(init.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran#_String_base#std##SAXXZ)
1>CS106CPPLib.lib(pcgraphics.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran#_String_base#std##SAXXZ)
1>CS106CPPLib.lib(strutils.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen#_String_base#std##SAXXZ)
1>CS106CPPLib.lib(simpio.obj) : error LNK2019: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen#_String_base#std##SAXXZ) referenced in function "protected: bool __thiscall std::basic_string,class std::allocator >::_Grow(unsigned int,bool)" (?_Grow#?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##IAE_NI_N#Z)
1>CS106CPPLib.lib(genlib.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen#_String_base#std##SAXXZ)
1>CS106CPPLib.lib(init.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen#_String_base#std##SAXXZ)
1>CS106CPPLib.lib(pcgraphics.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen#_String_base#std##SAXXZ)
1>CS106CPPLib.lib(simpio.obj) : error LNK2019: unresolved external symbol "private: static void __cdecl std::locale::facet::facet_Register(class std::locale::facet *)" (?facet_Register#facet#locale#std##CAXPAV123##Z) referenced in function "public: void __thiscall std::locale::facet::_Register(void)" (?_Register#facet#locale#std##QAEXXZ)
1>CS106CPPLib.lib(strutils.obj) : error LNK2001: unresolved external symbol "private: static void __cdecl std::locale::facet::facet_Register(class std::locale::facet *)" (?facet_Register#facet#locale#std##CAXPAV123##Z)
1>CS106CPPLib.lib(simpio.obj) : error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF#std##3JB)
1>CS106CPPLib.lib(strutils.obj) : error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF#std##3JB)
1>Debug\Blank.exe : fatal error LNK1120: 4 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.97
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here is the solution:
http://melbsdailydigest.blogspot.com/
1.) Download one of the latest projects from the Stanford CS106B Website:
CS106B Assignment 1
2.) Unzip the project and find its subdirectory \CS106. This is the folder that contains all the library (CS106CPPLib.lib) and header files for the CS106 program.
3.) Copy this folder as a subdirectory to one of your assignment folders (ex. C:\Assignment1\CS106.
4.) Startup Visual Studio2008 and click File->New->Project… When given the choice choose to create a new Console program.
5.) You’ll then be presented with a new project with multiple files including stdafx.h, stdafx.cpp and similarly named files for whatever you named your project when prompted earlier. DELETE/ REMOVE all these files from the project.
6.) Right click the Source File Folder and choose Add->Existing Item… Choose the first assignment file (Assign1warmup.cpp).
7.) If you compile at this point you’ll realize that it’s still looking for the stdafx.h precompiled header. Let’s fix that. Go to Project->Assignment1 Properties… (or whatever your project might be named). Go to the option in the “tree” menu for Configuration Properties->C/C++->Pre-Compiled Headers . Under the option for Create/Use Precompiled header, choose the drop down option for Not Using Precompiled headers.
8.) While you’re in this section, take the time now to also select the location for the header files for this project. Under the Configuration Properties->C/C++->General section choose the Additional Include Directories option and use the … to browse and select the CS106 folder that you copied to your project folder earlier.
9.) One last thing you should change here is in the Configuration Properties->C/C++->Code Generation section. Change the default (which I believe is for a Multi-Threaded Debug .DLL) to just Multi-Threaded Debug (or just Multi-Threaded if you are doing your release build).
10.) Lastly, we’ll need to let the linker know where to find the CS106 library file. To do that you’ll need to make 2 additional settings. One is in the Configuration Properties->Linker->General section where you can select the location of your additional library files in the section titled appropriately enough – “Additional Library Directories”. You’ll also need to add your library to the project through the “Additional Dependencies” section which is under Configuration Properties->Linker->Input. Just type in CS106CPPLIB.lib.
Note: I found that there seems to be some difference in the menus you get and the settings that get saved depending on what your selection is at the moment in the solution Explorer Window. I originally made all my changes while I was selecting the actual source file, but there were no linker menus at that point. I had to move up to the Source File Folder level to get additional menus where I could set my linker options. Also important to note is that if you make your settings at the lower level (ie. Cpp file) they seem to supersede whatever is set in the level above it.
At this point the project should correctly build with the selection of the Build->Rebuild Solution command.
Happy programming!
The source code would help to fix this. But....did you add #include <string> at the top of the file producing the errors?
I was using a ITK library. When I wrote a sample program using this library, I've got following linker errors. As we can see these all "unresolved" symbols are Windows API functions and these windows API functions were used by ITK library and not my program.
Error 1 error LNK2019: unresolved external symbol _SnmpUtilVarBindFree#4 referenced in function "int __cdecl gdcm::GetMacAddrSys(unsigned char *)" (?GetMacAddrSys#gdcm##YAHPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 2 error LNK2019: unresolved external symbol _SnmpUtilOidNCmp#12 referenced in function "int __cdecl gdcm::GetMacAddrSys(unsigned char *)" (?GetMacAddrSys#gdcm##YAHPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 3 error LNK2019: unresolved external symbol _SnmpUtilOidCpy#8 referenced in function "int __cdecl gdcm::GetMacAddrSys(unsigned char *)" (?GetMacAddrSys#gdcm##YAHPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 4 error LNK2019: unresolved external symbol _WSAStartup#8 referenced in function "int __cdecl gdcm::GetMacAddrSys(unsigned char *)" (?GetMacAddrSys#gdcm##YAHPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 5 error LNK2019: unresolved external symbol __imp__UuidCreate#4 referenced in function "private: static bool __cdecl gdcm::Util::GenerateUUID(unsigned char *)" (?GenerateUUID#Util#gdcm##CA_NPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 6 error LNK2019: unresolved external symbol _gethostbyname#4 referenced in function "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl gdcm::Util::GetIPAddress(void)" (?GetIPAddress#Util#gdcm##CA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 7 error LNK2019: unresolved external symbol _gethostname#8 referenced in function "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl gdcm::Util::GetIPAddress(void)" (?GetIPAddress#Util#gdcm##CA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 8 error LNK2019: unresolved external symbol _WSACleanup#0 referenced in function "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl gdcm::Util::GetIPAddress(void)" (?GetIPAddress#Util#gdcm##CA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
These errors have raised few questions in my mind. For some of them I think I know the answers but I need confirmation if I'm right or wrong.
These Windows API functions are used in gdcmUtil.cpp (because it says gdcmUtil.obj). So, compiler compiles gdcmUtil.cpp to (say)gdcmUtil.asm and it is assembler assembles it to gdcmUtil.obj. Since while compiling the library we are not generating any exe files. These *.obj files aren't linked against any other *.obj. So, windows API symbols are still external symbols for that module and thus left unresolved. Right?
Who is generating the *.LIB file? I mean compiler is generating *.s file and Assembler is generating *.obj file and we are not using linker. So, from where did we get *.lib file? Who packed all *.obj files to a *.lib file?
How are Windows API applications (programs that are written in C and use Windows API) are compiled? I mean, because its a standalone applications how are these WIN32 API symbols resolved? Assuming, I've written such program can anyone tell me what do I need to sucessfully build application?
I know that Windows API is implemented in kernel32.dll, gdi32.dll, user32.dll (which may in turn import some other dlls like wsock32.dll for networking API etc.) but the question is How to use these functions in Windows API functions in a C program. I mean how to dynamically link against these DLLs
In my quest to find answer to my problem of Linker errors. I discovered that I must add wsock32.lib (for WinSock 1.1) or ws2_32.lib(for WinSock 2) or snmpapi.lib to Linker Input.
Since when Windows API is being statically linked?
Since when windows API is being shipped in static libraries (*.lib files)?
In which directory can I find all these strange *.lib files?
Now, Is there any alternative solution other than adding *.lib files to linker input files? because when ever I use some new ITK library function, I get a new linker error. I've to Google to find in which *.lib file this specific symbol (window api function) belongs to then add that *.lib file to my linker input. Its driving me crazy! Is there any sane way?
Yes, that's right.
Who is generating what .lib file? A static library is normally generated by the lib utility. A library for a dll is normally generated by the linker.
You resolve Windows symbols by linking with the right libraries.
Again, by linking against the appropriate library (e.g., kernel32.lib, gdi32.lib and user32.lib for the three DLLs you mentioned).
It's not statically linked. You link against the library. In the case of a library for a DLL (such as those listed above) the linker uses that to embed a record into the executable that tells the loader which DLL to use to resolve those symbols. The .lib files are in the lib subdirectory of wherever you installed the SDK (typically something like C:\Program Files\Microsoft SDKs\Windows\v6.0A. Normally the SDK installer will add those where necessary so you don't have to explicitly specify that directory when linking from the command line or within Visual Studio.
There are a few, though it's open to question whether they're really an improvement. One possibility is to use a pragma to tell the linker to use a particular library:
#pragma comment(lib, "ws2_32.lib")
This is particularly useful in a header if it uses functions that depend on a particular library.
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.