I have been cross-compiling with a CodeSourcery Lite 4.7.3 environment in Ubuntu for quite some time, and am transitioning to a windows based environment. I am building with the same version of CodeSourcery, and using "GNU ARM Eclipse Build Tools." For some reason, when I build projects that I had in Ubuntu in my windows system, when I put them on the target, it is searching an ARM9/ directory for a custom shared library that I have constructed.
To help understand the runtime error, what I am compiling is a dynamically loaded library that requires a shared library. The "targetapp" is pre-compiled, and I only get this error when I cross-compile the "dynamic_module" in the windows environment (yes, I am using the same compiling commands in windows, and linux, I just update the cross-compiler paths in the eclipse project).
[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
The target is a stripped down, custom built vanilla linux system with busybox. I just can't make sense of why this relative path is being embedded in my compiled library in Windows, but not in Ubuntu.
Below is the compiler version output for the Ubuntu cross-compiler, and the Windows cross-compiler.
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)
EDIT
I have continued struggling with this. It originally came up as an issue with compiling using CMake in windows, the CMake scripts were constructed by someone else, but I own the "dynamic module" and "libSharedLibrary.so." The "libSharedLibrary.so" is known to work on the architecture, and is loaded into "/usr/lib" for shared linking on the target. I had first compiled "dynamic_module" under Ubuntu just using standard makefiles, then tried with CMake in Windows, and standard makefiles in Windows, each with the same result. The CMake scripts originally referenced the "ARM9" path, and I suspected that it messed up something in my environment variables, or potentially other components of my cross environment. This morning I changed all "ARM9" references to "ARM7", and still have the same relative path being dumped into "dynamic_module." I can inspect the link path with the following command...
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]
I also got the verbose linker command captured as the following....
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'
Nowhere can I find this mysterious link to "ARM9" with the modified environment (cmake configurations referencing ARM7). As commented, the problem may be that my libSharedLibrary.so was cross-compiled in linux. I am now going to cross-compile it in Windows, and see if anything changes.
So, playing with it enough, the ARM reference is coming from somewhere in my environment, even though it isn't in the linker command, it is getting pulled in. What other information could be telling the linker to do this, given the command being issued in the above reference?
UPDATE
Sorry it took so long to update this question, as mentioned in the flagged answer, and in my comments below, I was able to determine a solution.
Similar SONAME linking problems found on stackoverflow helped me to isolate the issue to what I needed in my CMAKE file. I added the following as the last line in my CMakeLists.txt when compiling the libSharedLibrary.so library.
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY NO_SONAME 1)
If I am not mistaken, this prevents the SONAME from being embedded into the library (which I believe contained my mysterious relative ARM9 reference). Without the SONAME reference in the libSharedLibrary.so, then the libDynamicLibrary.so linking into the dynamic_module would use the provided name rather than the SONAME it found compiled in.
Thanks again for all of your help, and another bump to user1034749 for getting me closer to a solution.
I looking at your link command, and I suppose problem here:
-Wl,-soname,ARM7/libDynamic_Module.so
if link shared library with such flags, and then link main program with such library, then:
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: error while loading shared libraries: ARM7/libDynamic_Module.so: cannot open shared object file: No such file or directory
you almost exactly the problem as you described above, why ARM9 instead of ARM7, it is possible only resolve on your side, with access to filesystem.