English 中文(简体)
Cannot find /lib/libc.so.6
原标题:

I m cross-compiling an application, but linking blows up with an error that it

"cannot find /lib/libc.so.6".

The libc.so.6 that it should be using is the one that sits at /home/work/worldcom/filesys/lib/libc.so.6. What have I got wrong here?

linking libobj.so
arm-none-linux-gnueabi-g++ obj1.o obj2.o obj2.o  -o libobj.so -L/home/work/worldcom/filesys/usr -Wl,-O1 -Wl,-z,defs -Wl,--enable-new-dtags -Wl,--sort-common -Wl,--as-needed -Wl,--hash-style=both -L/home/work/worldcom/filesys -L/home/work/worldcom/filesys/lib -L/home/work/worldcom/filesys/usr/lib -lcurl -shared
/home/lishevita/armv5tel/arm-2009q3/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: skipping incompatible /lib/libc.so.6 when searching for /lib/libc.so.6
/home/lishevita/armv5tel/arm-2009q3/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: cannot find /lib/libc.so.6
collect2: ld returned 1 exit status<br />
make: *** [libobj.so] Error 1<br />

My makefile is handwritten (i.e. not generated by Autotools). In order to avoid a blanket "your Makefile is broken" here are some details from the makefile that might help clarify.

CROSS_COMPILE = arm-none-linux-gnueabi-  
SYSROOT = /home/work/worldcom/filesys/  
DESTDIR = /home/work/worldcom/filesys/  

RELEASE_CXXFLAGS = -Os  
DEBUG_CXXFLAGS = -O0 -gstabs  
PKGCONFIG=`env ROOT=/home/work/worldcom/filesys cross-pkg-config glib-2.0 libcurl --cflags`  

CC = $(CROSS_COMPILE)gcc  
CXX = $(CROSS_COMPILE)g++  
LD = $(CROSS_COMPILE)ld  
AR = $(CROSS_COMPILE)ar  

LDFLAGS = -Wl,-O1 -Wl,-z,defs -Wl,--enable-new-dtags -Wl,--sort-common -Wl,--as-needed -Wl,--hash-style=both -L$(SYSROOT) -L$(SYSROOT)lib -L$(SYSROOT)usr -L$(SYSROOT)usr/lib -lcurl  

libobj.so: $(LIBOBJ_OBJS)  
        @echo linking $@  
        $(CXX) $^ -o $@ $(LDFLAGS) -shared $(PKG_LIBS) 

Of course there is also a definition and target for the LIBOBJ_OBJS but those are irrelevant to the problem.

最佳回答

You didn t indicate what gcc version you are using, but if it is a recent enough one (4.0.0 and above me thinks) you should try adding the --sysroot flag to g++/ld. Point it to $SYSROOT as defined in your Makefile. For example:

--sysroot=$(SYSROOT)

Assuming recent enough gcc version, it will work.

问题回答

I just went through the same issue; adding --sysroot=/rootfs/prefix helped me get closer to the real issue. I got it fixed by installing package libstdc++-dev in target.

Have you not considered that possibly the LIBPATH is set and hard-coded to look for the /lib/libc.so.6 and therefore the /lib path?

Have you tried to set the environment variable like this on the command line, prior to issuing make when cross-compiling:

LIBPATH=/home/work/worldcom/filesys/lib

In your specific case, as you have mentioned in the tag cross-compiling , it might be worth it to remove any references to /lib to wholly force the linker to look in your own home directory instead as not to interfere with the cross-compile process.

The other possibility is that the gcc compiler when it was built for your environment, the configuration during the building of the compiler from source, was specified to point to the /lib path.

Hope this helps, Best regards, Tom.





相关问题
Where are the symbols etext, edata and end defined?

This is a code from Linux man page: #include <stdio.h> #include <stdlib.h> extern char etext, edata, end; int main() { printf("First address past: "); printf(" program text (...

Problem statically linking MFC libraries

I have a Visual Studio 6 workspace I m trying to convert to a Visual Studio 2008 solution. The output of said solution is a .dll. It has to be a .dll and it needs to statically link MFC as I can t ...

Create a shared lib using another shared lib

I have a shared library "libwiston.so". I am using this to create another shared library called "libAnimation.so", which will be used by another project. Now, the second library "libAnimation.so" can ...

C++ linker - Lack of duplicate symbols

Why does the following code not give me a duplicate symbol linker error for Impl? I ran across this problem in some code I inherited and I m recreating a shorter version here for simplicity. I have ...

problem w/ linking static function g++

I am trying to build a small program and I have my own library libfoo. I have a camera class that is calling a static function from my Vector3 class (i.e. crossProduct). My camera class and Vector3 ...

Extract statically linked libraries from an executable

I m not sure if this is even possible, but given an executable file (foo.exe), with has many libraries which has been linked statically. Is there any software that extract from this file the .lib ( ...

热门标签