I've a large project which was originally built on Macos, that I'm trying to get compiling on Windows. The makefile for the project is as follows:
CC=C:/cygwin64/bin/g++.exe
BASE_FLAGS = -std=c++14
LDFLAGS = -I/usr/local/Cellar/boost/1.69.0/include -I/opt/local/include -I include/
LLIBFLAGS = -L/usr/local/Cellar/boost/1.68.0/lib
LINKFLAGS = -lboost_thread -lboost_system -l boost_filesystem -l boost_regex -ll -lm
FLAGS = $(BASE_FLAGS) $(LLIBFLAGS) $(LDFLAGS) $(LINKFLAGS)
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
SRCS := $(call rwildcard,src/,*.cpp) $(call rwildcard,src/,*.c)
mac:
cd src; bison -d parse.y --debug -t; flex lex.l
time ./runscripts.sh
$(CC) $(FLAGS) -o main.out $(SRCS)
BASE_FLAGS_WIN = -std=gnu++11
LDFLAGS_WIN = -I include/ -I C:\Users\elllz\Downloads\boost_1_69_0
LLIBFLAGS_WIN = -LC:\Users\elllz\Downloads\boost_1_69_0\stage\lib
LINKFLAGS_WIN = -lm -lboost_system -lboost_regex -lboost_filesystem -lboost_thread
FLAGS_WIN = $(BASE_FLAGS_WIN) $(LDFLAGS_WIN) $(LLIBFLAGS_WIN) $(LINKFLAGS_WIN)
win:
bison -d .\src\parse.y -t -g
flex .\src\lex.l
.\scripts\ALL_HEADER_TOKENS.bat
cp .\parse.tab.h .\src\parse.tab.h
cp .\parse.tab.c .\src\parse.tab.c
cp .\lex.yy.c .\src\lex.yy.c
rm .\parse.tab.h .\parse.tab.c .\lex.yy.c
$(CC) $(FLAGS_WIN) $(SRCS)
Note that the first second is the (working) macos target, and the later is the Windows target. When trying to link boost on Windows, I keep getting a plethora of undefined reference errors, like such:
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE]+0x15): undefined reference to `boost::filesystem::path::codecvt()'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE]+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path::codecvt()'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE]+0x32): undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, _mbstate_t> const&)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE]+0x32): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, _mbstate_t> const&)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem6existsERKNS0_4pathE[_ZN5boost10filesystem6existsERKNS0_4pathE]+0x1e): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem6existsERKNS0_4pathE[_ZN5boost10filesystem6existsERKNS0_4pathE]+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE[_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE]+0x1e): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE[_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE]+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/ccbzCEFH.o:Token.cpp:(.text$_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE[_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE]+0x7e): undefined reference to `boost::re_detail_106900::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::c_regex_traits<char> > >::match()'
/cygdrive/c/Users/elllz/AppData/Local/Temp/ccbzCEFH.o:Token.cpp:(.text$_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE[_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE]+0x7e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::re_detail_106900::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::c_regex_traits<char>
> >::match()'
/cygdrive/c/Users/elllz/AppData/Local/Temp/ccbzCEFH.o:Token.cpp:(.text$_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEE6assignEPKcS7_j[_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEE6assignEPKcS7_j]+0x31): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::c_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/ccbzCEFH.o:Token.cpp:(.text$_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEE6assignEPKcS7_j[_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEE6assignEPKcS7_j]+0x31): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::basic_regex<char, boost::regex_traits<char, boost::c_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
That's only a snippet, all the information I can find says it's a boost linking problem, but I can't pin it down for the life of me. I'm compiling boost 1.69.0 with the commands:
.\boostrap.bat
./bjam
./bjam install
In a similar manner to the instructions found here. I've tried jsut about everything I can think of, as well as spent a lot of time recompiling boost, so any help you might be able to offer would be greatly appreciated!
Things I have tried:
Checking the libaries do exist in /stage/lib, they do, as .a and .dll.a files.
Moving the entire boost folder into a relative path of my build folder, in case I was specifying the link / include folders wrong.
Recompiling boost with a host of options, I can't come close to recalling them all.
I suspect that you may have multiple issues...
Your makefile specifies different versions of the boost libraries: 1.69.0 and 1.68.0
LDFLAGS = -I/usr/local/Cellar/boost/1.69.0/include -I/opt/local/include -I include/
LLIBFLAGS = -L/usr/local/Cellar/boost/1.68.0/lib
It could be as simple as that.
However, on a Windows machine, the command:
.\boostrap.bat
normally assumes building the boost libraries using Visual Studio.
So depending upon where you built the boost libraries from, you may have built Visual Studio lib files, not g++ lib files. You can tell from the library file names:
// gcc, actually mingw73: mgw73
libboost_filesystem-mgw73-mt-x64-1_69.dll.a
// msvc 2017: vc141
boost_filesystem-vc141-mt-x64-1_69.lib
It sounds like yours are correct, but you can specify the g++ compiler explicitly when building boost, e.g.:
.\boostrap.bat gcc
Finally, it's difficult to maintain cross platform makefiles, especially with boost.
I recommend using cmake instead.
Related
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
I'm trying to link Boost.Log statically into my program. Boost.Log has successfully compiled with other modules using bjam. However, when I try to link with my program I'm getting an error:
g++ -g -O2 -pthread -o sonar sonar-main.o sonar-config.o sonar-util.o sonar-logger.o /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_system.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_timer.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_iostreams.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_thread.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_log_setup.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_log.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_filesystem.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_atomic.a -lcrypto -lssl
sonar-logger.o: In function `void boost::log::v2s_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> >::aligned_write<wchar_t>(wchar_t const*, long)':
/usr/include/boost/log/utility/formatting_ostream.hpp:702: undefined reference to `boost::log::v2s_mt_posix::aux::code_convert(wchar_t const*, unsigned long, std::string&, std::locale const&)'
/usr/include/boost/log/utility/formatting_ostream.hpp:696: undefined reference to `boost::log::v2s_mt_posix::aux::code_convert(wchar_t const*, unsigned long, std::string&, std::locale const&)'
sonar-logger.o: In function `void boost::log::v2s_mt_posix::type_dispatcher::callback_base::trampoline<boost::log::v2s_mt_posix::binder1st<boost::log::v2s_mt_posix::output_fun, boost::log::v2s_mt_posix::expressions::aux::stream_ref<boost::log::v2s_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> > >&>, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >(void*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)':
/usr/include/boost/log/utility/formatting_ostream.hpp:575: undefined reference to `boost::log::v2s_mt_posix::aux::code_convert(wchar_t const*, unsigned long, std::string&, std::locale const&)'
collect2: error: ld returned 1 exit status
I've compiled boost with the following:
./b2 --ignore-site-config -a -j9 --with-timer --with-system --with-chrono --with-iostreams --with-log --with-thread variant=debug link=static threading=multi
So far:
I've tried to troubleshoot it using this article (http://www.boost.org/doc/libs/1_60_0/libs/log/doc/html/log/rationale/namespace_mangling.html) that talks about how it could be a different namespace based on compiling. However, when I look in the libboost_log.a I can see functions named like so "void boost::log::v2s_mt_posix::aux::code_convert
This article (https://sourceforge.net/p/boost-log/discussion/710022/thread/2a7b5c0d/) says to make sure both BOOST_LOG_USE_CHAR and BOOST_LOG_USE_WCHAR_T are not defined. They are not.
Other articles say to define BOOST_LOG_DYN_LINK,but I'm using static libraries.
Here is how it's defined in my Makefile.am:
sonar_CPPFLAGS = -march=native -pipe -funroll-loops -fomit-frame-pointer -fforce-addr -fprefetch-loop-arrays -Wall -std=c++0x
sonar_SOURCES = main.cpp \
config.cpp \
config.hpp \
util.cpp \
util.hpp \
logger.cpp \
logger.hpp
sonar_LDADD = /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_system.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_timer.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_iostreams.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_thread.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_log_setup.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_log.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_filesystem.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_atomic.a -lcrypto -lssl
sonar_LDFLAGS = -pthread
How can I nix this linker error?
You're likely including headers from an older version of Boost.
In 1.60, the code_convert series of functions are templated, but the error you're seeing is an undefined reference to a non-templated function.
I'm getting some "undefined reference" errors in ld and am at a loss as to what's causing them.
My makefile builds several executables using commands like this:
g++ -ogui_program1 -Lpath/to/MyLibs gui_program1.o -lMyUI -lMyBusinessLogic \
-lMyUtil -lboost_regex
g++ -ogui_program2 -Lpath/to/MyLibs gui_program2.o -lMyUI -lMyBusinessLogic \
-lMyUtil -lboost_regex
g++ -ocli_program1 -Lpath/to/MyLibs cli_program1.o -lMyUI -lMyBusinessLogic \
-lMyUtil -lboost_regex
g++ -ocli_program2 -Lpath/to/MyLibs cli_program2.o -lMyUI -lMyBusinessLogic \
-lMyUtil -lboost_regex
And so on. (Actually, there are quite a few more libraries than this, but this is the general idea.)
MyUI, MyBusinessLogic, and MyUtil are all dynamic libraries that I've already built. To make writing the makefile simpler, the same list of libraries is used for both GUI and command line programs, even though the command line programs don't need libMyUI.so.
One and only one of the command line programs is giving numerous errors about undefined references to Boost.Regex symbols when I try to link it, even though I'm linking -lboost_regex with every binary:
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)'
libMyBusinessLogic.so: undefined reference to `boost::cpp_regex_traits::toi(char const*&, char const*, int) const'
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::match()'
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)'
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::find()'
libMyBusinessLogic.so: undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)'
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher >, boost::regex_traits > >::match()'
Linking all other programs works fine. If I remove -lMyUI from the one command-line program, then it works fine, even though MyUI doesn't show up anywhere in the error list.
Why isn't ld finding Boost.Regex symbols, when I've added -lboost_regex to the end of the command? Why does removing a seemingly unrelated library fix it? Why do other programs link without any problems?
I've figured out at least most of the answer. Due to some sloppiness in my makefile rules, libMyUI.so was linked against boost_regex, but libMyBusinessLogic.so wasn't. I'm guessing that, as a result, linking MyUI caused boost_regex to get pulled in prematurely, before the linker knew all of the symbols that MyBusinessLogic would need from it.
As long as I'm consistent - either all of My*.so link with boost_regex, or none of them do - everything works. I'm not sure which of these solutions is most preferred, but at least I have a fix.
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).
At first, small program:
#include <mysql++.h>
using namespace mysqlpp;
void mainuu ()
{ Connection conn("mysql", "localhost", "root", "pwd");}
If I compile it as one file in CodeLite or in such way:
g++ -I/usr/include/mysql -I/usr/include/mysql++ -lmysqlclient -lmysqlpp -o Test mysql_api.cpp
it's ok
but, when I try to build whole project with this file I get this:
g++ -o ./Debug/server ./Debug/main.o ./Debug/log.o ./Debug/packet.o ./Debug/mysql_api.o -L.
./Debug/mysql_api.o: In function `mainuu()':
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10: undefined reference to `mysqlpp::Connection::Connection(char const*, char const*, char const*, char const*, unsigned int)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:12: undefined reference to `mysqlpp::Connection::query(char const*)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:13: undefined reference to `mysqlpp::SQLTypeAdapter::SQLTypeAdapter(char const*, bool)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:13: undefined reference to `mysqlpp::operator<<(mysqlpp::quote_type1, mysqlpp::SQLTypeAdapter const&)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:19: undefined reference to `mysqlpp::operator<<(std::basic_ostream<char, std::char_traits<char> >&, mysqlpp::String const&)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10: undefined reference to `mysqlpp::Connection::~Connection()'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10: undefined reference to `mysqlpp::Connection::~Connection()'
./Debug/mysql_api.o: In function `mysqlpp::Row::operator[](int) const':
/usr/include/mysql++/row.h:328: undefined reference to `mysqlpp::Row::at(unsigned int) const'
./Debug/mysql_api.o: In function `mysqlpp::Query::store()':
/usr/include/mysql++/query.h:467: undefined reference to `mysqlpp::Query::str(mysqlpp::SQLQueryParms&)'
/usr/include/mysql++/query.h:467: undefined reference to `mysqlpp::SQLTypeAdapter::SQLTypeAdapter(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
/usr/include/mysql++/query.h:467: undefined reference to `mysqlpp::Query::store(mysqlpp::SQLTypeAdapter const&)'
collect2: ld returned 1 exit status
make[1]: *** [Debug/server] Error 1
make[1]: Leaving directory `/home/asyler/.codelite/workspace/test/server'
make: *** [All] Error 2
Here is CodeLite g++ compiler settings:
-g -I/usr/include/mysql -I/usr/include/mysql++ -lmysqlclient -lmysqlpp -L/usr/lib/mysql -L/usr/lib/mysql++ -lmysql++
Looks like you need to edit CodeLite project settings and add these settings -lmysqlclient -lmysqlpp that you pass in command line. Fill Library Path and Libraries fields on Linker tab.
Those are linker errors.
When you create your final executable, you still must provide references to all library functions, just as you did when you compiled the single translation unit.
So, pass -lmysqlclient -lmysqlpp to g++ this time, too.
If you are using an Integrated Development Environment, configure your project's build settings accordingly. In particular, I see that CodeLite has both "Compiler" and "Linker" build settings. It's "Linker" settings that you're after.
For more information on the build process (i.e. compiling, linking and the difference), read a good C++ book.