ARM交叉编译应用程序时链接SDL发生错误

3

我正在尝试为ARM处理器交叉编译简单的SDL应用程序。

我使用的是摩托罗拉A1200,配备了Intel Xscale PX27x rev 7(带有iwmmxt扩展)处理器,并使用修改后的交叉编译工具链,例如gcc:

arm-linux-gnu-g++ --version
arm-linux-gnu-g++ (GCC) 3.3.6
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ arm-linux-gnu-g++ -v
Reading specs from /opt/crosstool/bin/../lib/gcc-lib/arm-linux-gnu/3.3.6/specs
Configured with: /home/nuso2f/mkezx-0.9.20/build/host/crosstool-ezx/configure --host=i486-host_linux-gnu --target=arm-linux-gnu --prefix=/home/nuso2f/mkezx-0.9.20/build/host/crosstool-ezx.fake_root --with-cpu=iwmmxt --enable-cxx-flags=-mcpu=iwmmxt --with-float=soft --with-headers=/home/nuso2f/mkezx-0.9.20/build/host/crosstool-ezx.fake_root/arm-linux-gnu/include --with-local-prefix=/home/nuso2f/mkezx-0.9.20/build/host/crosstool-ezx.fake_root/arm-linux-gnu --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++,f77 --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 3.3.6

坦白说,这个编译器不是我编译的,所以上面提到的路径是无效的。 还有一些库文件目录,如libSDL、libSDL_mixer等等。我已经检查过所有这些库文件是否适用于ARM。
$ file *.so*
ELF 32-biarm-linux-gnu-g++ ttt.cpp -o ttt.arm -I/usr/include -L`pwd`

所以它们是一样的。

然后我把libSDL-1.2.so复制到了项目目录中。检查了该库中的符号。

readelf --syms libSDL-1.2.so

一切都好。

然后尝试编译: (请注意,$CXX和其他相应的环境变量,如$LD、$AR等,已设置为交叉编译工具链的位置)

$ arm-linux-gnu-g++ ttt.cpp -o ttt.arm -I/usr/include -L`pwd`
/tmp/ccXpDX0V.o(.text+0xb0): In function `main':
: undefined reference to `SDL_Init'
/tmp/ccXpDX0V.o(.text+0xd8): In function `main':
: undefined reference to `SDL_SetVideoMode'
/tmp/ccXpDX0V.o(.text+0x170): In function `main':
: undefined reference to `SDL_UpperBlit'
/tmp/ccXpDX0V.o(.text+0x17c): In function `main':
: undefined reference to `SDL_Flip'
/tmp/ccXpDX0V.o(.text+0x1c8): In function `main':
: undefined reference to `SDL_PollEvent'
/tmp/ccXpDX0V.o(.text+0x2d8): In function `$a':
: undefined reference to `SDL_FillRect'
/tmp/ccXpDX0V.o(.text+0x334): In function `myabort(char const*)':
: undefined reference to `SDL_GetError'
/tmp/ccXpDX0V.o(.text+0x380): In function `my_img_load(char*)':
: undefined reference to `SDL_RWFromFile'
/tmp/ccXpDX0V.o(.text+0x390): In function `my_img_load(char*)':
: undefined reference to `SDL_LoadBMP_RW'
/tmp/ccXpDX0V.o(.text+0x3b8): In function `my_img_load(char*)':
: undefined reference to `SDL_DisplayFormatAlpha'
/tmp/ccXpDX0V.o(.text+0x3c8): In function `my_img_load(char*)':
: undefined reference to `SDL_FreeSurface'
collect2: ld returned 1 exit statust LSB shared object, ARM, version 1, dynamically linked, stripped

尽管我尝试像这样编译
arm-linux-gnu-g++ ttt.cpp -o ttt.arm -I/usr/include ./libSDL-1.2.so

它可以编译和链接(我希望)SDL,但是有另一个链接错误,涉及到qt库中的符号(我认为是与SDL链接的),因此这不是解决方案,因为我不知道这些符号属于哪些库。
所以问题是:
- 我在动态链接方面做错了什么根本性的事情吗? - 为什么-L选项不能帮助gcc链接该目录中的库? - 我能否强制编译程序时完全不使用这些库(好吧,我需要它们来在设备上运行程序),并在运行时加载它们?

请注意,-I/usr/include将使用来自您的主机的头文件,这些头文件可能与您的交叉编译工具链提供的不同。 - Patrice Tisserand
1个回答

1

-L 只是添加一个库搜索目录。尝试指定 -lSDL-1.2-lSDL 来实际链接到一个库。


我还发现了-Wl,--noinhibit-exec选项,它会强制链接,即使需要的符号未找到。 - 3demax

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接