我已经在Ubuntu中使用CodeSourcery Lite 4.7.3环境进行了交叉编译已有一段时间了,并且正在转换到基于Windows的环境。我使用相同版本的CodeSourcery构建,并使用“GNU ARM Eclipse Build Tools”。出于某种原因,当我在Windows系统中构建我在Ubuntu中的项目时,当我将它们放在目标上时,它正在ARM9 /目录中搜索我构建的自定义共享库。
为了帮助理解运行时错误,我正在编译的是一个需要共享库的动态加载库。 “targetapp”是预编译的,当我在windows环境中交叉编译“dynamic_module”时,我只会得到这个错误(是的,我在windows和linux中使用相同的编译命令,我只是更新了eclipse项目中的编译器路径。)
[root@(none) root]# ./targetapp | grep dynamic_module
Error opening dll '/home/root/dynamic_module': ARM9/libSharedLibrary.so: cannot open shared object file: No such file or directory
目标是一个带有busybox的精简版定制的vanilla linux系统。我只是无法理解为什么这个相对路径被嵌入我在Windows中的编译库中,而不是在Ubuntu中。
以下是Ubuntu交叉编译器和Windows交叉编译器的编译器版本输出。
Ubuntu G ++ -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabi-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure
-v
--with-pkgversion='Ubuntu/Linaro 4.7.3-12ubuntu1'
--with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++
--prefix=/usr
--program-suffix=-4.7
--enable-shared
--enable-linker-build-id
--libexecdir=/usr/lib
--without-included-gettext
--enable-threads=posix
--with-gxx-include-dir=/usr/arm-linux-gnueabi/include/c++/4.7.3
--libdir=/usr/lib
--enable-nls
--with-sysroot=/
--enable-clocale=gnu
--enable-libstdcxx-debug
--enable-gnu-unique-object
--disable-libmudflap
--disable-libitm
--enable-plugin
--with-system-zlib
--enable-objc-gc
--with-cloog
--enable-cloog-backend=ppl
--disable-cloog-version-check
--disable-ppl-version-check
--enable-multiarch
--enable-multilib
--disable-sjlj-exceptions
--with-arch=armv5t
--with-float=soft
--disable-werror
--enable-checking=release
--build=i686-linux-gnu
--host=i686-linux-gnu
--target=arm-linux-gnueabi
--program-prefix=arm-linux-gnueabi-
--includedir=/usr/arm-linux-gnueabi/include
Thread model: posix
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-12ubuntu1)
Windows G ++ -v
Using built-in specs.
COLLECT_GCC=arm-none-linux-gnueabi-g++.exe
COLLECT_LTO_WRAPPER=c:/arm_cross/bin/../libexec/gcc/arm-none-linux-gnueabi/4.7.3/lto-wrapper.exe
Target: arm-none-linux-gnueabi
Configured with: /scratch/jbrown/2013.05-arm-linux-release/src/gcc-4.7-2013.05/configure
--build=i686-pc-linux-gnu
--host=i686-mingw32
--target=arm-none-linux-gnueabi
--enable-threads
--disable-libmudflap
--disable-libssp
--disable-libstdcxx-pch
--enable-extra-sgxxlite-multilibs
--with-arch=armv5te
--with-gnu-as
--with-gnu-ld
--with-specs='%{save-temps: -fverbose-asm}
%{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables}
-D__CS_SOURCERYGXX_MAJ__=2013
-D__CS_SOURCERYGXX_MIN__=5
-D__CS_SOURCERYGXX_REV__=24
%{O2:%{!fno-remove-local-statics: -fremove-local-statics}}
%{O*:%{O|O0|O1|O2|Os:;:%{!fno-remove-local-statics: -fremove-local-statics}}}'
--enable-languages=c,c++
--enable-shared
--enable-lto
--enable-symvers=gnu
--enable-__cxa_atexit
--with-pkgversion='Sourcery CodeBench Lite 2013.05-24'
--with-bugurl=https://sourcery.mentor.com/GNUToolchain/
--disable-nls
--prefix=/opt/codesourcery
--with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc
--with-build-sysroot=/scratch/jbrown/2013.05-arm-linux-release/install/host-i686-mingw32/arm-none-linux-gnueabi/libc
--with-libiconv-prefix=/scratch/jbrown/2013.05-arm-linux-release/obj/pkg-2013.05-24-arm-none-linux-gnueabi/arm-2013.05-24-arm-none-linux-gnueabi.extras/host-libs-i686-mingw32/usr
--with-gmp=/scratch/jbrown/2013.05-arm-linux-release/obj/pkg-2013.05-24-arm-none-linux-gnueabi/arm-2013.05-24-arm-none-linux-gnueabi.extras/host-libs-i686-mingw32/usr
--with-mpfr=/scratch/jbrown/2013.05-arm-linux-release/obj/pkg-2013.05-24-arm-none-linux-gnueabi/arm-2013.05-24-arm-none-linux-gnueabi.extras/host-libs-i686-mingw32/usr
--with-mpc=/scratch/jbrown/2013.05-arm-linux-release/obj/pkg-2013.05-24-arm-none-linux-gnueabi/arm-2013.05-24-arm-none-linux-gnueabi.extras/host-libs-i686-mingw32/usr
--with-ppl=/scratch/jbrown/2013.05-arm-linux-release/obj/pkg-2013.05-24-arm-none-linux-gnueabi/arm-2013.05-24-arm-none-linux-gnueabi.extras/host-libs-i686-mingw32/usr
--with-host-libstdcxx='-static-libgcc
-Wl,-Bstatic,-lstdc++,-Bdynamic
-lm'
--with-cloog=/scratch/jbrown/2013.05-arm-linux-release/obj/pkg-2013.05-24-arm-none-linux-gnueabi/arm-2013.05-24-arm-none-linux-gnueabi.extras/host-libs-i686-mingw32/usr
--with-libelf=/scratch/jbrown/2013.05-arm-linux-release/obj/pkg-2013.05-24-arm-none-linux-gnueabi/arm-2013.05-24-arm-none-linux-gnueabi.extras/host-libs-i686-mingw32/usr
--disable-libgomp
--disable-libitm
--enable-poison-system-directories
--with-build-time-tools=/scratch/jbrown/2013.05-arm-linux-release/obj/tools-i686-pc-linux-gnu-2013.05-24-arm-none-linux-gnueabi-i686-mingw32/arm-none-linux-gnueabi/bin
--with-build-time-tools=/scratch/jbrown/2013.05-arm-linux-release/obj/tools-i686-pc-linux-gnu-2013.05-24-arm-none-linux-gnueabi-i686-mingw32/arm-none-linux-gnueabi/bin
Thread model: posix
gcc version 4.7.3 (Sourcery CodeBench Lite 2013.05-24)
修改
我一直在努力解决这个问题。最初出现的问题是在Windows中使用CMake进行编译,CMake脚本是由其他人构建的,但我拥有“动态模块”和“libSharedLibrary.so”。已知“libSharedLibrary.so”可以在体系结构上工作,并加载到“/ usr / lib”中以便在目标上进行共享链接。我首先使用标准makefile在Ubuntu下编译“dynamic_module”,然后在Windows中使用CMake,在Windows中使用标准makefile,每个都使用相同的结果。 CMake脚本最初引用了“ARM9”路径,我怀疑它在我的环境变量或我的交叉环境的其他组件中搞砸了。今天早上我将所有“ARM9”引用更改为“ARM7”,并且仍然将相同的相对路径转储到“dynamic_module”中。我可以使用以下命令检查链接路径...
C:\Raw_SVN\dynamic_module>"C:\ARM_Cross\bin\arm-none-linux-gnueabi-readelf.exe" -a ARM7\dynamic_module | findstr "Shared l
ibrary:"
Type: DYN (Shared object file)
0x00000001 (NEEDED) Shared library: [librt.so.1]
0x00000001 (NEEDED) Shared library: [libarmadillo.so.4]
0x00000001 (NEEDED) Shared library: [libpthread.so.0]
0x00000001 (NEEDED) Shared library: [libboost_serialization.so.1.55.0]
0x00000001 (NEEDED) Shared library: [libboost_date_time.so.1.55.0]
0x00000001 (NEEDED) Shared library: [ARM9/libSharedLibrary.so]
0x00000001 (NEEDED) Shared library: [libstdc++.so.6]
0x00000001 (NEEDED) Shared library: [libm.so.6]
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.6]
我还获得了如下捕获的详细链接器命令....
C:/ARM_Cross/bin/arm-none-linux-gnueabi-g++.exe
-v
-fPIC
-isystem C:/ARM_Cross/arm-none-linux-gnueabi/libc/include
-isystem C:/ARM_Cross/arm-none-linux-gnueabi/usr/include
-LC:/ARM_Cross/arm-none-linux-gnueabi/libc/usr/lib
-LC:/ARM_Cross/arm-none-linux-gnueabi/usr/lib
-shared
-Wl,-soname,ARM7/libDynamic_Module.so
-o
ARM7/libDynamic_Module.so
"CMakeFiles/Dynamic_Module.dir/Dynamic_Module.cpp.o"
"CMakeFiles/Dynamic_Module.dir/InternalComponents/comp1.cpp.o"
"CMakeFiles/Dynamic_Module.dir/InternalComponents/comp2.cpp.o"
"CMakeFiles/Dynamic_Module.dir/InternalComponents/comp3.cpp.o"
"CMakeFiles/Dynamic_Module.dir/InternalComponents/comp4.cpp.o"
"CMakeFiles/Dynamic_Module.dir/InternalComponents/comp5.cpp.o"
-llapack
-lf2c
-lblas
-lrt
-larmadillo
-lpthread
-lexpat
-lboost_serialization
-lboost_date_time
-lSharedLibrary
Using built-in specs.
COLLECT_GCC=C:/ARM_Cross/bin/arm-none-linux-gnueabi-g++.exe
COLLECT_LTO_WRAPPER=c:/arm_cross/bin/../libexec/gcc/arm-none-linux-gnueabi/4.5.2/lto-wrapper.exe
Target: arm-none-linux-gnueabi
Configured with: /scratch/janisjo/arm-linux-lite/src/gcc-4.5-2011.03/configure
--build=i686-pc-linux-gnu
--host=i686-mingw32
--target=arm-none-linux-gnueabi
--enable-threads
--disable-libmudflap
--disable-libssp
--disable-libstdcxx-pch
--enable-extra-sgxxlite-multilibs
--with-arch=armv5te
--with-gnu-as
--with-gnu-ld
--with-specs='%{save-temps: -fverbose-asm}
%{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables}
-D__CS_SOURCERYGXX_MAJ__=2011
-D__CS_SOURCERYGXX_MIN__=3
-D__CS_SOURCERYGXX_REV__=41
%{O2:%{!fno-remove-local-statics: -fremove-local-statics}}
%{O*:%{O|O0|O1|O2|Os:;:%{!fno-remove-local-statics: -fremove-local-statics}}}'
--enable-languages=c,c++
--enable-shared
--enable-lto
--enable-symvers=gnu
--enable-__cxa_atexit
--with-pkgversion='Sourcery
G++ Lite 2011.03-41'
--with-bugurl=https://support.codesourcery.com/GNUToolchain/
--disable-nls
--prefix=/opt/codesourcery
--with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc
--with-build-sysroot=/scratch/janisjo/arm-linux-lite/install/host-i686-mingw32/arm-none-linux-gnueabi/libc
--with-libiconv-prefix=/scratch/janisjo/arm-linux-lite/obj/host-libs-2011.03-41-arm-none-linux-gnueabi-i686-mingw32/usr
--with-gmp=/scratch/janisjo/arm-linux-lite/obj/host-libs-2011.03-41-arm-none-linux-gnueabi-i686-mingw32/usr
--with-mpfr=/scratch/janisjo/arm-linux-lite/obj/host-libs-2011.03-41-arm-none-linux-gnueabi-i686-mingw32/usr
--with-mpc=/scratch/janisjo/arm-linux-lite/obj/host-libs-2011.03-41-arm-none-linux-gnueabi-i686-mingw32/usr
--with-ppl=/scratch/janisjo/arm-linux-lite/obj/host-libs-2011.03-41-arm-none-linux-gnueabi-i686-mingw32/usr
--with-host-libstdcxx='-static-libgcc
-Wl,-Bstatic,-lstdc++,-Bdynamic
-lm'
--with-cloog=/scratch/janisjo/arm-linux-lite/obj/host-libs-2011.03-41-arm-none-linux-gnueabi-i686-mingw32/usr
--with-libelf=/scratch/janisjo/arm-linux-lite/obj/host-libs-2011.03-41-arm-none-linux-gnueabi-i686-mingw32/usr
--disable-libgomp
--enable-poison-system-directories
--with-build-time-tools=/scratch/janisjo/arm-linux-lite/obj/tools-i686-pc-linux-gnu-2011.03-41-arm-none-linux-gnueabi-i686-mingw32/arm-none-linux-gnueabi/bin
--with-build-time-tools=/scratch/janisjo/arm-linux-lite/obj/tools-i686-pc-linux-gnu-2011.03-41-arm-none-linux-gnueabi-i686-mingw32/arm-none-linux-gnueabi/bin
Thread model: posix
gcc version 4.5.2 (Sourcery G++ Lite 2011.03-41)
COMPILER_PATH=c:/arm_cross/bin/../libexec/gcc/arm-none-linux-gnueabi/4.5.2/;c:/arm_cross/bin/../libexec/gcc/;c:/arm_cross/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/../../../../arm-none-linux-gnueabi/bin/
LIBRARY_PATH=c:/arm_cross/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/;c:/arm_cross/bin/../lib/gcc/;c:/arm_cross/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/../../../../arm-none-linux-gnueabi/lib/;c:/arm_cross/bin/../arm-none-linux-gnueabi/libc/lib/;c:/arm_cross/bin/../arm-none-linux-gnueabi/libc/usr/lib/
COLLECT_GCC_OPTIONS='-v'
'-fPIC'
'-isystem'
'C:/ARM_Cross/arm-none-linux-gnueabi/libc/include'
'-isystem'
'C:/ARM_Cross/arm-none-linux-gnueabi/usr/include'
'-LC:/ARM_Cross/arm-none-linux-gnueabi/libc/usr/lib'
'-LC:/ARM_Cross/arm-none-linux-gnueabi/usr/lib'
'-shared'
'-o'
'ARM7/libDynamic_Module.so'
'-shared-libgcc'
'-march=armv5te'
'-funwind-tables'
'-D__CS_SOURCERYGXX_MAJ__=2011'
'-D__CS_SOURCERYGXX_MIN__=3'
'-D__CS_SOURCERYGXX_REV__=41'
c:/arm_cross/bin/../libexec/gcc/arm-none-linux-gnueabi/4.5.2/collect2.exe
--sysroot=c:\arm_cross\bin\../arm-none-linux-gnueabi/libc
--eh-frame-hdr
-shared
-dynamic-linker /lib/ld-linux.so.3
-X
-m armelf_linux_eabi
-o ARM7/libDynamic_Module.so c:/arm_cross/bin/../arm-none-linux-gnueabi/libc/usr/lib/crti.o c:/arm_cross/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/crtbeginS.o
-LC:/ARM_Cross/arm-none-linux-gnueabi/libc/usr/lib
-LC:/ARM_Cross/arm-none-linux-gnueabi/usr/lib
-Lc:/arm_cross/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2
-Lc:/arm_cross/bin/../lib/gcc
-Lc:/arm_cross/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/../../../../arm-none-linux-gnueabi/lib
-Lc:/arm_cross/bin/../arm-none-linux-gnueabi/libc/lib
-Lc:/arm_cross/bin/../arm-none-linux-gnueabi/libc/usr/lib
-soname
ARM7/libDynamic_Module.so
CMakeFiles/Dynamic_Module.dir/Dynamic_Module.cpp.o
CMakeFiles/Dynamic_Module.dir/InternalComponents/comp1.cpp.o
CMakeFiles/Dynamic_Module.dir/InternalComponents/comp2.cpp.o
CMakeFiles/Dynamic_Module.dir/InternalComponents/comp3.cpp.o
CMakeFiles/Dynamic_Module.dir/InternalComponents/comp4.cpp.o
CMakeFiles/Dynamic_Module.dir/InternalComponents/comp5.cpp.o
-llapack
-lf2c
-lblas
-lrt
-larmadillo
-lpthread
-lexpat
-lboost_serialization
-lboost_date_time
-lSharedLibrary
-lstdc++
-lm
-lgcc_s
-lc
-lgcc_s
c:/arm_cross/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/crtendS.o
c:/arm_cross/bin/../arm-none-linux-gnueabi/libc/usr/lib/crtn.o
make[2]: Leaving directory 'C:/Raw_SVN/Dynamic_Module'
使用修改后的环境(参考ARM7的cmake配置),我无处可寻找到“ARM9”的神秘链接。如评论所述,问题可能是我的libSharedLibrary.so是在linux中交叉编译的。我现在要在Windows中对它进行交叉编译,看看是否有任何变化。
所以,充分利用它,ARM引用来自我的环境中的某个地方,即使它不在链接器命令中,它也会被拉进去。还有什么其他信息可以告诉链接器这样做,鉴于上述参考文件中发出的命令?
更新
很抱歉花了这么长时间来更新这个问题,正如标记答案中所提到的那样,在下面的评论中,我能够确定一个解决方案。
在stackoverflow上找到的Similar SONAME linking problems帮助我将问题与我在CMAKE文件中所需的问题隔离开来。在编译libSharedLibrary.so库时,我在CMakeLists.txt中添加了以下内容作为最后一行。
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY NO_SONAME 1)
如果我没有弄错,这可以防止SONAME嵌入到库中(我相信它包含了我神秘的相对ARM9参考)。如果没有libSharedLibrary.so中的SONAME引用,则链接到dynamic_module的libDynamicLibrary.so将使用提供的名称而不是它在其中编译的SONAME。
再次感谢您的所有帮助,并再次感谢user1034749让我更接近解决方案。
答案 0 :(得分:0)
我看着你的链接命令,我想这里有问题:
-Wl,-soname,ARM7 / libDynamic_Module.so
如果链接共享库有这样的标志,然后链接main 程序与这样的库,然后:
evgeniy @ localhost / tmp / test $ gcc -shared -o libfoo.so test.o -Wl,-soname,ARM7 / libDynamic_Module.so evgeniy @ localhost / tmp / test $ gcc -L
pwd
main.c -lfoo evgeniy @ localhost / tmp / test $ ./a.out ./a.out:加载共享库时出错: ARM7 / libDynamic_Module.so:无法打开共享对象文件:没有这样的 文件或目录
你几乎完全是你上面描述的问题, 为什么ARM9而不是ARM7,它可能只能解决你的问题, 可以访问文件系统。