LNK2005 errors occured on my own project building process.

Added by Kapoios Kapou 10 months 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 (R) Windows (R) Resource Compiler Version 6.0.5724.0
Copyright (C) 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_init@program_options@boost@QAEAAV012@PBD0@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_init@program_options@boost
@QAEAAV012@PBDPBVvalue_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<char>,class std::allocator<char> > const &,unsigned int,unsigned int)" (??0options_description@program_options@boost@QAE@ABV?$basic_string@DU?$char_traits@D@std@V?$allocator@D@2@std@II@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 & __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@@std@AAV23@ABVoptions_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<char>::parse(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 &,bool)const " (?parse
?$value_semantic_codecvt_helper@D@program_options@boost@EBEXAAVany@3@ABV?$vector@V?$basic_string@DU?$char_traits@D@std@V?$allocator@D@2@std@V?$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)
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@std@V?$allocator@V?$basic_string@DU?$char_traits@D@std@V?$allocator@D@2@std@2@std@PAV?$basic_string@DU?$char_traits@D@std@V?$allocator@D@2@5@H@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_occurrence@validators@program_options@boost
@YAXABVany@3@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<char>,class std::allocator<char> > const &)" (??0invalid_option_value@program_options@boost
@QAE@ABV?$basic_string@DU?$char_traits@D@std@V?$allocator@D@2@std@@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::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@std@1@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: virtual char const * __thiscall boost::program_options::validation_error::what(void)const " (?what@validation_error@program_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<char>,class std::allocator<char> > __cdecl boost::program_options::to_internal(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?to_internal@program_options@boost@YA?AV?$basic_string@DU?$char_traits@D@std@V?$allocator@D@2@std@ABV34@@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
SET

  1. The names of the Wt libraries. See cmake manual for syntax: the
  2. 'debug' and 'optimized' tell what names to use for non-debug and
  3. debug builds. On MSVS, this is important to get right for runtime
  4. library compatibility reasons.
    SET(WT_LIBS
    optimized wthttp debug wthttpd
    optimized wt debug wtd)
  1. Usually there's no need to set BOOST_LIBS on windows; auto-linking is used.
  2. The libraries as listed below is a bit naive; the names tend to be more
  3. complex, and especially on windows, you'll have to specify the optimized/debug
  4. builds separately (as done above for Wt). The libraries as listed below may
  5. 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)
  1. tell the compiler where it should look for extra include files
    INCLUDE_DIRECTORIES(${WT_INSTALL_DIR}/include)
    INCLUDE_DIRECTORIES(${BOOST_INSTALL_DIR})
  1. 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

  1. tell the linker where all these libraries should be searched for
    #LINK_DIRECTORIES (
  2. ${WT_INSTALL_DIR}/lib/
  3. ${BOOST_INSTALL_DIR}/lib/
    #)

ADD_EXECUTABLE(
GOP.wt
Main.C
)

  1. 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 Magnifier - cmake cache from last build (12.4 KB)


Replies (2)

RE: LNK2005 errors occured on my own project building process. - Added by Wim Dumon 10 months 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.

(1-2/2)