目前,我正在进行一个项目,以记录西门子plc的数据。为了达到这个目的,我使用snap7。snap7(http://snap7.sourceforge.net/)是一个通信库。
我已经设法在我的linux桌面上运行了它,但是当我试图交叉编译snap7库时,我得到了一些错误
链接所有对象文件时生成错误。

g++ -shared -fPIC -o ../bin/mips-openwrt-linux-g++/libsnap7.so @"filelist.txt" -L.  -lpthread -lrt  -O3
/usr/bin/ld: ../temp/mips-openwrt-linux/sys_snap_msgsock.o: Relocations in generic ELF (EM: 8)
./temp/mips-openwrt-linux/sys_snap_msgsock.o: could not read symbols: File in wrong format
collect2: error: ld returned 1 exit status
make: *** [../bin/mips-openwrt-linux-g++/libsnap7.so] Error 1

如果我是正确的,我认为它使用了错误的链接器,它应该使用位于以下位置的工具链链接器:openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uclibc-0.9.33.2/bin/
我也试过用mips-openwrt-linux-g++编译这个软件。
现在又出现了一个错误:
mips-openwrt-linux-g++ -shared -fPIC -o ../bin/mips-openwrt-linux-g++/libsnap7.so @"filelist.txt" -L.  -lpthread -lrt  -O3
openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.8.3/../../../../mips-openwrt-linux-uclibc/bin/ld: ../temp/mips-openwrt-linux/sys_snap_msgsock.o: relocation R_MIPS_26 against `close' can not be used when making a shared object; recompile with -fPIC
../temp/mips-openwrt-linux/sys_snap_msgsock.o: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [../bin/mips-openwrt-linux-g++/libsnap7.so] Error 1

我希望有人熟悉这个错误,并能帮助我。
提前谢谢。
编辑1:
有一些预编译的二进制文件。在makefiles中,我将cc改为g++目录。没有ld标志,所以我不能在那里设置链接器。

最佳答案

你能交叉编译并运行一个“hello world”程序吗?
file ../temp/mips-openwrt-linux/sys_snap_msgsock.o的输出是什么?

10-08 02:31