简体   繁体   English

我的交叉编译器找不到共享库

[英]My cross-compiler cannot find a shared library

I am coding with Eclipse on a Debian VM, and cross-compile for a Raspberry Pi Zero. 我正在Debian VM上使用Eclipse进行编码,并为Raspberry Pi Zero进行交叉编译。 I would like to use the mraa library, but after hours of struggle I still cannot make it work. 我想使用mraa库,但是经过数小时的努力,我仍然无法使它工作。 - On the target (Raspi zero) I can compile mraa locally using CMake, simply following the author's instructions. -在目标上(Raspi零),我可以按照作者的指示使用CMake在本地编译mraa。 It works perfectly when I play with a c++ example locally. 当我在本地玩c ++示例时,它可以完美工作。 - On the host, I copied the *.so files from the target, but the cross-compiler is not liking it (undefined reference errors). -在主机上,我从目标复制了* .so文件,但交叉编译器不喜欢它(未定义的引用错误)。 In the Eclipse settings, I added the header directory to the include path, the shared lib directory to the library search path (-L) and I added the -lmraa flag. 在Eclipse设置中,我将标头目录添加到include路径,将共享lib目录添加到库搜索路径(-L),并且添加了-lmraa标志。

What am I doing wrong? 我究竟做错了什么? Am I supposed to compile MRAA on the host using CMake? 我应该使用CMake在主机上编译MRAA吗? If so, how do I define my cross-compiler with CMake? 如果是这样,如何用CMake定义交叉编译器?

Sorry for not editing my question earlier, but sometimes the question becomes clear only once you find the answer... 抱歉,您未及早编辑我的问题,但有时只有找到答案后问题才会变得清楚...

Essentially, I wanted to use a library (MRAA) for which I had the source code and a cmake file. 本质上,我想使用一个具有我的源代码和cmake文件的库(MRAA)。 I thought that I could simply run cmake on the target (my RasPi Zero), then transfer the .so (shared libraries) files to my host in order to cross-compile with Eclipse. 我以为我可以在目标(我的RasPi Zero)上运行cmake,然后将.so(共享库)文件传输到主机,以便与Eclipse进行交叉编译。 But it didn't work. 但这没有用。

So instead I compiled the library using cmake on the host. 因此,我改为在主机上使用cmake编译了库。 For it to work, you need to provide a link to a cross-compiler as well as a link to a root file system similar to the target because of all the dependencies. 为了使其正常工作,由于所有依赖性,您需要提供指向交叉编译器的链接以及与目标类似的根文件系统的链接。 So I created a toolchain.cmake file to define everything and called this toolchain file as an option when I ran cmake. 因此,我创建了一个toolchain.cmake文件来定义所有内容,并在运行cmake时将此工具链文件称为选项。

Everything is explained here: http://www.vtk.org/Wiki/CMake_Cross_Compiling 此处介绍了所有内容: http//www.vtk.org/Wiki/CMake_Cross_Compiling

The cross-compiler and the root file system are provided here: https://github.com/raspberrypi/tools/tree/master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64 此处提供了交叉编译器和根文件系统: https : //github.com/raspberrypi/tools/tree/master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64

And this seems to be the proper way to use someone else's shared library when the compiled version does not exist for your target (in my case, a Raspberry Pi Zero). 当目标的编译版本不存在时(这是Raspberry Pi Zero),这似乎是使用其他人的共享库的正确方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM