2

I have Ubuntu 12.01 with gcc 4.8.2 and would like to cross compile for the Vortex86DX CPU running an old 2.6.23 kernel.

I´m trying the following testing code:

#include <iostream>

int main()
{
   std::cout << "Hello world" << std::endl;
}

That is compiled using the following command line:

g++ -static-libgcc -static-libstdc++ -march=i586 test.cpp -otest586

When I run the test586 on the target architecture I´m getting this error:

$ ./test586
./teste586: symbol lookup error: ./test586: undefined symbol: _ZMSbIwSt11char_traitsIwESaIwEE4_Rep20_S_empty_rep_storageE

Any ideas of what is going on here ? This is just a small code - the real code has around 10 different libraries all written in C++ 11.


In fact the comment from Marco was right. The code still need some dynamics libraries:

$ ldd ./test586
linux-gate.so.1 =>  (0xb776b000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb75a4000)
/lib/ld-linux.so.2 (0xb776e000)

I have to avoid all dynamic library as the target system either does not have them or will have in a very old version.

Help appreciated to accomplish that.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Mendes
  • 17,489
  • 35
  • 150
  • 263
  • 1
    Looks like you are missing some dynamic library, have you tried ldd ./test586 ? – Marco Sep 25 '15 at 11:39
  • I don´t want to used dynamic libraries, that´s why I choose the `-static` flags (the target hardware does not has this libraries).... How can I avoid using these libraries ? – Mendes Sep 25 '15 at 11:41
  • 2
    Yes you are right using -static, but it looks like like your executable is still looking for something dinamically, ldd will tell you which libraries your program is trying to load and where it fails – Marco Sep 25 '15 at 11:44
  • You´re right... very good point.... Now I need help to avoid them... Please check the EDIT´ed post. – Mendes Sep 25 '15 at 11:44
  • 1
    Marco's right. We understand that you don't _want_ to link dynamically but, at present, you _are_. `ldd` will tell you what library is to blame, giving you a direction on how to continue your debugging. – Lightness Races in Orbit Sep 25 '15 at 11:45
  • If your target machine has no libraries at all, why aren't you using a baremetal toolchain? – Lightness Races in Orbit Sep 25 '15 at 11:45
  • I cannot remove the hardware SO as it has several I/O programs installed... It´s an embedded system... It is a custom build Linux based on 2.3.2 Kernel (very old...) – Mendes Sep 25 '15 at 11:46
  • If you use -static gcc should already try to link statically everything possibile, if I were you I would first try to add -static and after I would try to increment verbosity of the gcc process to see what's going on during compilation – Marco Sep 25 '15 at 12:01

1 Answers1

3

I think the problem is the order of the command switches, i.e. the linker first discovers the dependencies (libgcc, libstdc++) and only then resolves them. If you give it -static-libgcc before it found the dependency then it will simply ignore it.

the following works for me:

$ g++ -m32 -march=i586 test.cpp -o test586 -static -static-libgcc -static-libstdc++
$ ./test586 
Hello world
$ ldd test586 
not a dynamic executable
mariusm
  • 1,483
  • 1
  • 11
  • 26
  • 1
    Worked fine... Now I have another problem - Illegal instruction - it simply does not run on my Vortex86DX processor... Tried i486 and i586. – Mendes Sep 25 '15 at 13:39
  • oh, I think you will have to build the whole toolchain (binutils, gcc, glibc) for this architecture, because your Ubuntu toolchain (libc and libstdc++) is probably optimized for i686 using newer kernel headers or so. – mariusm Sep 25 '15 at 13:51
  • Yes, I agree. I´m opening a new topic for it. – Mendes Sep 25 '15 at 13:52
  • if you use file command on any binary executable on your vortex it will tell you how they have been compiled. – Marco Sep 25 '15 at 16:11
  • new topic opened at https://stackoverflow.com/questions/32783889/vortex86dx-illegal-instruction-on-c-code-toolchain-build – Thorbjørn Ravn Andersen Aug 31 '21 at 10:44