undefined reference gcc cxa - c++

I'm trying to compile a program with make, but I get stuck on a error raised (see below) :
gcc -Wall -g -O2 -I. -I../include -I/usr/include/libxml2/ -I/usr/include/x86_64-linux-gnu/ -I/usr/include/geotiff/ -I/usr/local/hdf4/hdf-4.2.11/hdf4/include/ -I/usr/local/hdf-eos/hdfeos/include/ -I -I -o convert_lpgs_to_espa convert_lpgs_to_espa.o -L../lib -l_espa_format_conversion -l_espa_raw_binary -l_espa_common -L/usr/lib/x86_64-linux-gnu/ -lxml2 -L/usr/lib/ -lgeotiff -L/usr/lib/x86_64-linux-gnu/ -ltiff -L/usr/lib/x86_64-linux-gnu/ -ljpeg -L -ljbig -L/usr/local/hdf-eos/hdfeos/hdfeos2/lib -lgctp -L -lz -lm
/usr/lib/x86_64-linux-gnu/libicuuc.so.52: référence indéfinie vers « __cxa_throw_bad_array_new_length#CXXABI_1.3.8 »
collect2: error: ld returned 1 exit status
Makefile:95: recipe for target 'convert_lpgs_to_espa' failed
make[1]: *** [convert_lpgs_to_espa] Error 1
make[1]: Leaving directory '/project/$folders$/tools'
Makefile:6: recipe for target 'all' failed
make: *** [all] Error 2
Following this close question : program linking fails when using custom built gcc, I purge and reinstall libstdc++-4.9-dev.
I'm running
Ubuntu 15.04 with gcc (Ubuntu 4.9.2-10ubuntu13) 4.9.2
How can I resolve this issue ?

It's because you link using gcc instead of g++. The difference is that the g++ command adds the C++ runtime library when linking.
You can either change from using gcc to g++, or manually link with the C++ runtme library by adding -lstdc++.

Related

Undefined reference to `fftw_init_threads' while installing pHash library

I am trying to install pHash library on ubuntu, i installed libfftw3 and all the required libraries. Everything is Ok when I run ./configure command, but when i try to run the 'make' command this error always appear : undefined reference to `fftw_init_threads'.
make command :
g551683#sst-p1310007fl:~/Documents/pHash-0.2.9.6$ make
make all-recursive
make[1]: Entering directory '/home/g551683/Documents/pHash-0.2.9.6'
Making all in src
make[2]: Entering directory '/home/g551683/Documents/pHash-0.2.9.6/src'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/g551683/Documents/pHash-0.2.9.6/src'
Making all in bindings
make[2]: Entering directory '/home/g551683/Documents/pHash-0.2.9.6/bindings'
make[3]: Entering directory '/home/g551683/Documents/pHash-0.2.9.6/bindings'
make[3]: Nothing to be done for 'all-am'.
make[3]: Leaving directory '/home/g551683/Documents/pHash-0.2.9.6/bindings'
make[2]: Leaving directory '/home/g551683/Documents/pHash-0.2.9.6/bindings'
Making all in examples
make[2]: Entering directory '/home/g551683/Documents/pHash-0.2.9.6/examples'
/bin/sh ../libtool --tag=CXX --mode=link g++ -O2 -ffast-math -O3 -L/usr/local/lib -lssl -lcrypto -o test_texthash test_texthash.o ../src/libpHash.la -lmpg123 -lsamplerate -lsndfile -lswscale -lavformat -lavutil -lavcodec -lpng -ljpeg -lfftw3
libtool: link: g++ -O2 -ffast-math -O3 -o .libs/test_texthash test_texthash.o -L/usr/local/lib ../src/.libs/libpHash.so -lssl -lcrypto /usr/local/lib/libmpg123.so /usr/lib/x86_64-linux-gnu/libltdl.so -ldl /usr/local/lib/libsamplerate.so -lsndfile -lswscale -lavformat -lavutil -lavcodec /usr/local/lib/libpng16.so -lz /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/local/lib/libfftw3.a -lm
test_texthash.o: In function `_GLOBAL__sub_I_main':
test_texthash.cpp:(.text.startup+0x1b1): undefined reference to `fftw_init_threads'
collect2: error: ld returned 1 exit status
Makefile:323: recipe for target 'test_texthash' failed
make[2]: *** [test_texthash] Error 1
make[2]: Leaving directory '/home/g551683/Documents/pHash-0.2.9.6/examples'
Makefile:419: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/g551683/Documents/pHash-0.2.9.6'
Makefile:298: recipe for target 'all' failed
make: *** [all] Error 2
Can someone help me to solve this error!
From the documentation:
First, programs using the parallel complex transforms should be linked with -lfftw3_threads -lfftw3 -lm on Unix, or -lfftw3_omp -lfftw3 -lm if you compiled with OpenMP. You will also need to link with whatever library is responsible for threads on your system (e.g. -lpthread on GNU/Linux) or include whatever compiler flag enables OpenMP (e.g. -fopenmp with gcc).
You are not linking against this fftw3_threads library, nor to the pthread library.

undefined reference to symbol '_ZN5boost6system15system_categoryEv' error

I'm new to c++ rest sdk Casablanca and using it in Codelite ide.
Operating System : Arch Linux
gcc version : 6.1.1
While building the code I get the following error in debug mode:
/bin/sh -c '/usr/bin/make -j4 -e -f Makefile'
----------Building project:[ Casa - Debug ]----------
make[1]: Entering directory '/home/vinci/Documents/CPP_Projects_Programs/Casa'
/usr/bin/g++ -c "/home/vinci/Documents/CPP_Projects_Programs/Casa/main.cpp" -g -O0 -fopenmp -std=c++14 -std=c++11 -Wall -o ./Debug/main.cpp.o -I. -I/usr/local/include/cpprest -I/usr/local/include/pplx -I/home/vinci/casablanca/Release/src -I. -I/usr/local/include/cpprest -I/usr/local/include/pplx
/usr/bin/g++ -o ./Debug/Casa #"Casa.txt" -L. -L/usr/local/lib -L/usr/lib64 -L/usr/lib -lcpprest
/usr/bin/ld: ./Debug/main.cpp.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/lib/libboost_system.so.1.60.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[1]: *** [Casa.mk:79: Debug/Casa] Error 1
make[1]: Leaving directory '/home/vinci/Documents/CPP_Projects_Programs/Casa'
make: *** [Makefile:5: All] Error 2
====1 errors, 0 warnings, total time: 00:00:14 seconds====
I searched this on Stackoverflow before asking and most of the answers just pointed to linking the libraries properly in project settings and I have done that as one can see in the code above but still keeps giving the error and I don't know what am i missing??
A little Help would be appreciated...
Thank You
/usr/lib/libboost_system.so.1.60.0: error adding symbols: DSO missing from command line
This DSO error means that libboost_system is missing from the command line.
You should also add:
-lboost_system
to your command line just like -lcpprest
This can happen if you reference libraries in the wrong order. I have a personal library that depends on -lboost_system, but I had listed my own library after the boost library and was getting this error. I moved my personal library to the front of the list, and the error went away.

Building Lua on windows gives undefined reference error

while building Lua on windows by mingw491 it gives an undefined reference error. Following is the output:
C:\Users\Alizadeh\Desktop\lua-5.3.0>mingw32-make PLAT=mingw
cd src && mingw32-make mingw
mingw32-make[1]: Entering directory 'C:/Users/Alizadeh/Desktop/lua-5.3.0/src'
mingw32-make "LUA_A=lua53.dll" "LUA_T=lua.exe" \
"AR=gcc -std=gnu99 -shared -o" "RANLIB=strip --strip-unneeded" \
"SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe
mingw32-make[2]: Entering directory 'C:/Users/Alizadeh/Desktop/lua-5.3.0/src'
g++ -c -o lua.o lua.c
g++ -c -o lapi.o lapi.c
g++ -c -o lcode.o lcode.c
.
.
.
g++ -c -o loadlib.o loadlib.c
g++ -c -o linit.o linit.c
gcc -std=gnu99 -shared -o lua53.dll lapi.o lcode.o lctype.o ldebug.o ldo.o ldump
.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o
ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o lbitlib.o lcorolib.o
ldblib.o liolib.o lmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o
linit.o
ldo.o:ldo.c:(.text+0xe5): undefined reference to `__cxa_allocate_exception'
ldo.o:ldo.c:(.text+0x105): undefined reference to `__cxa_throw'
ldo.o:ldo.c:(.text+0x234): undefined reference to `__cxa_begin_catch'
ldo.o:ldo.c:(.text+0x24c): undefined reference to `__cxa_end_catch'
ldo.o:ldo.c:(.rdata$_ZTIP11lua_longjmp[__ZTIP11lua_longjmp]+0xffff3fb8): undefin
ed reference to `vtable for __cxxabiv1::__pointer_type_info'
C:/Qt/Qt5.4.0/Tools/mingw491_32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../.
./i686-w64-mingw32/bin/ld.exe: ldo.o: bad reloc address 0x0 in section `.rdata$_
ZTIP11lua_longjmp[__ZTIP11lua_longjmp]'
collect2.exe: error: ld returned 1 exit status
makefile:59: recipe for target 'lua53.dll' failed
mingw32-make[2]: *** [lua53.dll] Error 1
mingw32-make[2]: Leaving directory 'C:/Users/Alizadeh/Desktop/lua-5.3.0/src'
makefile:116: recipe for target 'mingw' failed
mingw32-make[1]: *** [mingw] Error 2
mingw32-make[1]: Leaving directory 'C:/Users/Alizadeh/Desktop/lua-5.3.0/src'
makefile:55: recipe for target 'mingw' failed
mingw32-make: *** [mingw] Error 2
I'm using mingw (491) on windows7 and I want to link it with Qt.
I found the answer. I've just used g++ instead of gcc and it fixed :)
The solution is to add the following line in src/Makefile:
CXX= gcc -std=gnu99
Or more generally to set CXX to whichever value CC is set.
This problem occurs because the Lua make files rely on the implicit rules and variables of GNU make (source). Which means that make should call $(CC) -c $(CFLAGS) $(CPPFLAGS) to build .o files from .c files.
However mingw make calls $(CXX) -c $(CFLAGS) $(CPPFLAGS). This means that Lua C code is compiled as C++. The issue reveals itself at linktime as here gcc is used and it fails to find C++ related dependencies. So from here you have 2 solutions:
Replace gcc by g++ at link time (Mosi's solution). Which you should NOT do!
As you will end up with C++ symbols with mangled names and you will not be able to use your DLL in anything else than C++ projects. Although your code will not be portable as any other Lua DLL will not have C++ symbols.
Replace g++ by gcc during compilation (see above). You will end up with valid C symbols in your DLL.

Building error in make step, gdk, libbat.la, MT_global_exit

i'm trying to build MonetDB from source on CentOS.
Typically the problems occur in the make step,
I run the configuration as follows
./configure -prefix=$HOME/MonetDB--disable-geom --disable-strict
This works perfectly fine. However, using "make" afterwards leads to an error:
...
make[3]: Entering directory `/users/db01/dm/MonetDB/MonetDB-11.19.9/gdk'
/bin/sh ../libtool --tag=CC --mode=link gcc -DLIBGDK -g -O2 -D_REENTRANT -version-info 11:4:0 -o libbat.la -rpath /users/db01/dm/MonetDB/MDB/lib libbat_la-gdk_batop.lo libbat_la-gdk_select.lo libbat_la-gdk_select_legacy.lo libbat_la-gdk_search.lo libbat_la-gdk_tm.lo libbat_la-gdk_align.lo libbat_la-gdk_bbp.lo libbat_la-gdk_heap.lo libbat_la-gdk_setop.lo libbat_la-gdk_utils.lo libbat_la-gdk_atoms.lo libbat_la-gdk_qsort.lo libbat_la-gdk_ssort.lo libbat_la-gdk_storage.lo libbat_la-gdk_bat.lo libbat_la-gdk_delta.lo libbat_la-gdk_cross.lo libbat_la-gdk_system.lo libbat_la-gdk_value.lo libbat_la-gdk_posix.lo libbat_la-gdk_logger.lo libbat_la-gdk_sample.lo libbat_la-gdk_calc.lo libbat_la-gdk_aggr.lo libbat_la-gdk_group.lo libbat_la-gdk_mapreduce.lo libbat_la-gdk_imprints.lo libbat_la-gdk_join.lo libbat_la-gdk_join_legacy.lo libbat_la-gdk_unique.lo libbat_la-gdk_firstn.lo ../common/options/libmoptions.la ../common/stream/libstream.la ../common/utils/libmutils.la -lm -lz -lbz2 -pthread -ldl
libtool: link: gcc -shared -fPIC -DPIC .libs/libbat_la-gdk_batop.o .libs/libbat_la-gdk_select.o .libs/libbat_la-gdk_select_legacy.o .libs/libbat_la-gdk_search.o .libs/libbat_la-gdk_tm.o .libs/libbat_la-gdk_align.o .libs/libbat_la-gdk_bbp.o .libs/libbat_la-gdk_heap.o .libs/libbat_la-gdk_setop.o .libs/libbat_la-gdk_utils.o .libs/libbat_la-gdk_atoms.o .libs/libbat_la-gdk_qsort.o .libs/libbat_la-gdk_ssort.o .libs/libbat_la-gdk_storage.o .libs/libbat_la-gdk_bat.o .libs/libbat_la-gdk_delta.o .libs/libbat_la-gdk_cross.o .libs/libbat_la-gdk_system.o .libs/libbat_la-gdk_value.o .libs/libbat_la-gdk_posix.o .libs/libbat_la-gdk_logger.o .libs/libbat_la-gdk_sample.o .libs/libbat_la-gdk_calc.o .libs/libbat_la-gdk_aggr.o .libs/libbat_la-gdk_group.o .libs/libbat_la-gdk_mapreduce.o .libs/libbat_la-gdk_imprints.o .libs/libbat_la-gdk_join.o .libs/libbat_la-gdk_join_legacy.o .libs/libbat_la-gdk_unique.o .libs/libbat_la-gdk_firstn.o -Wl,--whole-archive ../common/options/.libs/libmoptions.a ../common/utils/.libs/libmutils.a -Wl,--no-whole-archive -Wl,-rpath -Wl,/users/db01/dm/MonetDB/MonetDB-11.19.9/common/stream/.libs -Wl,-rpath -Wl,/users/db01/dm/MonetDB/MDB/lib ../common/stream/.libs/libstream.so -L/usr/kerberos/lib64 -lssl -lcrypto -lm -lz -lbz2 -ldl -O2 -pthread -pthread -Wl,-soname -Wl,libbat.so.11 -o .libs/libbat.so.11.0.4
/usr/bin/ld: .libs/libbat_la-gdk_utils.o: relocation R_X86_64_PC32 against `MT_global_exit' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
make[3]: *** [libbat.la] Error 1
make[3]: Leaving directory `/users/db01/dm/MonetDB/MonetDB-11.19.9/gdk'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/users/db01/dm/MonetDB/MonetDB-11.19.9/gdk'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/users/db01/dm/MonetDB/MonetDB-11.19.9'
make: *** [all] Error 2
I found a similar error, containing MT_global_exit in the web: https://www.monetdb.org/pipermail/users-list/2014-June/007334.html
Trying the mentioned suggestion by deleting __attribute__((__visibility__("hidden")))
from the gdk/gdk_private.h was
lead to several different errors (in gdk_private.h) during the make process.
If you have any suggestions, I'd be happy to hear them!
best regards

Install gdb-7.2 on Solaris 11 for segmentation fault error

I am trying to install gdb-7.2 on Solaris 11 for debugging a c++ script that is issuing a segmentation fault alert.
Once configured (./configure),
checking whether -fkeep-inline-functions is supported... yes
configure: creating ./config.status
config.status: creating Makefile
I move on make (make) however this fails with the following errors:
ar: creating libgdb.a ranlib libgdb.a
rm -f gdb
gcc -g -O2 -rdynamic \
-o gdb gdb.o libgdb.a \
../readline/libreadline.a ../opcodes/libopcodes.a ../bfd/libbfd.a \
../libiberty/libiberty.a ../libdecnumber/libdecnumber.a \
-ldl -lcurses -lz -lsocket -lnsl -lm -lsocket -lnsl -ldl -lm \
-lpython2.6 -lexpat ../libiberty/libiberty.a gnulib/libgnu.a
Undefined first referenced symbol in file
wattr_on libgdb.a(tui-wingeneral.o)
wattr_off libgdb.a(tui-wingeneral.o)
ld: fatal: symbol referencing errors. No output written to gdb collect2: ld returned 1 exit status
*** Error code 1 make: Fatal error: Command failed for target `gdb'
What could be the possible issue and is there any solution for this?
It looks like some bug linking against the Solaris curses library. Offhand I can't diagnose it. It's worth digging into and patching upstream...
Meanwhile, you can probably work around it by configuring with --disable-tui.