0

How do I use a custom dynamic library (wiringPi in my case) with a ARMv6 C++ compiler that was created with crosstool-ng? I built wiringPi then added -lwiringPi to the linker options, and this works fine using g++ but does not when using the new ARMv6 C++ compiler.

Error is: ld: cannot find -lwiringPi

Given that the crosstool compiler seems to have a structure of its own, maybe I have to build the library somewhere inside the ARMv6 C++ compiler files?

Shinagan
  • 435
  • 3
  • 15
  • Where is your compiler located and where did you install your library? – nsilent22 Jul 20 '15 at 20:07
  • ARMv6 compiler located in ~/local/x-tools/arm-unknown-linux-gnueabi/bin/, the library is in /usr/local/lib. I installed the compiler following this tutorial: [tuto](http://www.kitware.com/blog/home/post/426) – Shinagan Jul 20 '15 at 21:56
  • 1
    So your compiler won't find the library, since /usr/local/lib is location for your OS, and the compiler probably will try to find it under ~/local/x-tools/arm-unknown-linux-gnueabin/somedirnameidontremember/lib. Use `arm-unknown-linux-gnueabi-gcc --print-search-dirs` or `--print-sysroot` to get the hint where you should install your lib. – nsilent22 Jul 20 '15 at 22:23
  • Making progress! I copied my *.so files in the [...]/sysroot/lib/ folder indicated by --print-sysroot. Now I get the following output : `[...]libwiringPi.so: file not recognized: File format not recognized` Using the library files on my raspberry pi did not help, the library is still of unrecognized format... – Shinagan Jul 20 '15 at 22:55
  • Check with `file` command what file type `libwiringPi.so` really is. Could be, you compiled the library for your native architecture (e.g. i386 or x86_64) and try to use it for armv6. – nsilent22 Jul 21 '15 at 05:50
  • If I take a random library in that same folder I get: `ELF 32-bit LSB shared object, ARM, EABI5 version 1 (GNU/Linux), dynamically linked, for GNU/Linux 3.12.43, not stripped` My files, taken from the raspberry pi build: `ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=cbd69abfafee95a462e64a34c3b862a5023190d4, not stripped` How can I build my library "for GNU/Linux 3.12.43"? Maybe using crosstools-ng again? – Shinagan Jul 21 '15 at 11:56
  • So, if your libwiringPi.so is built form ARM EABI5 (which is good), make sure that for compiling your project you use arm g++ compiler... and arm linker (so you don't use `/usr/bin/ld`, but `~/local/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknow-linux-gnueabi-ld`). – nsilent22 Jul 21 '15 at 16:45
  • 1
    Solved!! First, thanks a lot for your help! It made me aware of a lot of things I absolutely did not know. In addition to using the right linker as you just said, there was one more critical step. I had used crosstool-ng to create a soft float compiler, which is apparently the default with my ubuntu, but the Raspberry Pi is a hard float system! Therefore I had to create a new hard float ARM compiler. Lastly, custom libraries have to go in [...]/sysroot/usr/lib, and nowhere else! Thanks again! – Shinagan Jul 21 '15 at 21:11

0 Answers0