Add C ++ library for eclipse C ++ project

I am trying to add an existing library to Eclipse. I am using cross compiler for C ++ with Eclipse IDE installed in a debian linux VM.

mmapGpio

lib is found here .

/mmapGpioBasicRev1.tar.gz

has a file cpp

and h

a small demo program.

I have compiled this code with no problem. A file is created .o

. I have successfully archived the file withar -q libmmapGpio.a mmapgpio.o

I put mine libmmapGpio.a

in ~/.../UserLib directory

I put mine mmapGpio.h

in~/.../UserInclude

At this moment, everything is in order.

I am opening a new project that uses the library mmapGpio

:

#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 the linker says cannot find -llibmapGpio

!

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

  • includes path: /home/octopuss/rpi/UserInclude

    (mmapGpio.h file)
  • Library path: /home/octopuss/rpi/UserLib

    (libmmapGpio.a file)
  • Libraries: libmmapGpio

Why am I getting this message?

for details -> 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

      

mistake:

  • skip incompatible /home/.../UserLib/libmmapGpio.so when looking for -lmmapGpio
  • ld: cannot find -lmmapGpio
+3


source to share


2 answers


"why is this message?"

This is because, with your settings, the linker is actually looking for a library file named liblibmmapGpio.a

.

"... so cross-compilation is done, but the linker says" Can't find -llibmapGpio "!
...
 - Libraries: libmmapGpio"

You just need to specify the unprefixed library lib

in your linker library settings:



mmapGpio

enter image description here

Eclipse CDT Builder passes this value -l

to the linker, which automatically expands to search for the specified alternate addresses. libmmapGpio.a

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

+1


source


I found the problem ... my .so lib was not compiled by ARM, so there is an X86 library not compatible with my ARM program.

I work it out to set the erm-linuxgnuabihf- prefix and its path to change the setting.



Thanks to TTAVAR PEI and Scott Stensland

enjoy

0


source







All Articles