4

I have tried to include Boost in Qt Creator since yesterday. But it doesn't work.

INCLUDEPATH += C:\boost_1_59_0

But how do I that with the ".a" files?

Sorry for my bad english.

Error Message:

C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o): duplicate section `.data$_ZZN5boost16cpp_regex_traitsIcE21get_catalog_name_instEvE6s_name[__ZZN5boost16cpp_regex_traitsIcE21get_catalog_name_instEvE6s_name]' has different size
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTVN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size

C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size
debug/main.o: In function `ZN5boost9re_detail18basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiSsi':
C:/boost_1_59_0/boost/regex/v4/basic_regex_parser.hpp:220: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o: In function `ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE':
C:/boost_1_59_0/boost/regex/v4/basic_regex_creator.hpp:774: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
C:/boost_1_59_0/boost/regex/v4/basic_regex_creator.hpp:856: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o: In function `ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE':
C:/boost_1_59_0/boost/regex/v4/basic_regex_creator.hpp:922: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o: In function `ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh':
C:/boost_1_59_0/boost/regex/v4/basic_regex_creator.hpp:1125: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o: In function `ZNK5boost9re_detail31cpp_regex_traits_implementationIcE18lookup_collatenameEPKcS4_':
C:/boost_1_59_0/boost/regex/v4/cpp_regex_traits.hpp:679: undefined reference to `boost::re_detail::lookup_default_collate_name(std::string const&)'
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o):cpp_regex_traits.cpp:(.text+0x30): undefined reference to `__gxx_personality_sj0'
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o):cpp_regex_traits.cpp:(.text+0x6c): undefined reference to `_Unwind_SjLj_Register'
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o):cpp_regex_traits.cpp:(.text+0x261): undefined reference to `_Unwind_SjLj_Unregister'
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o):cpp_regex_traits.cpp:(.text+0x430): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned int&, unsigned int)'
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o):cpp_regex_traits.cpp:(.text+0x4ec): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned int&, unsigned int)'
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o):cpp_regex_traits.cpp:(.text+0x5dc): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned int&, unsigned int)'
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o):cpp_regex_traits.cpp:(.text+0x74e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned int)'
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o):cpp_regex_traits.cpp:(.text+0x76d): undefined reference to `std::runtime_error::runtime_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o):cpp_regex_traits.cpp:(.text+0x84c): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned int&, unsigned int)'
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o):cpp_regex_traits.cpp:(.text+0x8ae): undefined reference to `_Unwind_SjLj_Resume'
C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o):cpp_regex_traits.cpp:(.text+0x937): undefined reference to `_Unwind_SjLj_Resume'
C:/Qt/Qt5.5.0/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: C:/boost_1_59_0/stage/lib/libboost_regex-mgw51-mt-1_59.a(cpp_regex_traits.o): bad reloc address 0x50 in section `.rdata'
collect2.exe: error: ld returned 1 exit status
Orest Hera
  • 6,706
  • 2
  • 21
  • 35
Grevak
  • 533
  • 5
  • 17
  • 1
    What are your error messages? – Orest Hera Sep 27 '15 at 10:53
  • Similar issues were observed in http://stackoverflow.com/questions/11635485/regex-boost-library-linking-in-release-mode-warns-duplicate-section-has-differe and http://stackoverflow.com/questions/14181351/i-got-duplicate-section-errors-when-compiling-boost-regex-with-size-optimizati The advises to check compiling options, for example add to your project compile option: `-march=i686`; other suggestion `-fno-tree-vectorize`, check optimization option (if `-Os` was used, it should be used for all project files). Compile options may be added with `QMAKE_CXXFLAGS += -march=i686`. – Orest Hera Sep 27 '15 at 11:44
  • You are building your project in debug mode, however libraries are used for release. To avoid issues with that you should link with debug library files marked by `-d`, for example `-lboost_filesystem-mgw51-mt-d-1_59` – Orest Hera Sep 27 '15 at 12:18
  • You used different mingw versions for compiling boost (5.1) and Qt project (4.9.2). At first before playing with compiler options just build boost by mingw that is used for Qt. Put this path for building boost: `PATH=C:\Qt\Qt5.5.0\Tools\mingw492_32\bin;%PATH%` – Orest Hera Sep 27 '15 at 13:28

1 Answers1

5

To link external libraries in Qt project you should provide required linker options. Those options can be added to LIBS variable in the .pro file.

According to Link Your Program to a Boost Library:

Auto-Linking

Most Windows compilers and linkers have so-called “auto-linking support,” which eliminates the second challenge. Special code in Boost header files detects your compiler options and uses that information to encode the name of the correct library into your object files; the linker selects the library with that name from the directories you've told it to search.

The GCC toolchains (Cygwin and MinGW) are notable exceptions; GCC users should refer to the linking instructions for Unix variant OSes for the appropriate command-line options to use.

For MinGW the library search path is added by -Lpath option and the library name that should be linked by -llibrary, where library is the library name dropping the filename's leading lib and trailing suffix (.a in this case):

LIBS += -L"C:/boost_library_directory" -lname1 -lname2

Update according to new log of error messages

You use two different MinGW compilers:

  • MinGW 4.9.2 shipped with Qt
  • external MinGW 5.1.0 to build Boost

There is too large gap between those compilers and your Boost binaries are not compatible with Qt compiler. I was able to reproduce your error messages using MinGW 5.1.0 for Boost and MinGW 4.8 in my Qt installation.

Build Boost using compiler provided by Qt. Set proper toolchain path for building Boost:

PATH=C:\Qt\Qt5.5.0\Tools\mingw492_32\bin;%PATH%

It should work with proper library versions, for example -lboost_regex-mgw492-mt-1_59.

Note that there are also two types of Boost binaries: release and debug (tagged by -d in file name). According to doc:

Although it's true that sometimes these choices don't affect binary compatibility with other compiled code, you can't count on that with Boost libraries.

So, you may want different project options for debug and release builds. In Qt .pro it can be done by testing CONFIG variable:

# set common library path
LIBS += -L"C:/boost_1_59_0/stage/lib"
CONFIG(debug, debug|release) {
    # debug libraries
    LIBS += -lboost_regex-mgw492-mt-d-1_59
}
CONFIG(release, debug|release) {
    # release libraries
    LIBS += -lboost_regex-mgw492-mt-1_59

    # Release variant of Boost binary libraries is compiled with
    # disabled run-time assertion (NDEBUG is defined).
    # To align binaries with header-only libraries and other headers
    # it is possible to define NDEBUG for project release build.
    # It is not defined in Qt by default.
    DEFINES += NDEBUG
}
Orest Hera
  • 6,706
  • 2
  • 21
  • 35
  • cannot find -llibboost_filesystem-mgw51-mt-1_59 and cannot find -llibboost_system-mgw51-mt-1_59 and cannot find -llibboost_regex-mgw51-mt-1_59 – Grevak Sep 27 '15 at 11:17
  • How about `-lboost_filesystem-mgw51-mt-1_59` without `lib` prefix? – Orest Hera Sep 27 '15 at 11:18
  • Now is there an error message that's too long for comments -.- – Grevak Sep 27 '15 at 11:21
  • LIBS += -L"C:/boost_1_59_0/stage/lib" -lboost_filesystem-mgw51-mt-1_59 LIBS += -L"C:/boost_1_59_0/stage/lib" -lboost_system-mgw51-mt-1_59 LIBS += -L"C:/boost_1_59_0/stage/lib" -lboost_regex-mgw51-mt-1_59 my file – Grevak Sep 27 '15 at 11:23
  • @Grevak You can edit your original question post and put those error messages there. – Orest Hera Sep 27 '15 at 11:23
  • @Grevak You do not need to add the same library path many times. It is enough to add it once `LIBS += -L"C:/boost_1_59_0/stage/lib"` and you need to provide name of each required library as `-l...`. Anyway it should not lead to errors. – Orest Hera Sep 27 '15 at 11:26
  • @Grevak That's it! I updated my answer according to your error messages. – Orest Hera Sep 27 '15 at 14:32