Cygwin Compiler: Undefined Reference - c++

When I try to compile a random project in Code:Blocks, the Cygwin Compiler throws an undefined reference error about own library files:
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(_cygwin_crt0_common.o):_cygwin_crt0_common.cc:(.data+0x0):
undefined reference to `___real__Znwj'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(_cygwin_crt0_common.o):_cygwin_crt0_common.cc:(.data+0x8):
undefined reference to `___real__ZdlPv'
I am linking the netlink library as well as the WS2_32.lib
Is that a compiler issue?

Other hint, it comes from _cygwin_crt0_common.cc. So there is obviously central something missing. You are using Cygwin version of gcc, right? Have your tried -lcygwin? You could also try -mno-cygwin.
My advice is normally to use vanilla MinGW, creates clean windows binaries (at the loss of POSIX features)..

Related

Boost linking error - single undefined reference

I'm having an odd linking problem with Boost (version 1.58). I'm building with g++ 4.8 on Ubuntu 15.10.
I get the following error:
undefined reference to
'boost::program_options::options_description::options_description(std::string
const&, unsigned int, unsigned int)' collect2: error: ld returned 1
exit status
What's strange is that all other symbols from lboost_program_options are found; options_description is the only undefined reference. If I comment out uses of options_description but keep uses of positional_options_description (which I'm also using) then the whole program compiles and links flawlessly. I am linking with -lboost_program_options, and if I remove this then as expected there are 8 missing boost::options_description symbols.
For a long time linking has worked correctly. Without any build system changes that I'm aware of it suddenly broke. The only systems level change was an upgrade to Ubuntu 15.10, which I don't think should have affected anything.
Any thoughts or suggestions appreciated.
Update: After lots of fiddling I got this working again, although I'm not sure what did it. I'm still interested in any answers to what could cause this type of behavior though.
Check that the ABI is compatible (you're using the same compiler version and flags used when compiling the boost libraries).
On Ubuntu, this means using stock GCC with libstdc++.
If you can't, compile your own Boost System and Boost Program Options binaries using your preferred flags.
Similar things prevent code samples from linking on http://coliru.stacked-crooked.com if your compiler is not the same as used when compiling boost there.
I had a similar problem after upgrading to Ubuntu 15.10 with a different symbol missing in a lib belonging to boost::program_options.
It helped to simply clean up the whole project by throwing away all object files etc. and recompiling it from scratch.

Issues with Boost Linking/Build in Dev-C++

I'm trying to compile a personal program that uses the Boost/Regex library in Orwell Dev-C++ with TDM-GCC 4.8.2 64 bit Release, and when I attempt to initialize a Boost::Regex object I get these error messages.
text$_ZN5boost9re_detail27cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE[_ZN5boost9re_detail27cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE]+0x2b): undefined reference to `boost::re_detail::cpp_regex_traits_char_layer<char>::init()'
regex_tester_main.cpp:(.text$_ZN5boost9re_detail11raw_storage6extendEy[_ZN5boost9re_detail11raw_storage6extendEy]+0x5f): undefined reference to `boost::re_detail::raw_storage::resize(unsigned long long)'
regex_tester_main.o: bad reloc address 0x5f in section `.text$_ZN5boost9re_detail11raw_storage6extendEy[_ZN5boost9re_detail11raw_storage6extendEy]'
I've followed this guide to install Boost and I used gcc as my toolkit parameters for the bootstrap.bat and the b2 builder. I've included the include and lib paths in my includes and library options. And lastly linked the appropriate libboost_regex*.a file. Before this I tried using the mingw toolkit option for the bootstrap and gcc option for b2 like the tutorial linked above does, and encountered the same errors. Can anyone shed insight into what has gone wrong?
SOLVED!
I also have the Haskell GHC installed which comes packaged with a mingw/GCC package which was located earlier in the PATH environment variable than the TDM-GCC/minGW-64 package I was aiming to use to build Boost. And so when I specified my toolset it was targeting the wrong complier and thus when I tried to build other programs with Boost it probably ran into some name-mangling issues. I removed GHC's mingw/GCC complier package from PATH and rebuilt Boost, it complies and links fine now :).

cross compiling qt (linux/mingw -> windows): various undefined references

(Crosspost from here, since nobody seems to have an idea)
Hello everyone,
I am trying to cross compile qt 4.8.3 from my linux for my windows. The final goal is to build a static qt, but independent of building static or not I always get the same error. Playing around with various flags didn't help either:
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x18dc): undefined reference to `QGb18030Codec::QGb18030Codec()'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x18ef): undefined reference to `QGbkCodec::QGbkCodec()'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x1902): undefined reference to `QGb2312Codec::QGb2312Codec()'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x1915): undefined reference to `QEucJpCodec::QEucJpCodec()'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x1928): undefined reference to `QJisCodec::QJisCodec()'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x193b): undefined reference to `QSjisCodec::QSjisCodec()'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x1956): undefined reference to `vtable for QEucKrCodec'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x1971): undefined reference to `vtable for QCP949Codec'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x198c): undefined reference to `vtable for QBig5Codec'
./.obj/release-shared/qtextcodec.o:qtextcodec.cpp:(.text+0x19a7): undefined reference to `vtable for QBig5hkscsCodec'
I'm using the default win32-g++ configuration file in combination with mingw.
I googled quite a bit around, but I have still no idea, where this comes from.. Maybe someone of you has the right hint for me ;-)
You could use MXE to build it. It's quite easy. You simply do:
make qt
It does pretty much everything automatically, including downloading sources, applying needed patches to enable cross compiling (which might be why manually cross compiling Qt on your own is failing), and building all dependencies. You can download MXE from: http://mxe.cc. Read the docs of course on how to cross compile software with it.
The gist of it is that instead of qmake you use i686-pc-mingw32-qmake (after you've changed your PATH to include the MXE directory, as per the docs.)
MXE builds everything as static libraries, so when you cross compile a program, you'll get a single .exe file with no depenendies on any DLLs.

Linker Error When Using Boost.asio With MingW on windows 7

I tried to compile a very basic example found on the boost.asio example but I'm getting linker error's. This is the complete command line I'm using:
mingw32-c++.exe -L..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib -L..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib -o bin\Debug\CPP_WITHOUT_FEAR_1st_APP.exe obj\Debug\main.o obj\Debug\prog_2.o obj\Debug\timer.o obj\Debug\convert.o -lwsock32 ..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib\libboost_system-mgw45-mt-1_48.a
The Errors I'm getting:
..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib\libboost_system-mgw45-mt-1_48.a(error_code.o):error_code.cpp:(.text+0x148): undefined reference to `_Unwind_Resume'
..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib\libboost_system-mgw45-mt-1_48.a(error_code.o):error_code.cpp:(.text+0x16c4): undefined reference to `_Unwind_Resume'
..\..\Important\docs\c++\boost\boost_1_48_0\stage\lib\libboost_system-mgw45-mt-1_48.a(error_code.o):error_code.cpp:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
Tried to figure out what's wrong but I was unable to find the answer any where.
Thanks,
Sree
Are you trying to link object files compiled in gcc with your program compiled in g++ ?
`undefined reference to `__gxx_personality_v0'`
is normally related to specifying gcc as the compiler when you meant to specify g++
If this isn't the case are you trying to link object files compiled with SJLJ (setjmp/longjmp) using a DW2 (Dwarf-2) compiler or vice versa ?
E.g. Were your program's object files compiled by mingw (version 3.4.5 is SJLJ) and boost compiled by gcc (version 4.4+ is DW2) ?
If this was the case, then ensure that your compiler and the libraries you are linking to were compiled with the same compiler, that has either SJLJ exception handling or DW2 exception handling.
The minGW 4.40 beta on their website has DW2 by default now, and assuming that boost was compiled with DW2, that should then compile and link cleanly.
As for what SJLJ and DW2 are they are methods of exception handling. SJLJ uses setjmp and longjump, whilst DW2 uses DWARF-2 (or DWARF-3) debugging information. SJLJ is slower but DW2 requires more space, leading to large binaries.
For more information about exception handling see here
For how DW2 works see here

Mysql++ "undefined reference to __imp___ZN7mysqlpp10ConnectionC1Eb"

I am trying to install the mysql++ in Code::Blocks, but When I try to run the example code I get this error:
undefined reference to __imp___ZN7mysqlpp10ConnectionC1Eb
What I am doing wrong?
You must build MySQL++ with the exact same compiler and compiler options as you're using to build your program. What you're seeing is a name mangling and/or ABI mismatch due to mixing compilers and/or build options. This can be anything from a drastic error like trying to use a Visual C++ DLL with MinGW, to something more subtle like trying to use a MinGW DLL built with g++ 3.4.5 in a program you're building with MinGW g++ 4.4.
Unlike C, C++ doesn't try to preserve binary compatibility between greatly different compilers.
You probably have a linker issue. It could well be that a DLL you need isn't present, or mysql++ was compiled but not correctly linked.