Community
cancel
Showing results for 
Search instead for 
Did you mean: 
CBrou1
New Contributor I
1,654 Views

How to create and use a static library ?

I have been unsuccessful at creating and linking a static library with Eclipse.What am I doing wrong ?

 

  • First, I have created an empty IoT C++ project
  • Then I changed Properties>C/C++ Build>Settings>Build Artifact to "Static Library" with output prefix lib
  • I am able to build the project and it outputs a libXXX file. By default the file extension of the object file is blank so I have made some tests with and without forcing the extension to .a

 

 

4 Replies
Pedro_M_Intel
Employee
94 Views

Hello CABrouwers,

Have you tried to include the static library of the second project in Properties>C/C++ Build>Settings>Includes? If you do, does it make a difference?

Check how mraa is included there to guide you in how to include your library.

Peter.

CBrou1
New Contributor I
94 Views

Peter,

 

Thanks for your reply. The include does not change the issue. It is not surprising because I had added the library with its absolute path so there was no ambiguity there/

 

Also the error message refers to the absolute path of the library file.

I was reading about GCC and came accross a comment that in the Unix world GCCs add the prefix and the suffix automatically to the library name that is give with the -l option, Could it be the problem ? Would be strange that the Eclipse interface does not take that into account.

CBrou1
New Contributor I
94 Views

By the way what is strange is that there is no message about undefined symbols, which is the message I get if I omit to add the library. So clearly the library is accessed by the linker .. so I don't understand why LD complains it can't find it !

CBrou1
New Contributor I
94 Views

I found a work around:

Create the libXXXX.a archive as initially described.

Copy it in the folder : iotdk-ide-win\devkit-x86\sysroots\i586-poky-linux\usr\lib

In the project using the lib : Add the lib XXXX to the list in Properties>C/C++ General>Paths and Symbols>Libraries (! not libXXXX.a but just XXXX)

 

.. then all works out nicely

Reply