LNK2005 errors occured on my own project building process.
Added by Anonymous almost 13 years ago
Hi all. You can consider this post as a "continuation" of [[[http://redmine.webtoolkit.eu/boards/2/topics/4714]]].
I'm overly doomed by linking dependencies, so I wasted a week's time to just trying to build my own Wt project (I hoped I coded it well, so it will run successfully after I get rid of building failures).
After success on solving the problem referenced in my above-mentioned post (cannot open boost/any), I got those linker errors (complete build log from MSVC 2008):
>
> ------ Build started: Project: ZERO_CHECK, Configuration: Debug Win32 ------
> Checking Build System
> CMake does not need to re-run because C:/Users/Tekmon/Desktop/GOP/GEOapp/build/CMakeFiles/generate.stamp is up-to-date.
> Build log was saved at "file://c:\Users\Tekmon\Desktop\GOP\GEOapp\build\ZERO_CHECK.dir\Debug\BuildLog.htm"
> ZERO_CHECK - 0 error(s), 0 warning(s)
> ------ Build started: Project: GOP.wt, Configuration: Debug Win32 ------
> Compiling...
> Main.C
> Compiling manifest to resources...
>
Microsoft ® Windows ® Resource Compiler Version 6.0.5724.0
Copyright © Microsoft Corporation. All rights reserved.
Linking...
libboost_program_options-vc90-mt-gd-1_47.lib(options_description.obj) : error LNK2005: "public: class boost::program_options::options_description_easy_init & __thiscall boost::program_options::options_description_easy_init::operator()(char const ,char const)" (??Roptions_description_easy_initprogram\_options@boost@
QAEAAV012PBD0
Z) already defined in boost_program_options-vc90-mt-gd-1_47.lib(boost_program_options-vc90-mt-gd-1_47.dll)
libboost_program_options-vc90-mt-gd-1_47.lib(options_description.obj) : error LNK2005: "public: class boost::program_options::options_description_easy_init & __thiscall boost::program_options::options_description_easy_init::operator()(char const ,class boost::program_options::value_semantic const,char const *)" (??Roptions_description_easy_initprogram\_options@boost@
QAEAAV012PBDPBVvalue\_semantic@12@0
Z) already defined in boost_program_options-vc90-mt-gd-1_47.lib(boost_program_options-vc90-mt-gd-1_47.dll)
libboost_program_options-vc90-mt-gd-1_47.lib(options_description.obj) : error LNK2005: "public: __thiscall boost::program_options::options_description::options_description(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,unsigned int,unsigned int)" (??0options_descriptionprogram\_options@boost@
QAEABV?$basic\_string@DU?$char\_traits@D@std@
V?$allocatorD@2@
stdII`Z) already defined in boost_program_options-vc90-mt-gd-1_47.lib(boost_program_options-vc90-mt-gd-1_47.dll)
AAV23
libboost_program_options-vc90-mt-gd-1_47.lib(options_description.obj) : error LNK2005: "public: class boost::program_options::options_description & __thiscall boost::program_options::options_description::add(class boost::program_options::options_description const &)" (?add`options_description`program\_options@boost@`QAEAAV123`ABV123@`Z) already defined in boost\_program\_options-vc90-mt-gd-1\_47.lib(boost\_program\_options-vc90-mt-gd-1\_47.dll)
libboost\_program\_options-vc90-mt-gd-1\_47.lib(options\_description.obj) : error LNK2005: "public: class boost::program\_options::options\_description\_easy\_init \_\_thiscall boost::program\_options::options\_description::add\_options(void)" (?add\_options`options\_description@program\_options@boost@`QAE?AVoptions_description_easy_init`23`XZ) already defined in boost\_program\_options-vc90-mt-gd-1\_47.lib(boost\_program\_options-vc90-mt-gd-1\_47.dll)
libboost\_program\_options-vc90-mt-gd-1\_47.lib(options\_description.obj) : error LNK2005: "class std::basic\_ostream<char,struct std::char\_traits<char> > & \_\_cdecl boost::program\_options::operator<<(class std::basic\_ostream<char,struct std::char\_traits<char> > &,class boost::program\_options::options\_description const &)" (??6program\_options`boost@`YAAAV?$basic_ostream`DU?$char\_traits@D@std@@`stdABVoptions\_description@01@
Z) already defined in boost_program_options-vc90-mt-gd-1_47.lib(boost_program_options-vc90-mt-gd-1_47.dll)
libboost_program_options-vc90-mt-gd-1_47.lib(value_semantic.obj) : error LNK2005: "private: virtual void __thiscall boost::program_options::value_semantic_codecvt_helper::parse(class boost::any &,class std::vector<class std::basic_string<char,struct std::char_traits,class std::allocator >,class std::allocator<class std::basic_string<char,struct std::char_traits,class std::allocator > > > const &,bool)const " (?parse?$value\_semantic\_codecvt\_helper@D@program\_options@boost@
EBEXAAVany3@ABV?$vector@V?$basic\_string@DU?$char\_traits@D@std@
V?$allocatorD@2@
stdV?$allocator`V?$basic\_string@DU?$char\_traits@D@std@`V?$allocator`D@2@`std`@`2
std_N`Z) already defined in boost_program_options-vc90-mt-gd-1_47.lib(boost_program_options-vc90-mt-gd-1_47.dll)
V?$allocator
libboost_program_options-vc90-mt-gd-1_47.lib(value_semantic.obj) : error LNK2005: "void __cdecl boost::program_options::validate(class boost::any &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *,int)" (?validate`program_options`boost@`YAXAAVany`2@ABV?$vector@V?$basic\_string@DU?$char\_traits@D@std@`V?$allocator`D@2@`stdV?$basic\_string@DU?$char\_traits@D@std@
V?$allocatorD@2@
std@
2std
PAV?$basic_stringDU?$char\_traits@D@std@
V?$allocatorD@2@
5H
Z) already defined in boost_program_options-vc90-mt-gd-1_47.lib(boost_program_options-vc90-mt-gd-1_47.dll)
libboost_program_options-vc90-mt-gd-1_47.lib(value_semantic.obj) : error LNK2005: "void __cdecl boost::program_options::validators::check_first_occurrence(class boost::any const &)" (?check_first_occurrencevalidators@program\_options@boost@
YAXABVany3@
Z) already defined in boost_program_options-vc90-mt-gd-1_47.lib(boost_program_options-vc90-mt-gd-1_47.dll)
libboost_program_options-vc90-mt-gd-1_47.lib(value_semantic.obj) : error LNK2005: "public: __thiscall boost::program_options::invalid_option_value::invalid_option_value(class std::basic_string<char,struct std::char_traits,class std::allocator > const &)" (??0invalid_option_valueprogram\_options@boost@
QAEABV?$basic\_string@DU?$char\_traits@D@std@
V?$allocatorD@2@
std`Z) already defined in boost_program_options-vc90-mt-gd-1_47.lib(boost_program_options-vc90-mt-gd-1_47.dll)
1
libboost_program_options-vc90-mt-gd-1_47.lib(value_semantic.obj) : error LNK2005: "public: __thiscall boost::program_options::validation_error::validation_error(enum boost::program_options::validation_error::kind_t,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0validation_error`program_options`boost@`QAE`W4kind\_t@012@ABV?$basic\_string@DU?$char\_traits@D@std@`V?$allocator`D@2@`stdZ) already defined in boost_program_options-vc90-mt-gd-1_47.lib(boost_program_options-vc90-mt-gd-1_47.dll)
validation_error
libboost_program_options-vc90-mt-gd-1_47.lib(value_semantic.obj) : error LNK2005: "public: virtual char const * __thiscall boost::program_options::validation_error::what(void)const " (?whatprogram\_options@boost@
UBEPBDXZ) already defined in boost_program_options-vc90-mt-gd-1_47.lib(boost_program_options-vc90-mt-gd-1_47.dll)
libboost_program_options-vc90-mt-gd-1_47.lib(convert.obj) : error LNK2005: "class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl boost::program_options::to_internal(class std::basic_string<char,struct std::char_traits,class std::allocator > const &)" (?to_internalprogram\_options@boost@
YA?AV?$basic_stringDU?$char\_traits@D@std@
V?$allocatorD@2@
stdABV34
Z) already defined in boost_program_options-vc90-mt-gd-1_47.lib(boost_program_options-vc90-mt-gd-1_47.dll)
Creating library C:\Users\Tekmon\Desktop\GOP\GEOapp\build\Debug\GOP.wt.lib and object C:\Users\Tekmon\Desktop\GOP\GEOapp\build\Debug\GOP.wt.exp
C:\Users\Tekmon\Desktop\GOP\GEOapp\build\Debug\GOP.wt.exe : fatal error LNK1169: one or more multiply defined symbols found
Build log was saved at "file://c:\Users\Tekmon\Desktop\GOP\GEOapp\build\GOP.wt.dir\Debug\BuildLog.htm"
GOP.wt - 14 error(s), 0 warning(s)
Build: 1 succeeded, 1 failed, 1 up-to-date, 0 skipped
I did some research on this error code and I tried any error-fixing method that I found (i.e [[[http://stackoverflow.com/questions/6623778/cmake-linking-to-boost-error-lnk2005?lq=1]]] , http://stackoverflow.com/questions/6468681/problem-linking-to-boost-library-with-cmake-generated-project-file-for-msvc9 - I should mention that a LNK1104 ocuured previously, but it's cause was that I've mispelled the names of libboost libraries in my CMakeLists.txt).
So far, I tried to fix those errors by disabling cmake's auto-linking, moving boost's dlls to another directory (to left only the static libraries into lib directory) and applying some other suggestions but they persist.
My CMakeLists.txt placed on source directory is:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET (WT_INSTALL_DIR \"C:/Program Files/WT\")
SET (BOOST_INSTALL_DIR \"C:/Program Files/boost/boost_1_47\")
- The names of the Wt libraries. See cmake manual for syntax: the
- 'debug' and 'optimized' tell what names to use for non-debug and
- debug builds. On MSVS, this is important to get right for runtime
- library compatibility reasons.
SET (WT_LIBS optimized wthttp debug wthttpd optimized wt debug wtd)
<!-- -->
- Usually there's no need to set BOOST_LIBS on windows; auto-linking is used.
- The libraries as listed below is a bit naive; the names tend to be more
- complex, and especially on windows, you'll have to specify the optimized/debug
- builds separately (as done above for Wt). The libraries as listed below may
- work on Linux. If not, consider using cmake's FindBoost method
SET (BOOST_LIBS boost_signals-vc90-mt-gd-1_47 boost_regex-vc90-mt-gd-1_47 boost_thread-vc90-mt-gd-1_47 boost_filesystem-vc90-mt-gd-1_47 boost_system-vc90-mt-gd-1_47 boost_random-vc90-mt-gd-1_47 boost_date_time-vc90-mt-gd-1_47 boost_program_options-vc90-mt-gd-1_47)
<!-- -->
- tell the compiler where it should look for extra include files
INCLUDE_DIRECTORIES(${WT_INSTALL_DIR}/include)
INCLUDE_DIRECTORIES(${BOOST_INSTALL_DIR})
<!-- -->
- tell the linker where all these libraries should be searched for
LINK_DIRECTORIES (
${WT_INSTALL_DIR}/lib/
${BOOST_INSTALL_DIR}/lib/
)
#test:
ADD_DEFINITIONS(-DBOOST_ALL_NO_LIB)
#ADD_DEFINITIONS(-DBOOST_ALL_DYN_LINK)
#test:
SET (BOOST_USE_STATIC_LIBS ON)
- tell the linker where all these libraries should be searched for
#LINK_DIRECTORIES ( - ${WT_INSTALL_DIR}/lib/
- ${BOOST_INSTALL_DIR}/lib/
#)
ADD_EXECUTABLE(
GOP.wt
Main.C
)
- tell cmake what it should link your executable to
TARGET_LINK_LIBRARIES (
GOP.wt
${WT_LIBS} ${BOOST_LIBS} ${SYSTEM_LIBS}
)
I also checked CMakeOutput.txt and TargetDirectories. My CMakeCache.txt from last build is attached to this post.
Any help would be appreciated.
CMakeCache.txt (12.4 KB) CMakeCache.txt | cmake cache from last build |
Replies (2)
RE: LNK2005 errors occured on my own project building process. - Added by Wim Dumon almost 13 years ago
It looks like you're linking twice to each boost library. You cannot do this, you'll get the errors that you get.
As I commented in the CMakeLists.txt, leave BOOST_LIBS blank if you're on msvs. The correct boost libraries will be automatically linked against (unless you specifically disable this feature of boost through some compile-time define). The only thing you have to do is to make sure that the linker finds the library, by including the path to your boost library in LINK_DIRECTORIES.
Best regards,
Wim.
RE: LNK2005 errors occured on my own project building process. - Added by Anonymous almost 13 years ago
Thank You Wim!