undefined reference to boost::filesystem::path_traits::convert - c++

I am trying to compile a program using cmake, and am seeing the following linker error:
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log_setup.so:
undefined reference to
boost::filesystem::path_traits::convert(wchar_t const*, wchar_t
const*, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >&, std::codecvt<wchar_t, char, __mbstate_t>
const&)' /home/quant/bin/boost_1_61_0/stage/lib/libboost_log.so:
undefined reference to
boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry
const&, std::__cxx11::basic_string,
std::allocator >&)'
The linker command that ninja generated looks like this:
g++ -pthread -DBOOST_ALL_DYN_LINK
utility/test/CMakeFiles/utilityTest.dir/loadCSVTests.cpp.o
utility/test/CMakeFiles/utilityTest.dir/main.cpp.o
utility/test/CMakeFiles/utilityTest.dir/randomDeviceTests.cpp.o -o
utility/test/utilityTest -rdynamic
/home/quant/bin/boost_1_61_0/stage/lib/libboost_thread.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_program_options.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_serialization.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_unit_test_framework.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_system.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log_setup.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_filesystem.so
utility/lib/libutilityLib.a utility/testLib/libutilityTestLib.a
utility/lib/libutilityLib.a
/home/quant/bin/boost_1_61_0/stage/lib/libboost_thread.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_program_options.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_serialization.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_unit_test_framework.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_system.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log_setup.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_filesystem.so
-Wl,-rpath,/home/quant/bin/boost_1_61_0/stage/lib
As you can see, I am linking against boost_filesystem and boost_system, so it's not the same problem as referenced on this SO post (and the many others like it).
I am using boost 1.61, which I compiled with gcc 5.3 (the same compiler as the one I'm compiling my program with).
What am I doing wrong?

I had a similar issue, this could be because of a new ABI which is introduced from gcc 5.1.
https://github.com/openframeworks/openFrameworks/issues/4203
I fixed mine by adding "add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)" to CMakeLists.txt

Related

How to maintain compatibility between gcc 7 and gcc 9 with -Ofast

I have library which I have compiled on Ubuntu 18.04 using the version of gcc which comes bundled in the build-essential package, gcc 7.5.0.
If I then try to compile an application on Ubuntu 20.04 and link against the that library I previous built using the default gcc version, gcc 9.3.0, then I get a bunch of errors such as undefined reference to __expf_finite. Note, I do compile my original library with -Ofast as I need to take advantage of all optimizations. According to this SO question, it suggests that math-finite.h is no longer supported by the libc update.
So as a possible solution, I tried compiling my library on Ubuntu 20.04 using gcc 9.3.0 to then see if I can link against that library using an application compiled with gcc 7.5.0 on Ubuntu 18.04 (basically the reverse of the first scenario).
However, when I do this, I get ABI compat errors with std::string:
./trueface_sdk/libtf.a(ocl.cpp.o): In function `cv::ocl::Kernel::set(int, cv::ocl::KernelArg const&)':
ocl.cpp:(.text._ZN2cv3ocl6Kernel3setEiRKNS0_9KernelArgE+0x375): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
ocl.cpp:(.text._ZN2cv3ocl6Kernel3setEiRKNS0_9KernelArgE+0x49d): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
../trueface_sdk/libtf.a(ocl.cpp.o): In function `oclCleanupCallback.cold':
ocl.cpp:(.text.unlikely.oclCleanupCallback+0x36): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
ocl.cpp:(.text.unlikely.oclCleanupCallback+0xcf): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
ocl.cpp:(.text.unlikely.oclCleanupCallback+0x184): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
../trueface_sdk/libtf.a(ocl.cpp.o):ocl.cpp:(.text._ZN2cv3ocl6Device4ImplC2EPv[_ZN2cv3ocl6Device4ImplC5EPv]+0xb7b): more undefined references to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()' follow
../trueface_sdk/libtf.a(sqlite3.c.o):(.data.rel+0xb0): undefined reference to `fcntl64'
I also get undefined reference to fcntl64.
So what is the solution? How can I compile a library that will be compatible with multiple version of gcc?
Based on the comments, it looks like it is not compatible because of the use of the -Ofast compiler optimization flag.

Connecting c++ to mysql using mysql-c++-connector 8

I want to connect to mysql 8 using mysql-c++-connector8 (xdevapi) and I use .so file for linking but I get errors
here is my main.cpp file
#include <iostream>
#include <mysqlx/xdevapi.h>
using namespace ::mysqlx;
using std::cout;
using std::cin;
using std::endl;
int main(){
Session sess("localhost",3306,"root","mypass");
Schema db = sess.getSchema("university");
Collection myColl = db.getCollection("student");
DocResult myDocs = myColl.find("name like :param").execute();
cout<<myDocs.fetchOne();
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(1)
set(CMAKE_CXX_STANDARD 17)
include_directories(~/mysql-connector-c++/include)
link_directories(~/mysql-connector-c++/lib64)
set(PROJECT_LINK_LIBS libmysqlcppconn8.so)
add_executable(myExe main.cpp)
target_link_libraries(myExe ${PROJECT_LINK_LIBS})
Errors:
[ 50%] Linking CXX executable myExe
/usr/bin/ld: CMakeFiles/myExe.dir/main.cpp.o: in function `mysqlx::string::string(char const*)':
/home/amir/mysql-connector-c++/include/mysqlx/devapi/common.h:100: undefined reference to `mysqlx::string::Impl::from_utf8(mysqlx::string&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: CMakeFiles/myExe.dir/main.cpp.o: in function `mysqlx::string::string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/amir/mysql-connector-c++/include/mysqlx/devapi/common.h:105: undefined reference to `mysqlx::string::Impl::from_utf8(mysqlx::string&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: CMakeFiles/myExe.dir/main.cpp.o: in function `mysqlx::string::operator std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >() const':
/home/amir/mysql-connector-c++/include/mysqlx/devapi/common.h:115: undefined reference to `mysqlx::string::Impl::to_utf8[abi:cxx11](mysqlx::string const&)'
/usr/bin/ld: CMakeFiles/myExe.dir/main.cpp.o: in function `void mysqlx::internal::Settings_detail<mysqlx::internal::Settings_traits>::set<true, mysqlx::SessionOption, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, mysqlx::SessionOption, unsigned int&, mysqlx::SessionOption, mysqlx::string const&>(mysqlx::SessionOption, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, mysqlx::SessionOption&&, unsigned int&, mysqlx::SessionOption&&, mysqlx::string const&)':
/home/amir/mysql-connector-c++/include/mysqlx/devapi/detail/settings.h:67: undefined reference to `mysqlx::internal::Settings_detail<mysqlx::internal::Settings_traits>::do_set(std::__cxx11::list<std::pair<int, mysqlx::common::Value>, std::allocator<std::pair<int, mysqlx::common::Value> > >&&)'
/usr/bin/ld: CMakeFiles/myExe.dir/main.cpp.o: in function `void mysqlx::internal::Settings_detail<mysqlx::internal::Settings_traits>::set<true, mysqlx::SessionOption, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(mysqlx::SessionOption, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)':
/home/amir/mysql-connector-c++/include/mysqlx/devapi/detail/settings.h:67: undefined reference to `mysqlx::internal::Settings_detail<mysqlx::internal::Settings_traits>::do_set(std::__cxx11::list<std::pair<int, mysqlx::common::Value>, std::allocator<std::pair<int, mysqlx::common::Value> > >&&)'
/usr/bin/ld: CMakeFiles/myExe.dir/main.cpp.o: in function `void mysqlx::internal::Settings_detail<mysqlx::internal::Settings_traits>::set<true, mysqlx::SessionOption, mysqlx::string const&>(mysqlx::SessionOption, mysqlx::string const&)':
/home/amir/mysql-connector-c++/include/mysqlx/devapi/detail/settings.h:67: undefined reference to `mysqlx::internal::Settings_detail<mysqlx::internal::Settings_traits>::do_set(std::__cxx11::list<std::pair<int, mysqlx::common::Value>, std::allocator<std::pair<int, mysqlx::common::Value> > >&&)'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/myExe.dir/build.make:95: myExe] Error 1
make[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/myExe.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/myExe.dir/rule] Error 2
make: *** [Makefile:118: myExe] Error 2
I don't want to use legacy connectors as it is not recommended .
TL;DR; You need to use the old GCC ABI by setting the _GLIBCXX_USE_CXX11_ABI to 0. This can be done with cmake by adding the following to your CMakeLists.txt:
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
The issue comes from the "Linux - Generic" of the MySQL connector which have likely been built without the new CXX11 ABI of GCC (introduced in gcc 5.1).
Since your compiler is recent, the default is to use the new ABI, so when you include <mysqlx/xdevapi.h>, you create declarations such as:
mysqlx::string::Impl::from_utf8(
mysqlx::string&,
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
...that use the new ABI (see the __cxx11 namespace).
But since the connectors have been built with the old ABI, the libmysqlcppconn8.so contains symbols for functions matching this kind of declaration:
mysqlx::string::Impl::from_utf8(
mysqlx::string&,
std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
You can check this by running readelf -Ws libmysqlcppconn8.so, for the "Linux - Generic" version I get (with a grep from_utf8)1:
1428: 00000000000a0a86 193 FUNC GLOBAL DEFAULT 12 _ZN6mysqlx6string4Impl9from_utf8ERS0_RKSs
9437: 00000000000a0a86 193 FUNC GLOBAL DEFAULT 12 _ZN6mysqlx6string4Impl9from_utf8ERS0_RKSs
But for the Ubuntu 18.10 version I get:
725: 00000000000a23e0 183 FUNC GLOBAL DEFAULT 12 _ZN6mysqlx6string4Impl9from_utf8ERS0_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
10141: 00000000000a23e0 183 FUNC GLOBAL DEFAULT 12 _ZN6mysqlx6string4Impl9from_utf8ERS0_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
The easiest fix is to tell your compiler to use the old ABI, so that the symbol will match. This can be done by setting the _GLIBCXX_USE_CXX11_ABI macro to 0 when compiling:
g++ -D_GLIBCXX_USE_CXX11_ABI=0 main.cpp
...or by adding the following to CMakeLists.txt:
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
If you use multiple external libraries, you have to be careful that those also use the old ABI, otherwise you will likely face the opposite issue, i.e., a library built with the new ABI cannot be used directly to build a program with the old ABI.
1 The "Linux - Generic" version contains reference to the CXX11 ABI, so I do not really know what is going on here. It looks like some parts of the library has been compile with the new ABI.
You may need to download the specific version for current OS instead generic-linux version.
for example rhel8 x86_64 platform, the mysql-connector-c++-8.0.23-1.el8.x86_64.rpm and mysql-connector-c++-devel-8.0.23-1.el8.x86_64.rpm should be downloaded. (https://dev.mysql.com/downloads/connector/cpp/)
Then unarchive that into same folder. (note if you have windows system, please unarchive it in linux since there's some soft link in it)
Then just using it without old CXX11ABI (need NOT to define _GLIBCXX_USE_CXX11_ABI=0)

How can I include Boost in my Qt Project File?

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
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
}

Compilation issue with boost library

I am trying to compile some source codes. However it is throwing some error related to boost library. Here is the error
undefined reference to `boost::re_detail::get_mem_block()'
main.cpp:(.text+0x40a6): undefined reference to `boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)'
main.cpp:(.text+0x40db): undefined reference to `boost::re_detail::put_mem_block(void*)'
main.cpp:(.text+0x430a): undefined reference to `boost::re_detail::put_mem_block(void*)'
main.o: In function `_ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_.constprop.1207':
main.cpp:(.text+0x436e): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
main.cpp:(.text+0x439f): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
main.cpp:(.text+0x43d0): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<
I have the boost regex library installed in my system and I have given the path to the library using -L option and specified the library using -lboost_regex option as well. What could be the issue?
It does find the library. But still throwing an error
I met the same problem, and it has been solved. So maybe you had installed an older version of boost before, and the linker linkes the older version.
Try to remove all installed boost library, and reinstall the boost library, your problem will be solved.

undefined reference to `__stack_chk_fail'

Getting this error while compiling C++ code:
undefined reference to `__stack_chk_fail'
Options already tried:
added -fno-stack-protector while compiling - did not work, error persists
added a dummy implementation of void __stack_chk_fail(void) in my code. Still getting the same error.
Detailed Error:
/u/ac/alanger/gurobi/gurobi400/linux64/lib/libgurobi_c++.a(Env.o)(.text+0x1034): In function `GRBEnv::getPar/u/ac/alanger/gurobi/gurobi400/linux64/lib/libgurobi_c++.a(Env.o)(.text+0x1034): In function `GRBEnv::getParamInfo(GRB_StringParam, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
: undefined reference to `__stack_chk_fail'
amInfo(GRB_StringParam, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
: **undefined reference to `__stack_chk_fail'**
Earlier, I was getting 10's of such errors. Found out that there was a version mismatch between the gcc of the pre-compiled libraries I am using and the gcc version I was using to compile the code. Updated gcc and now I am getting only 2 of these errors.
Any help, please?
libgurobi_c++.a was compiled with -fno-stack-protector (obviously).
A few things come to mind:
add -fstack-protector when linking. This will make sure that libssp gets linked.
Manually link -lssp
Make your dummy version of __stack_chk_fail(void) in it's own object file and and add this .o file to your linker command AFTER libgurobi_c++.a. GCC/G++ resolves symbols from left to right during linking so despite your code having the function defined, a copy of an object containing the __stack_chk_fail symbol needs to be on the linker line to the right of libgurobi_c++.a.
In gentoo I had the same problem and i resolved creating 2 files. The first contain the option to be parsed by emerge and passed to gcc:
/etc/portage/env/nostackprotector.conf
CFLAGS="-fno-stack-protector -O2"
And the second tells which package should use this settings:
/etc/portage/package.env/nostackprotector
x11-libs/vte nostackprotector.conf
sys-libs/glibc nostackprotector.conf
www-client/chromium nostackprotector.conf
app-admin/sudo nostackprotector.conf
Just had the same issue: c++ code with an implementation of void __stack_chk_fail(void) showing several undefined reference to __stack_chk_fail errors when compiling.
My solution was to define __stack_chk_fail(void) as extern "C":
extern "C" {
__stack_chk_fail(void)
{
...
}
}
This suppressed the compilation error :)
Hope it helps!
https://wiki.ubuntu.com/ToolChain/CompilerFlags
says:
"Usually this is a result of calling ld instead of gcc during a build to perform linking"
This is what I encountered when modified the Makefile of libjpeg manually. Use gcc instead of ld solved the problem.