使用共享库交叉编译应用程序

Cross compiling a application using Shared libraries

我有一个在 GCC 中编译和执行的现有应用程序。 我正在交叉编译同一个应用程序,我能够交叉编译并生成共享库。但是当我尝试使用共享库链接到应用程序时,出现以下错误

arm-poky-linux-gnueabi-gcc MSO_Version.o MSO_Connect.o MSO_errors.o -o bin/MSO_Version_shared -Wall -g -Os -fPIC -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk -I../include -I../wsq -I/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk/usr/include/ -L/opt/poky/1.8/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi/usr/lib -L../lib -L/opt/poky/1.8/sysroots/i686-pokysdk-linux/lib -L/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/lib -L/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk/usr/lib -lMSO -lMSOComm -lusb
/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/ld: skipping incompatible /opt/poky/1.8/sysroots/i686-pokysdk-linux/lib/libgcc_s.so.1 when searching for libgcc_s.so.1
/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/ld: cannot find /lib/libc.so.6
/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/ld: cannot find /usr/lib/libc_nonshared.a
/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/ld: cannot find /lib/ld-linux-armhf.so.3
collect2: error: ld returned 1 exit status
make[1]: *** [MSO_Version_shared] Error 1
make[1]: Leaving directory `/home/linux/ESYS-IMP-LINUXAPP-SUF-24092012-V0.01/Internal Release/ESYS-IMP-LinuxApp-SUF-LIB-SRS-V0.01/samples'
make: *** [samples] Error 2

如果我使用静态库进行编译,则会生成可执行文件。下面是我的 makefile

export CROSS_COMPILE

CC = $(CROSS_COMPILE)gcc

ifeq ($(DEBUG),yes)
CFLAGS = -Wall -g -Os -fPIC -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk


else
CFLAGS = -Wall -Os -fPIC -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk


endif

LIB_USB = -lusb
LIB_SDL = -lSDL -lSDL_ttf

LIBPATH += -L/opt/poky/1.8/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi/usr/lib
LIBPATH += -L../lib
LIBPATH += -L/opt/poky/1.8/sysroots/i686-pokysdk-linux/lib
LIBPATH += -L/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/lib
LIBPATH += -L/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk/usr/lib
LIB_STATIC_SAGEM = ../lib/libMSO.a ../lib/libMSOComm.a
LIB_SAGEM = -lMSO -lMSOComm


SRCINCLUDE += -I../include -I../wsq
SRCINCLUDE += -I/home/fsl-release-bsp/build_image/tmp/sysroots/imx6ulevk/usr/include/

EXEC_PATH = bin
EXEC_STATIC = MSO_Version #MSO_TestBio MSO_TestThread
EXEC_SHARED = MSO_Version_shared #MSO_TestBio_shared

MSO_Version_SRC = MSO_Version.c MSO_Connect.c MSO_errors.c
MSO_Version_OBJ = $(MSO_Version_SRC:.c=.o)

.PHONY: all
all: $(EXEC_STATIC) $(EXEC_SHARED)

%.o: %.c
        $(CC) -c $(CFLAGS) $(SRCINCLUDE) $< -o $@

.PHONY: MSO_Version MSO_Version_shared
MSO_Version: $(MSO_Version_OBJ)
        $(CC) $(MSO_Version_OBJ) -o $(EXEC_PATH)/MSO_Version $(CFLAGS) $(SRCINCLUDE) $(LIB_STATIC_SAGEM) $(LIB_USB)
MSO_Version_shared: $(MSO_Version_OBJ)
        $(CC) $(MSO_Version_OBJ) -o $(EXEC_PATH)/MSO_Version_shared $(CFLAGS) $(SRCINCLUDE) $(LIBPATH) $(LIB_SAGEM) $(LIB_USB)

你可以看到我正在生成两个可执行文件,一个是静态库,另一个是共享库。 我使用的是 poky 1.8,内核是 2.6.38。使用 NXP IMX6ULEVK 板。 谁能告诉我哪里错了

您将架构指定为 armv7-a:

-march=armv7-a

但 link 面向 i686 库:

-L/opt/poky/1.8/sysroots/i686-pokysdk-linux/lib -L/opt/poky/1.8/sysroots/i686-pokysdk-linux/usr/lib