gcc static linking with LTO flag with boost filesystem fails - c++

boost version 1.64
gcc version 6.4.1
Linux OpenSuse x64 42.2
Cmake 3.5.2
[linking, no LTO] works:
-std=gnu++11 -O2 -fopenmp -static /opt/lib64/libboost_filesystem.a /opt/lib64/libboost_system.a
[linking, with LTO] does not work:
-std=gnu++11 -O2 -fopenmp -flto=8 -static /opt/lib64/libboost_filesystem.a /opt/lib64/libboost_system.a
error:
/opt/lib64/libboost_filesystem.a(operations.o): In function `boost::filesystem::detail::is_empty(boost::filesystem::path const&, boost::system::error_code*)':
operations.cpp:(.text+0x536a): undefined reference to `vtable for boost::detail::sp_counted_impl_p<boost::filesystem::detail::dir_itr_imp>'
/opt/lib64/libboost_filesystem.a(operations.o): In function `(anonymous namespace)::remove_all_aux(boost::filesystem::path const&, boost::filesystem::file_type, boost::system::error_code*)':
operations.cpp:(.text+0x699d): undefined reference to `vtable for boost::detail::sp_counted_impl_p<boost::filesystem::detail::dir_itr_imp>'
operations.cpp:(.text+0x6add): undefined reference to `vtable for boost::detail::sp_counted_impl_p<boost::filesystem::detail::dir_itr_imp>'
collect2: error: ld returned 1 exit status
CMakeFiles/zebr.dir/build.make:137: recipe for target 'zebr' failed
--> boost libraries compiled with gcc 6.4.1 and -std=gnu++11 flag
--> with gcc 4.8.5 everything works fine

Related

linking error in boost asio

I am getting below linking error while compiling a simple piece of code using pthread.
The system i am working on is x86_64 (gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11) and am compiling as -
gcc -lpthread ~/temp/temp.cpp -lrt -L"/usr/lib/x86_64-redhat-linux5E/lib64/".
Its evident that the problem is with pthread library. So i have two questions.
Q1. is it fine to use x64 pthread libs with x86 code. (In this piece of code it doesnt matter but it does in my usage) (I guess its not but how might i differentiate between x64 and x86 libs?)
Q2. i see pthread and lrt both are present at /usr/lib but even if i give that path it says -lpthread not found.
What am i missing here? Thanks for your help.
Error :
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x12): undefined reference to `__libc_csu_fini'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x19): undefined reference to `__libc_csu_init'
/tmp/cc2GQOUf.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
Code :
#include <stdio.h>
#include <pthread.h>
int main()
{
pthread_t f1_thread;
return 0;
}
In compilation phase,compiler can use gcc or g++,but g++ will call gcc command automatically.But in link phase,linker can use g++ or gcc -lstdc++.Because the gcc command cannot link with the libraries that be used by c++ program automatically, so usually use g++to complete the link.
So the command g++ -g -lpthread ~/temp/temp.cpp -o temp should be ok.

G++ ARM cross compiling: undefined references

I am trying to compile the Jasmine OpenSSD code with arm-none-eabi-g++.
However, it first failed with the following error message
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/bin/ld: cannot find -lstdc++
To fix that, I ensured that linking with libstdc++.a was possible. Once I fixed that, it failed with the following errors:
/usr/lib/gcc/arm-none-eabi/4.8.2//libgcc.a(unwind-arm.o): In function `get_eit_entry':
/build/buildd/gcc-arm-none-eabi-6/build/arm-none-eabi/libgcc/../../../gcc-4.8.2/libgcc/unwind-arm-common.inc:221: undefined reference to `__exidx_end'
/build/buildd/gcc-arm-none-eabi-6/build/arm-none-eabi/libgcc/../../../gcc-4.8.2/libgcc/unwind-arm-common.inc:221: undefined reference to `__exidx_start'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/libc.a(lib_a-abort.o): In function `abort':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/libc.a(lib_a-signalr.o): In function `_kill_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/libc.a(lib_a-signalr.o): In function `_getpid_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/signalr.c:96: undefined reference to `_getpid'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/sbrkr.c:58: undefined reference to `_sbrk'
collect2: error: ld returned 1 exit status
make: *** [firmware.elf] Error 1
Here is the actual step at which it fails:
arm-none-eabi-g++ -static -nostartfiles -ffreestanding -T ld_script -Wl,-O1,-Map=list.txt ftl.o sata_identify.o sata_cmd.o sata_isr.o sata_main.o sata_table.o initialize.o mem_util.o flash.o flash_wrapper.o misc.o uart.o init.o -o firmware.elf -L"/usr/lib/gcc/arm-none-eabi/4.8.2/" -lgcc
Can someone suggest a fix? Also, this works perfectly well if I use arm-none-eabi-gcc instead of arm-none-eabi-g++
Your problem is caused by exception handling code that is produced by the compiler, which relies on runtime components - those are not present in your build.
-fno-exceptions turns off exception handling in the code-generation of the compiler.

Program with protocol-buffers don't compile with MinGW-w64: "undefined reference to google::protobuf:: ..."

I have installed the libprotobuf-dev=2.6.0-4 and protobuf-compiler=2.6.0-4 packages from Debian Jessie repository. Now I'm trying to compile a program that use the 'addressbook.proto' file from the Google Developers example with the MinGW-w64 compiler. I'm using Ubuntu 14.04.
With this command the program works:
$ g++ main.cpp addressbook.pb.cc -lprotobuf
But I want to compile for Windows too.
I added the symlink: /usr/include/google -> /usr/i686-w64-mingw32/include/google.
$ i686-w64-mingw32-g++ main.cpp addressbook.pb.cc -lprotobuf
/usr/bin/i686-w64-mingw32-ld: cannot find -lprotobuf
collect2: error: ld returned 1 exit status
With the library location still not working:
$ i686-w64-mingw32-g++ -L /usr/lib/i386-linux-gnu/ main.cpp addressbook.pb.cc -lprotobuf
/tmp/ccB1VJyR.o:main.cpp:(.text$_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv[__ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv]+0x7): undefined reference to `google::protobuf::internal::empty_string_'
/tmp/ccB1VJyR.o:main.cpp:(.text$_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv[__ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv]+0x2f): undefined reference to `google::protobuf::internal::empty_string_'
/tmp/ccPz4uiI.o:addressbook.pb.cc:(.text+0x78): undefined reference to `google::protobuf::DescriptorPool::generated_pool()'
/tmp/ccPz4uiI.o:addressbook.pb.cc:(.text+0x87): undefined reference to `google::protobuf::DescriptorPool::FindFileByName(std::string const&) const'
...
libprotobuf-dev contains library headers and pre-built binaries for your system. If you are cross-compiling you need to compile library from sources to target system as well. Something like "./configure CC=i686-w64-mingw32-g++" in library sources directory should do the job.

OpenSSL compiles failed on x86 thought was successful for x86_64

I'm trying to compile my project for x86 and x86_64 architectures on Windows. Using 64bit GCC from mingwbuilds project (4.8.1 rev 5), OpenSSL 1.0.1e compiles and links successfully, but using 32bit version of same compiler I got undefined references:
libcrypto.a(cryptlib.o):cryptlib.c:(.text+0x391): undefined reference to `OPENSSL_cpuid_setup'
libcrypto.a(mem.o):mem.c:(.text+0x859): undefined reference to `OPENSSL_cleanse'
libcrypto.a(md2_dgst.o):md2_dgst.c:(.text+0x156): undefined reference to `OPENSSL_cleanse'
libcrypto.a(md2_one.o):md2_one.c:(.text+0x59): undefined reference to `OPENSSL_cleanse'
libcrypto.a(md4_one.o):md4_one.c:(.text+0x56): undefined reference to `OPENSSL_cleanse'
libcrypto.a(md5_one.o):md5_one.c:(.text+0x56): undefined reference to `OPENSSL_cleanse'
libcrypto.a(sha_one.o):sha_one.c:(.text+0x56): more undefined references to `OPENSSL_cleanse' follow
libcrypto.a(eng_all.o):eng_all.c:(.text+0x4): undefined reference to `OPENSSL_cpuid_setup'
libcrypto.a(eng_rdrand.o):eng_rdrand.c:(.text+0x4e): undefined reference to `OPENSSL_ia32_rdrand'
libcrypto.a(eng_rdrand.o):eng_rdrand.c:(.text+0x81): undefined reference to `OPENSSL_ia32_rdrand'
c:/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.1/../../../../i686-w64-mingw32/bin/ld.exe: libcrypto.a(eng_rdrand.o): bad reloc address 0x4 in section `.data'
collect2.exe: error: ld returned 1 exit status
OpenSSL is configured like this:
# on x86_64:
./Configure mingw64 -fPIC -O3 --prefix=/mingw shared enable-ec_nistp_64_gcc_128
enable-krb5 enable-md2 enable-rc5 enable-rfc3779 no-asm
# and for x86:
./Configure mingw -fPIC -O3 --prefix=/mingw shared \
enable-krb5 enable-md2 enable-rc5 enable-rfc3779 no-asm
Found it myself :) This is where exports are prevented for i386 when no assembler used. Specifically:
#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) && !defined(I386_ONLY)
#define OPENSSL_CPUID_SETUP
#if defined(_WIN32)
typedef unsigned __int64 IA32CAP;
#else
typedef unsigned long long IA32CAP;
#endif
void OPENSSL_cpuid_setup(void)
{ ...
So, we need an assembler for x86. I Installed NASM and the library compiles successfully.

OCCI compilation with g++ in Linux

I'm trying to compile a basic program using OCCI library.
The compilation task is OK.
g++ -I. -g -I/opt/oracle/product/10.2.0/db_1/precomp/public -I/opt/oracle/product/10.2.0/db_1/rdbms/public -I/opt/oracle/product/10.2.0/db_1/rdbms/demo -I/opt/oracle/product/10.2.0/db_1/plsql/public -I/opt/oracle/product/10.2.0/db_1/network/public -DMAX_SEND_SIZE=2000 -c -o test.o test.cpp
the output is OK, test.o is generated. But, when I want to link the object file, with the following command,
g++ -L/opt/oracle/product/10.2.0/db_1/lib/ -lclntsh -locci -o test test.o
The linking task fails, the output is:
test.o: In function `main':
/home/xxx/occi/test.cpp:128: undefined reference to `oracle::occi::Environment::createEnvironment(oracle::occi::Environment::Mode, void*, void* (*)(void*, unsigned int), void* (*)(void*, void*, unsigned int), void (*)(void*, void*))'
/home/xxx/occi/test.cpp:170: undefined reference to `oracle::occi::Environment::terminateEnvironment(oracle::occi::Environment*)'
/home/xxx/occi/test.cpp:158: undefined reference to `oracle::occi::SQLException::~SQLException()'
/home/xxx/occi/test.cpp:158: undefined reference to `oracle::occi::SQLException::SQLException(oracle::occi::SQLException const&)'
/home/xxx/occi/test.cpp:163: undefined reference to `oracle::occi::SQLException::what() const'
/home/xxx/occi/test.cpp:158: undefined reference to `oracle::occi::SQLException::~SQLException()'
test.o:(.gcc_except_table+0xe0): undefined reference to `typeinfo for oracle::occi::SQLException'
collect2: ld returned 1 exit status
My environment resume:
Ubuntu Linux 11.04
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)
ORACLE_HOME = /opt/oracle/product/10.2.0/db_1
LD_LIBRARY_PATH = /opt/oracle/product/10.2.0/db_1/lib
Oracle version: 10.2.0
Can you help me please?, I really need to create a connection to Oracle using OCCI in Linux and I don't want to use Pro*C.
To use OCCI you need to install Instant Client provided by Oracle (have you installed?). I'm using Oracle 11.2, so my include directory path is /usr/include/oracle/11.2/client64 and my share libraries is /usr/lib/oracle/11.2/client64/lib.
I saw here
http://173.255.217.246:8000/mapnik_trac/wiki/OCCI
that 10.2 path is /usr/lib/oracle/10.2.0.4/client/include and /usr/lib/oracle/10.2.0.4/client/lib
In 11.2, I also need to link with nnz11 lib first as http://xme.im/connect-oracle-database-eclipse-linux-using-occi
This is an usefull blog describe about Instant Client http://oradim.blogspot.com/2009/08/getting-started-with-occi-linux-version.html