How do I cross compile a static library built on the target with static linkage using c++11 utilities

1.1k views Asked by At

**Edit: Found my problem. As explained by the following answer, I was not actually doing any linking when making the static library. Instead, I made a shared library and linked libstdc++ statically.

Compile a static library link with standard library (static)**

I am trying to create a method to use c++11 on an ancient arm platform running kernel (2.6.37). Unfortunately the latest cross compile our BSP contains is GCC 4.5.3, which does not support all the c++11 utilites we need.

Initially I tried to use old versions of crosstool-ng to build a cross compiler, but the older versions were too broken. The newer versions did not support the 2.6.37 kernel. I was able to complete one build, however the g++ binary was not built, making the whole endeavor useless (I did check that c++ was enabled in the menuconfig).

Thus my last option was to build gcc natively at version 4.9.4 and create a statically linked library to have my gcc 4.5.3 cross compiler link against. This seems to work for the most part. I create my library on the target with the following:

g++ -std=c++11 --static -c main2.cpp
ar -cvq libmain2.a main2.o

I then copy over the files and try build on the host machine with gcc 4.5.3 and get the following:

arm-angstrom-linux-gnueabi-g++ simple.cpp -lmain2 -L.

(I cleaned up some of the output)

undefined reference to `std::_Hash_bytes(void const*, unsigned int, unsigned int)' undefined reference to std::__throw_regex_error(std::regex_constants::error_type)'

However, when I use nm, I get the following:

    $ arm-angstrom-linux-gnueabi-nm libmain2.a | grep Hash_bytes
     U _ZSt11_Hash_bytesPKvjj
     U _ZSt11_Hash_bytesPKvjj
    $ arm-angstrom-linux-gnueabi-nm libmain2.a | grep throw_regex
     U _ZSt19__throw_regex_errorNSt15regex_constants10error_typeE
     U _ZSt19__throw_regex_errorNSt15regex_constants10error_typeE

Does anyone know what the heck is going on? Unfortunately we need to be able to use our cross compiler on the host system for most work, but we are also needing to integrate this specific library which uses c++11.

Also note that if I take out the regex and hash functionality from my code but leave other c++11 concepts like nullptr, type inference, delegation etc, the code compiles and runs on the target fine.

Edit: Okay, so after a little more investigation, it looks like the functions _Hash_bytes and __throw_regex_error are not being statically linked into the static library. I guess I need to know why this is the case in order to fix the issue.

0

There are 0 answers