gcc -funit-at-a-time causing compile to fail - c++

we have started linking our application with -libmysqlcppconn-static for MySQL support.
When we compile for debugging everything is ok, but when we compile for release using gcc -O2 we get errors.
We have tracked down the offending compiler option to be -funit-at-a-time.
We get may errors of the form:
libmysqlcppconn-static.a(mysql_connection.cpp.o): In function
sql::mysql::MySQL_Savepoint::getSavepointId()':
mysql_connection.cpp:(.text+0x8d): undefined reference to
std::allocator: :allocator()'
mysql_connection.cpp:(.text+0x133): undefined reference to
`std::allocator ::~allocator()'
We are working around this for now by including -fno-unit-at-a-time. Any insight into how we can correct this would be appreciated

it might be because you are using using gcc to compile the code.. try using g++ to compile the file
otherwise try using following command
gcc -lstdc++ file.cpp

Related

c++ compiling error with terminal

I wrote a piece of code with xcode 7.2 on a mac which compiles and works fine. However when i try to compile from terminal with command g++ -std=c++11 -o main.cpp an error occurs undefined symbols for architecture x86_64
functionname(std::_1::basic_istream<char,std::_1::char_traits<char> >&)"
where functionname is a function I created that has a file stream as a parameter.I am new to these kinds of compiling errors, so help would be much appreciated.

Getting huge error spew from GtkD on a simple program

I installed GtkD from AUR, and now I'm trying to compile this tutorial code. Both for compiling GtkD itself and the tutorial code, I'm using GDC 4.9.1.
I attempted to compile the code as follows (hello.d is the file name):
gdc -Wall -Werror -Wdeprecated -Wunknown-pragmas -g -m64 `pkg-config --cflags --libs gtkd-2` -O3 -frelease -o hello
But when I try that, I get this:
/tmp/ccxejYOB.o: In function `_Dmain':
/home/koz/Documents/Programming/D/gtkd/hello.d:23: undefined reference to `_D3gtk4Main4Main4initFKAAyaZv'
/home/koz/Documents/Programming/D/gtkd/hello.d:24: undefined reference to `_D3gtk10MainWindow10MainWindow7__ClassZ'
/home/koz/Documents/Programming/D/gtkd/hello.d:24: undefined reference to `_D3gtk10MainWindow10MainWindow6__ctorMFAyaZC3gtk10MainWindow10MainWindow'
/home/koz/Documents/Programming/D/gtkd/hello.d:26: undefined reference to `_D3gtk5Label5Label7__ClassZ'
/home/koz/Documents/Programming/D/gtkd/hello.d:26: undefined reference to `_D3gtk5Label5Label6__ctorMFAyabZC3gtk5Label5Label'
/home/koz/Documents/Programming/D/gtkd/hello.d:28: undefined reference to `_D3gtk4Main4Main3runFZv'
/tmp/ccxejYOB.o:(.data+0x30): undefined reference to `_D3gtk10MainWindow12__ModuleInfoZ'
/tmp/ccxejYOB.o:(.data+0x38): undefined reference to `_D3gtk5Label12__ModuleInfoZ'
/tmp/ccxejYOB.o:(.data+0x40): undefined reference to `_D3gtk4Main12__ModuleInfoZ'
/tmp/ccxejYOB.o:(.data._D67TypeInfo_S3std8typecons35__T6scopedTC5cairo7Context7ContextZ6Scoped6__initZ[_D67TypeInfo_S3std8typecons35__T6scopedTC5cairo7Context7ContextZ6Scoped6__initZ]+0x58): undefined reference to `_D3std8typecons35__T6scopedTC5cairo7Context7ContextZ6Scoped6__dtorMFZv'
I have no clue what's going on here, and would appreciate all the help possible.
GtkD in the AUR is compiled using DMD. ABI compatibility between DMD and GDC binaries is not guaranteed and linking may fail as in your case. (Linking may also succeed and you get runtime problems). To troubleshoot the issue, you can try using DMD and see if that solves your issue.
Anyway, I would recommend using dub and gtk-d library from the dub registry. Dub will take care of the compilation of your source code and gtk-d's code and linking them together. And it will enable you to use any compiler easily.
If you don't want to use dub, you can also download gtk-d and build it yourself using GDC.

GCC Fails to Generate Object Files When Compiling

Recently I have noticed that GCC does not generate object (*.o) files when compiling with '-c'. It does not issue any errors or warnings. I have run it with '-verbose' but it shows nothing out of the ordinary.
Running under Windows:
gcc -Wall -c source_file.c
I have also tried compiling with '-verbose' to display detailed information
gcc -Wall -verbose -c source_file.c
It should produce 'source_file.o' but it doesn't. Any idea what's going on?
The issue has been resolved. Reinstalling GCC (mingw) fixed the problem. It is possible the problem came about because I tried to install the 64-bit version of GCC (Mingw-w64) to top of the 32-bit version...

Static linking to libcrypto++, with g++

I am trying to compile a program on my system with Debian Wheezy and g++4.7. I want it to be able to run on another system with Debian Squeeze (and no recent g++). I can't compile the program on the Squeeze, because I use certain C++11 features the old g++ does not support, as well as a new Boost version and libcrypto++9.
As far as I understand the usual way to get around this problem is to static link the libraries not supported at the other system, in my case libstdc, boost and crypto++.
My (linking) compiler call right now is
g++-4.7 .obj/btcmirco.o -Wl,-Bstatic -lboost_program_options -lboost_system -lcrypto++ -Wl,-Bdynamic -lcurl -static-libgcc -std=c++11 -o MyProgram
However I seem to have missed something, because it throws a lot of undefined reference errors. It works fine if I dynamic link to crypto++ (and only static link libstdc and boost).
Can anyone tell me whats wrong, or if there is a fundamental error in my approach?
The linker errors I get are (shorted):
`.text._ZN8CryptoPP22BufferedTransformationD2Ev' referenced in section `.text._ZN8CryptoPP22BufferedTransformationD1Ev[_ZN8CryptoPP22BufferedTransformationD1Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib/libcrypto++.a(cryptlib.o): defined in discarded section `.text._ZN8CryptoPP22BufferedTransformationD2Ev[_ZN8CryptoPP22BufferedTransformationD5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib/libcrypto++.a(cryptlib.o)
`.text._ZN8CryptoPP25MessageAuthenticationCodeD2Ev' referenced in section `.text._ZN8CryptoPP25MessageAuthenticationCodeD1Ev[_ZN8CryptoPP25MessageAuthenticationCodeD1Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib/libcrypto++.a(cryptlib.o): defined in discarded section `.text._ZN8CryptoPP25MessageAuthenticationCodeD2Ev[_ZN8CryptoPP25MessageAuthenticationCodeD5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib/libcrypto++.a(cryptlib.o)
I experienced the same problem and this has to do with the fact that you are trying to mix code generated by g++-4.7 (your program) with code generated by a previous version of g++ (cryptopp library).
The reason behind this is that when you execute compile the library executing make command, it uses the default version of g++ set up for your system, usually the one that comes with the OS.
In order to solve the issue what you should do is compile cryptopp library with g++-4.7.
For that, compile the library by executing make CXX=g++-4.7. The resulting static library shouldn't give you the error when being linked with your code.

undefined reference to `GdiplusStartup#12'

I'm finding a way to use GDI+ library with g++ compiler, I have read some guildlines on the web and still meet with problem...
Here is my code:
#include "gdiplus.h"
using namespace Gdiplus;
// Skip Lines
GdiplusStartup(&lpGdiplusToken, &gdiplusStartupInput, &gdiplusStartupOutput);
// Skip Lines
And I have already used the compiler switch as below:
g++ -Wall -mwindows -lgdiplus -I"C:\MinGW\include" -I"C:\MinGW\include\gdiplus" -L"C:\MinGW\lib" -g3 -finput-charset=GBK "$(FilePath)" -o "$(FileDir)\$(FileNameNoExt).exe"
Still I got such errors:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccjX3mCb.o: In function `WinMain#16':
D:/Projects/cyau/cyau_pre4_20120226/cyau_main.cpp:65: undefined reference to `GdiplusStartup#12'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccjX3mCb.o: In function `Z15ExitApplicationP6HWND__jjl':
D:/Projects/cyau/cyau_pre4_20120226/cyau_main.cpp:128: undefined reference to `GdiplusShutdown#4'
So what's wrong with it? Is there anything more I need?
Thanks for help...
I had similar messages as you and after some research I've come to the following: place -lgdiplus after *.cpp files on the command line. Example:
g++ -mwindows program.cpp -lgdiplus
That command compiled my GDI+ program.
I'm using DevCPP, and had the same issue.
Creating a libgdiplus.a from a gdiplus.def
using this command solved my problem:
dlltool -k -d gdiplus.def -l libgdiplus.a
Initially i was using the command above without the -k params.
This worked for me. If you are using CodeBlocks
add
-mwindows -lgdiplus
on the other linker options
Step 1
Step 2
I don't have experience with g++, but I believe the problem is with linking.
Either the gdiplus library isn't getting linked, or it isn't compatabile with g++.
Hopefully that will help you continue tracking down the problem.
I am using VS 2015. One program compiles OK. Another program using the same code gave me the `GdiplusStartup#12'error (and many others). Fixed the problem by adding GdiPlus.lib to the linker input. Do not understand why the two programs behave differently, but it works.