nuwen MinGW + Boost- error linking boost_regex - c++
I downloaded the nuwen distribution of MinGW, which comes with Boost (GCC 4.6.1 and Boost 1.47.0.). I want to use the Boost regex package in a c++ program. libboost_regex.a is contained in C:\dev\MinGW\lib, which is in my path as well as the library search path for MinGW. When I compile, it gives me lots and lots of errors. I tried giving it the exact path to the library in the g++ command line, but to no avail. My best attempt at compiling: g++ -o test -LC:\dev\MinGW -lboost_regex testBoost.cpp. The program I'm trying to run:
#include <iostream>
#include <boost/regex.hpp>
int main (int argc, char* argv[])
{
static const boost::regex exp ("hello regex!");
}
My humongous pile of errors:
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail27cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE[boost::re_detail::cpp_regex_traits_char_layer<char>::cpp_regex_traits_char_layer(boost::re_detail::cpp_regex_traits_base<char> const&)]+0x20): undefined reference to `boost::re_detail::cpp_regex_traits_char_layer<char>::init()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail11raw_storage6extendEj[boost::re_detail::raw_storage::extend(unsigned int)]+0x41): undefined reference to `boost::re_detail::raw_storage::resize(unsigned int)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail18basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiSsi[boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fail(boost::regex_constants::error_type, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)]+0x214): undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail18basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiSsi[boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fail(boost::regex_constants::error_type, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)]+0x21f): undefined reference to `boost::regex_error::raise() const'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail18basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiSsi[boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fail(boost::regex_constants::error_type, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)]+0x22a): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail18basic_regex_parserIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiSsi[boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fail(boost::regex_constants::error_type, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)]+0x285): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fixup_recursions(boost::re_detail::re_syntax_base*)]+0x109): undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fixup_recursions(boost::re_detail::re_syntax_base*)]+0x114): undefined reference to `boost::regex_error::raise() const'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fixup_recursions(boost::re_detail::re_syntax_base*)]+0x11f): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fixup_recursions(boost::re_detail::re_syntax_base*)]+0x2e0): undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fixup_recursions(boost::re_detail::re_syntax_base*)]+0x2eb): undefined reference to `boost::regex_error::raise() const'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fixup_recursions(boost::re_detail::re_syntax_base*)]+0x2f6): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fixup_recursions(boost::re_detail::re_syntax_base*)]+0x345): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fixup_recursions(boost::re_detail::re_syntax_base*)]+0x382): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::create_startmaps(boost::re_detail::re_syntax_base*)]+0x179): undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::create_startmaps(boost::re_detail::re_syntax_base*)]+0x184): undefined reference to `boost::regex_error::raise() const'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::create_startmaps(boost::re_detail::re_syntax_base*)]+0x18f): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::create_startmaps(boost::re_detail::re_syntax_base*)]+0x2d6): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::create_startmap(boost::re_detail::re_syntax_base*, unsigned char*, unsigned int*, unsigned char)]+0x23d): undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::create_startmap(boost::re_detail::re_syntax_base*, unsigned char*, unsigned int*, unsigned char)]+0x248): undefined reference to `boost::regex_error::raise() const'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::create_startmap(boost::re_detail::re_syntax_base*, unsigned char*, unsigned int*, unsigned char)]+0x253): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::create_startmap(boost::re_detail::re_syntax_base*, unsigned char*, unsigned int*, unsigned char)]+0x947): undefined reference to `boost::regex_error::~regex_error()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZNK5boost9re_detail31cpp_regex_traits_implementationIcE12error_stringENS_15regex_constants10error_typeE[boost::re_detail::cpp_regex_traits_implementation<char>::error_string(boost::regex_constants::error_type) const]+0x89): undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZNK5boost9re_detail31cpp_regex_traits_implementationIcE12error_stringENS_15regex_constants10error_typeE[boost::re_detail::cpp_regex_traits_implementation<char>::error_string(boost::regex_constants::error_type) const]+0xe7): undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail19basic_regex_creatorIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE12insert_stateEiNS0_19syntax_element_typeEj[boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::insert_state(int, boost::re_detail::syntax_element_type, unsigned int)]+0x94): undefined reference to `boost::re_detail::raw_storage::insert(unsigned int, unsigned int)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost12object_cacheINS_9re_detail21cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_j[boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned int)]+0x1e): undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost12object_cacheINS_9re_detail21cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_j[boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned int)]+0x59): undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost12object_cacheINS_9re_detail21cpp_regex_traits_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_j[boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned int)]+0xdf): undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZNK5boost9re_detail31cpp_regex_traits_implementationIcE18lookup_collatenameEPKcS4_[boost::re_detail::cpp_regex_traits_implementation<char>::lookup_collatename(char const*, char const*) const]+0x10f): undefined reference to `boost::re_detail::lookup_default_collate_name(std::string const&)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail31cpp_regex_traits_implementationIcE4initEv[boost::re_detail::cpp_regex_traits_implementation<char>::init()]+0xe3): undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost9re_detail31cpp_regex_traits_implementationIcE4initEv[boost::re_detail::cpp_regex_traits_implementation<char>::init()]+0x11a): undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost16cpp_regex_traitsIcE16get_catalog_nameEv[boost::cpp_regex_traits<char>::get_catalog_name()]+0x1f): undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost16cpp_regex_traitsIcE16get_catalog_nameEv[boost::cpp_regex_traits<char>::get_catalog_name()]+0x3e): undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
C:\Users\nate\AppData\Local\Temp\ccTuJyrB.o:testBoost.cpp:(.text$_ZN5boost16cpp_regex_traitsIcE16get_catalog_nameEv[boost::cpp_regex_traits<char>::get_catalog_name()]+0x56): undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
collect2: ld returned 1 exit status
Edit: As suggested by Michael Burr, I ran g++ -Wl --verbose. Here is the output from it:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/dev/mingw/bin/../libexec/gcc/i686-pc-mingw32/4.6.1/lto-wrapper.exe
Target: i686-pc-mingw32
Configured with: ../src/configure --prefix=/c/temp/gcc/dest --enable-languages=c,c++ --with-arch=i686 --with-tune=generic --disable-libstdcxx-pch --disable-nls --disable-shared --disable-sjlj-exceptions --disable-win32-registry --enable-checking=release --disable-lto
Thread model: win32
gcc version 4.6.1 (GCC)
COLLECT_GCC_OPTIONS='-o' 'test.exe' '-Wl' '-v' '-LC:\dev\MinGW\' '-mtune=generic' '-march=i686'
c:/dev/mingw/bin/../libexec/gcc/i686-pc-mingw32/4.6.1/cc1plus.exe -quiet -v -iprefix c:\dev\mingw\bin\../lib/gcc/i686-pc-mingw32/4.6.1/ testBoost.cpp -quiet -dumpbase testBoost.cpp -mtune=generic -march=i686 -auxbase testBoost -Wl -version -o C:\Users\nate\AppData\Local\Temp\ccX1SmTk.s
cc1plus.exe: error: unrecognized command line option '-Wl'
GNU C++ (GCC) version 4.6.1 (i686-pc-mingw32)
compiled by GNU C version 4.6.1, GMP version 5.0.2, MPFR version 3.0.1-p4, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "c:\dev\mingw\bin\../lib/gcc/i686-pc-mingw32/4.6.1/../../../../i686-pc-mingw32/include"
ignoring duplicate directory "c:/dev/mingw/lib/gcc/../../lib/gcc/i686-pc-mingw32/4.6.1/../../../../include/c++/4.6.1"
ignoring duplicate directory "c:/dev/mingw/lib/gcc/../../lib/gcc/i686-pc-mingw32/4.6.1/../../../../include/c++/4.6.1/i686-pc-mingw32"
ignoring duplicate directory "c:/dev/mingw/lib/gcc/../../lib/gcc/i686-pc-mingw32/4.6.1/../../../../include/c++/4.6.1/backward"
ignoring duplicate directory "c:/dev/mingw/lib/gcc/../../lib/gcc/i686-pc-mingw32/4.6.1/include"
ignoring nonexistent directory "c:/temp/gcc/dest/include"
ignoring nonexistent directory "/c/temp/gcc/dest/include"
ignoring duplicate directory "c:/dev/mingw/lib/gcc/../../lib/gcc/i686-pc-mingw32/4.6.1/include-fixed"
ignoring nonexistent directory "c:/dev/mingw/lib/gcc/../../lib/gcc/i686-pc-mingw32/4.6.1/../../../../i686-pc-mingw32/include"
ignoring nonexistent directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
c:\dev\mingw\bin\../lib/gcc/i686-pc-mingw32/4.6.1/../../../../include/c++/4.6.1
c:\dev\mingw\bin\../lib/gcc/i686-pc-mingw32/4.6.1/../../../../include/c++/4.6.1/i686-pc-mingw32
c:\dev\mingw\bin\../lib/gcc/i686-pc-mingw32/4.6.1/../../../../include/c++/4.6.1/backward
c:\dev\mingw\bin\../lib/gcc/i686-pc-mingw32/4.6.1/include
c:\dev\mingw\bin\../lib/gcc/i686-pc-mingw32/4.6.1/../../../../include
c:\dev\mingw\bin\../lib/gcc/i686-pc-mingw32/4.6.1/include-fixed
End of search list.
GNU C++ (GCC) version 4.6.1 (i686-pc-mingw32)
compiled by GNU C version 4.6.1, GMP version 5.0.2, MPFR version 3.0.1-p4, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
This works fine for me using -lboost_regex passed on the command line (mingw-7.2.exe distribution from nuwen.net - freshly unpacked with nothing else done to the distribution - which contains the compiler and boost versions you mentioned).
Try passing the option -Wl,--verbose to have the gnu ld linker be verbose about where it's looking for the libraries - that might give you a clue. Maybe some hidden option/environment setting is causing the wrong libboost_regex.a to be picked up?
Another thing to try is to pass the full path and filename for the library as an input file to g++ (with no options) - GCC will figure out that it's a library file (and a lib directory search will not be done for it). So assuming that you have MinGW installed in C:\dev\Mingw, the command line should look like:
g++ -o test -LC:\dev\MinGW testBoost.cpp c:\dev\MinGW\lib\libboost_regex.a
If that works, then you have a problem with the wrong library being found, and you need to fix your build script/build configuration or you'll continue to have problems down the road. If that still doesn't work, then the library might have been corrupted - try downloading and/or extracting the nuwen.net distribution again. Or try building the Boost libraries from scratch (which may take a while).
Related
Trying to statically link MYSQL library in C++ without any luck
I'm stuck on this issue and I don't think it should be this difficult. I'm essentially getting a compilation error with several 'undefined reference' warnings which are, I believe, caused by the library not being properly linked to the project. The library resources along with the required header files are all located in the include folder of my project as well as in the include path. (For reference, I'm working inside of VScode). Here's part of my makefile MYSQL_CONCPP_DIR = /home/me/Git/CppProject/include/cpp-connector-mysql UTILS_DIR = /home/me/Git/CppProject/include/utils/ CPPFLAGS = -DSTATIC_CONCPP -I $(UTILS_DIR) LDLIBS = $(MYSQL_CONCPP_DIR)/lib64/libmysqlcppconn8-static.a -I $(UTILS_DIR) -lssl -lcrypto -lpthread CXXFLAGS := -std=c++17 -Wall -Wextra -g I started moving towards C++ development maybe a week ago and have been programming for maybe half a year. So, if there is something obvious that I am missing I would not mind being embarrassed on Stack Overflow, as long as I learn something. I've scoured the internet to find a solution and nothing has worked. I successfully did the exact same thing I'm trying to do (connect to localhost via a User class and a Connector class) in both Java and Python in a few hours, but am stuck on C++ with this issue. Here's the actual error message I get, which is incredibly difficult to decipher: /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o: in function `check_lib()': /home/adis/Git/CppProject/include/cpp-connector-mysql/jdbc/cppconn/driver.h:77: undefined reference to `check(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/adis/Git/CppProject/include/cpp-connector-mysql/jdbc/cppconn/driver.h:78: undefined reference to `check(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&)' /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o: in function `get_driver_instance_by_name': /home/adis/Git/CppProject/include/cpp-connector-mysql/jdbc/cppconn/driver.h:90: undefined reference to `_get_driver_instance_by_name' /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o: in function `mysqlx::abi2::r0::string::traits<char>::to_str[abi:cxx11](mysqlx::abi2::r0::string const&)': /home/adis/Git/CppProject/include/cpp-connector-mysql/mysqlx/devapi/common.h:225: undefined reference to `mysqlx::abi2::r0::string::Impl::to_utf8[abi:cxx11](mysqlx::abi2::r0::string const&)' /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o: in function `mysqlx::abi2::r0::DbDoc::DbDoc()': /home/adis/Git/CppProject/include/cpp-connector-mysql/mysqlx/devapi/document.h:107: undefined reference to `vtable for mysqlx::abi2::r0::DbDoc' /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o: in function `mysqlx::abi2::r0::DbDoc::~DbDoc()': /home/adis/Git/CppProject/include/cpp-connector-mysql/mysqlx/devapi/document.h:81: undefined reference to `vtable for mysqlx::abi2::r0::DbDoc' /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o: in function `mysqlx::abi2::r0::Value::print(std::ostream&) const': /home/adis/Git/CppProject/include/cpp-connector-mysql/mysqlx/devapi/document.h:508: undefined reference to `mysqlx::abi2::r0::common::Value::print(std::ostream&) const' /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o:(.data.rel.ro._ZTCN6mysqlx4abi22r05ValueE0_NS1_6common5ValueE[_ZTVN6mysqlx4abi22r05ValueE]+0x18): undefined reference to `typeinfo for mysqlx::abi2::r0::common::Value' /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o:(.data.rel.ro._ZTCN6mysqlx4abi22r05ValueE0_NS1_6common5ValueE[_ZTVN6mysqlx4abi22r05ValueE]+0x20): undefined reference to `mysqlx::abi2::r0::common::Value::print(std::ostream&) const' /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/Connector.o:(.data.rel.ro._ZTIN6mysqlx4abi22r05ValueE[_ZTIN6mysqlx4abi22r05ValueE]+0x28): undefined reference to `typeinfo for mysqlx::abi2::r0::common::Value' /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: warning: creating DT_TEXTREL in a PIE collect2: error: ld returned 1 exit status make: *** [Makefile:76: main] Error 1
CppDB compilation errors
I followed the following steps in order to build CppDB: svn co http://cppcms.svn.sourceforge.net/svnroot/cppcms/cppdb/trunk cppdb-trunk cd cppdb-trunk cmake ~/Desktop/cppdb-trunk make make install Afterwards, I'm trying to compile and run the file example1.cpp from the examples directory. When I run gcc example1.cpp I get the following errors: /tmp/ccGWenrv.o: In function main': example1.cpp:(.text+0x2a): undefined reference tostd::allocator::allocator()' example1.cpp:(.text+0x42): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)' example1.cpp:(.text+0x58): undefined reference tocppdb::session::session(std::__cxx11::basic_string, std::allocator > const&)' example1.cpp:(.text+0x64): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' example1.cpp:(.text+0x73): undefined reference tostd::allocator::~allocator()' example1.cpp:(.text+0x91): undefined reference to cppdb::session::operator<<(char const*)' example1.cpp:(.text+0xa5): undefined reference tocppdb::statement::operator<<(void ()(cppdb::statement&))' example1.cpp:(.text+0xb4): undefined reference to cppdb::statement::~statement()' example1.cpp:(.text+0xd2): undefined reference tocppdb::session::operator<<(char const)' example1.cpp:(.text+0xe6): undefined reference to cppdb::statement::operator<<(void (*)(cppdb::statement&))' example1.cpp:(.text+0xf5): undefined reference tocppdb::statement::~statement()' example1.cpp:(.text+0x170): undefined reference to cppdb::statement::statement()' example1.cpp:(.text+0x18e): undefined reference tocppdb::session::operator<<(char const*)' example1.cpp:(.text+0x1db): undefined reference to cppdb::statement::operator<<(tm const&)' example1.cpp:(.text+0x1e8): undefined reference tocppdb::statement::operator<<(char const*)' example1.cpp:(.text+0x1fd): undefined reference to `cppdb::statement::operator=(cppdb::statement const&)' etc. Any suggestions?
Try g++ example1.cpp -lcppdb. You need to link against the C++ run-time library (using g++ instead of gcc takes care of that) and against CppDB itself (the -lcppdb part). If GCC cannot find the -lcppdb library, you'll have to provide the path using -L, and you may have to use LD_LIBRARY_PATH at run time as well.
Wangle: /usr/local/lib/libfolly.so: undefined reference to boost::re_detail_106000
While installing Wangle, I encountered the following problem. I have already installed Boost, and I don't know why. [ 65%] Built target wangle Linking CXX executable bin/AcceptorTest /usr/bin/ld: warning: libboost_filesystem.so.1.54.0, needed by /usr/local/lib/libfolly.so, may conflict with libboost_filesystem.so.1.61.0 /usr/bin/ld: warning: libboost_system.so.1.54.0, needed by /usr/local/lib/libfolly.so, may conflict with libboost_system.so.1.61.0 /usr/local/lib/libfolly.so: undefined reference to `boost::re_detail_106000::perl_matcher<char const*, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)' /usr/local/lib/libfolly.so: undefined reference to `boost::re_detail_106000::get_mem_block()' /usr/local/lib/libfolly.so: undefined reference to `boost::re_detail_106000::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const' /usr/local/lib/libfolly.so: undefined reference to `boost::re_detail_106000::verify_options(unsigned int, boost::regex_constants::_match_flags)' /usr/local/lib/libfolly.so: undefined reference to `boost::re_detail_106000::get_default_error_string(boost::regex_constants::error_type)' /usr/local/lib/libfolly.so: undefined reference to `boost::re_detail_106000::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)' /usr/local/lib/libfolly.so: undefined reference to `boost::re_detail_106000::put_mem_block(void*)' /usr/local/lib/libfolly.so: undefined reference to `boost::re_detail_106000::raise_runtime_error(std::runtime_error const&)' /usr/local/lib/libfolly.so: undefined reference to `boost::re_detail_106000::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const' collect2: error: ld returned 1 exit status make[2]: *** [bin/AcceptorTest] Error 1 make[1]: *** [CMakeFiles/AcceptorTest.dir/all] Error 2 make: *** [all] Error 2
Using clang instead of gcc, removing the atomic check in the CMakeList.txt and disabling tests made wangle build for me on Arch. It currently won't build with GCC 7 (Issue) and GCC 5 threw a similar issue to yours for me. CC=clang CXX=clang cmake . -DBUILD_TEST=0 (code above does not include the atomic check you need to remove in the CMakeList.txt yourself! Just search for atomic.)
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.
C++ linker errors, Undefined references to Items that should be referenced from a Share Object
I am building a library, called physgameengine, to aid in building games. This game library links against several libraries, including: Ogre3d, Bullet Physics and SDL, which are in the library files libOgreMain-1.6.5.so, libBulletCollision.a, libBulletDynamics.a, libBulletSoftBody.a, libSDL-1.2.so.0. This Library/Shared object appears to build just fine in Ubuntu 9.10, using GCC and Code::blocks. It does build fine on windows with mingw and Code::blocks. In windows I can make games that compile/link using the library I built just fine, those programs run and do exactly what I expect it to. In Ubuntu when I try to compile/link a game that uses this Library I am making I get lots of undefined reference errors. But none to the functions or objects in the library I built, but rather to the items that my library calls. Here is an example of the errors I get. > ||warning: libOgreMain-1.6.5.so, needed by ../physgameengine/bin/ubuntudebug/libphysgame.so, not found (try using -rpath or -rpath-link)| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::Root(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::StringUtil::BLANK'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::updateAabbs()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::createRenderWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int, bool, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const*)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Timer::getMilliseconds()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::createSceneManager(unsigned short, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::~Root()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::~btCollisionWorld()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::renderOneFrame()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionObject::btCollisionObject()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Timer::getMillisecondsCPU()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btSimulationIslandManager::buildAndProcessIslands(btDispatcher*, btCollisionWorld*, btSimulationIslandManager::IslandCallback*)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Viewport::getActualWidth() const'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::initialise(bool, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Camera::lookAt(Ogre::Vector3 const&)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::removeCollisionObject(btCollisionObject*)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Viewport::getActualHeight() const'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Timer::reset()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::restoreConfig()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Timer::~Timer()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::NedAllocImpl::deallocBytes(void*)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::convexSweepTest(btConvexShape const*, btTransform const&, btTransform const&, btCollisionWorld::ConvexResultCallback&, float) const'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::NedAllocImpl::allocBytes(unsigned int, char const*, int, char const*)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `typeinfo for btCollisionWorld'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionObject::~btCollisionObject()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btSimulationIslandManager::btSimulationIslandManager()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Root::showConfigDialog()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionObject::setActivationState(int)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::LogManager::getSingleton()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::performDiscreteCollisionDetection()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::LogManager::logMessage(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Ogre::LogMessageLevel, bool)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Timer::Timer()'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::btCollisionWorld(btDispatcher*, btBroadphaseInterface*, btCollisionConfiguration*)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `typeinfo for btCollisionObject'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `Ogre::Camera::setPosition(Ogre::Vector3 const&)'| ../physgameengine/bin/ubuntudebug/libphysgame.so||undefined reference to `btCollisionWorld::addCollisionObject(btCollisionObject*, short, short)'| ||=== Build finished: 36 errors, 1 warnings ===| The bulk of the code is identical between windows and Linux they seem to have equivalent compile/linker settings. But the Linux game appears to be linking against the original libraries that my library should be linking against. What is going on? Any Ideas on how to fix it?
Unlike in Windows, in Linux systems it's not enough to place a shared library file into the same folder as executable. You should either provide an LD_LIBRARY_PATH variable or follow the linker's advice and use -rpath (check this question)
The very first line of your error tells you the problem: libOgreMain-1.6.5.so, needed by libphysgame.so, not found (try using -rpath or -rpath-link)| You need to specify the directory where libOgreMain is installed. Since you need to use a linker option, you need to use the -Wl feature of gcc. Assuming the files is in /opt/lib, you would add: gcc -Wl,-rpath-link,/opt/lib ...rest of linker line...
Just based on the first line: > ||warning: libOgreMain-1.6.5.so, needed by ../physgameengine/bin/ubuntudebug/libphysgame.so, not found (try using -rpath or -rpath-link)| It looks like your linker is having trouble finding your shared object. Check to make sure your linker's include paths are properly set up.
This is a good link on the subject http://sysprogs.com/w/fixing-rpath-link-issues-with-cross-compilers/ Essentially if you do not have -lmylib for all your libraries you link to, you cannot count on -Lpath to find them. Thus, if /opt/infoa/lib/liba.so depends on /opt/infod/lib/libd.so and you only specify -la, then you need something like this: gcc -Wl,-rpath-link,/opt/infod/lib -L/opt/infoa/lib -la *.c -o myexec