3

I am attempting to add an existing library to Eclipse. I use a cross compiler for C++ with the Eclipse IDE, installed on a virtual linux debian machine.

The mmapGpio lib is found here.

/mmapGpioBasicRev1.tar.gz has a cpp and an h file with a small demo program.

I have compiled this code without a problem. A .o file is generated. I've archived the file successfully with ar -q libmmapGpio.a mmapgpio.o

I've placed my libmmapGpio.a in ~/.../UserLib directory I've placed my mmapGpio.h in ~/.../UserInclude

At this point all is OK.

I open a new project that uses the mmapGpio library:

#include "mmapGpio.h"
#include "stdio.h"

int main(void){
    mmapGpio rpiGpio; // instantiate an instance of the mmapGpio class
    rpiGpio.setPinDir(17,mmapGpio::OUTPUT); // set GPIO17 to output
    while(1) {// toggle pin as fast as possible
           rpiGpio.writePinHigh(17);
           rpiGpio.writePinLow(17); 
    }

    return 0;
}

So cross-compilation is done, but linker say cannot find -llibmapGpio!

I have made declaration in the properties project; C/C++ General

  • includes path : /home/octopuss/rpi/UserInclude (the mmapGpio.h file)
  • Library path : /home/octopuss/rpi/UserLib (the libmmapGpio.a file)
  • Libraries : libmmapGpio

Why do I receive this message?

for detail -> console view

03:16:30 **** Build of configuration Debug for project Gpio1 ****
make all 
Building file: ../Gpio1.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/home/octopuss/rpi/UserInclude -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Gpio1.d" -MT"Gpio1.d" -o "Gpio1.o" "../Gpio1.cpp"
Finished building: ../Gpio1.cpp

Building target: Gpio1
Invoking: Cross G++ Linker
arm-linux-gnueabihf-g++ -L/home/octopuss/rpi/UserLib -o "Gpio1"  ./Gpio1.o   -lmmapGpio
/home/octopuss/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /home/octopuss/rpi/UserLib/libmmapGpio.so when searching for -lmmapGpio
/home/octopuss/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lmmapGpio
collect2: error: ld returned 1 exit status
make: *** [Gpio1] Erreur 1

error :

  • skipping incompatible /home/.../UserLib/libmmapGpio.so when searching for -lmmapGpio
  • ld: cannot find -lmmapGpio
  • 1
    I suggest you do this from the command line outside eclipse - once you understand the steps and have it cross compiling correctly then for future productivity setup eclipse – Scott Stensland Apr 16 '15 at 19:42
  • thank you for your answer Scott: to compile any problems, but it comes to cross compile for ARM linux system (gcc_linaro) on the command line when looking at the Eclipse console it's been very very long commands. I tried to put pictures of the console but I'm too new to the forum I renounce the photos. – Bernard MASTROGIACOMO Apr 17 '15 at 18:40

2 Answers2

1

"why this message ?"

It's because with your settings, the linker actually looks up for a library file named liblibmmapGpio.a.

"... so crosscompilation is done but linker say "cannot find -llibmapGpio" !
...
- Libraries : libmmapGpio"

You just need to specify the library without the lib prefix in the linker library settings:

mmapGpio

enter image description here

The Eclipse CDT Builder passes this as a -l option to the linker, which automatically extends to search for libmmapGpio.a at the specified additional pathes.

See also this Q&A for more illustrated samples and links:
Problems importing libraries to my c++ project, how to fix this?

Community
  • 1
  • 1
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
0

I found the problem ... my .so lib wasn't ARM cross compiled so there is a X86 library not compatible whith my ARM Programm.

I solve this to set erm-linuxgnuabihf- prefix and his path to cross setting parameter.

Thanks to TTAVAR PEI and Scott Stensland

enjoy