4 Replies Latest reply on Jan 22, 2016 8:38 PM by CABrouwers

    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

      • Then I create a second  project that refers to the objects in the first one(I copy the header file).
      • I also add the library files in Properties>C/C++ General>Paths and Symbols>Libraries
      • When I build the second project, the linker (LD) runs into troubles.
        The error message is :
        cannot find -lC:\Users\myName\workspace_iot\myProject\Debug\libxxx.a
        However, I am positive, the file output of the first project build is definitly located at C:\Users\myName\workspace_iot\myProject\Debug\libxxx.a

        • 1. Re: How to create and use a static library ?

          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.



          • 2. Re: How to create and use a static library ?


            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.

            • 3. Re: How to create and use a static library ?

              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 !

              • 4. Re: How to create and use a static library ?

                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