开发者

Cross compile with another library

How to compile with another set of libraries. When I compile on i686 Fedora 13 computer, it works fine. However, when I take the executable (via thumbdrive) and try to run it on another i386 machine, I get the following error message.

/usr/lib/libstdc++.so.6: version ‘GLIBCXX_3.4.9’ not found (required by ./Recorder)

Okay, so I have to compile using the i386 libraries so it's compatible. However, the i368 machine doesn't have a compiler. So I have to find a way to cross-compile with using the i386 machine libraries. So I copy all of i386 directory tree into the i686 machine and try to use -nostdlib and point all libraries to use the i386, and I've played with settings all day long and get no where.

I went ahead and tried to make a small program as a test and see if I could get it to cross compile first. Still no luck.

/// \file main.cpp
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>  
#include <iostream>
int main()
{
   std::cout << "Testing!" << std::endl;
   #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
      printf("POSIX Thread Priority Scheduling supported\n");
   #else
      #warning "POSIX Thread Priorit开发者_运维百科y Scheduling NOT supported."
   #endif
   #ifdef _POSIX_THREAD_PRIO_PROTECT
      printf("POSIX Thread Priority Ceiling supported");
   #else
      #warning "POSIX Thread Priority Ceiling NOT supported"
   #endif
   #ifdef _POSIX_THREAD_PRIO_INHERIT
      printf("POSIX Thread Priority Ceiling supported");
   #else
      #warning "POSIX Thread Priority Ceiling NOT supported"
   #endif
   return 0;
}

I compile the program with this command.

g++ -O3 -pedantic -Wextra -Wall -g -c /home/dmiller3/Experiments/Test2/main.cpp -o obj/Debug/main.o

I get the error when linking.

g++ -L../../TargetLibraries/cw_1901-glibc_std-standard-dist/lib  -o bin/Debug/Test2 obj/Debug/main.o   -nostdlib ../../TargetLibraries/cw_1901-glibc_std-standard-dist/lib/libpthread-2.5.so ../../TargetLibraries/cw_1901-glibc_std-standard-dist/lib/libc-2.5.so 
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to

00000000080482a0 obj/Debug/main.o: In function __static_initialization_and_destruction_0': /usr/lib/gcc/i686-redhat-linux/4.4.4/../../../../include/c++/4.4.4/iostream:72: undefined reference to std::ios_base::Init::Init()' ...Lot more errors...

How do we compile with another library? Why do I have to explicity point to the libc library (shouldn't this be automatic)? I've done some searching on the internet, and some articles state that I'm missing a crt0.o file, however I can't find this file on the i386 directory tree.


/usr/lib/libstdc++.so.6: version ‘GLIBCXX_3.4.9’ not found (required by ./Recorder)

The libstdc++ on the machine you are trying to run is older then the one you compile on, that is why it is complaining


GCC actually hard-codes some paths in it's source code. Your best bet is to find out which version of glibc is installed on your target system and then download the compiler for that system.

Can you describe your system in more detail? Is it running Linux? Which kernel and glibc/ulibc version?

What I had to do in a similar situation is to specify the include and link paths when compiling, so you end up having something like this:

<path to g++>/g++ -I<includes for my version system libs> -Wl,--rpath-link <custom libs path> -L <same custom libs path>

Some notes:

  • You have to be careful of the precedence of each include and lib path if you have same library in different locations.
  • You HAVE to use a cross-compiled toolchain, even if it's from x86 to x86, since the cross-compile process will eliminate many of hard-coded paths and other dependencies that GCC has.
  • You'll often have to provide all the libs from your target arch to compile against.
  • Take a look at Linux From Scratch http://trac.cross-lfs.org/ for an in-depth discussion of cross-compiling
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜