0

I have been trying to find a guide how to link a static library to my Eclipse CDT project but I was not able to find one. I have tried both with Visual Studio 2010 compiler and MiNGW.

I use Windows and Eclipse Juno 8.1.1 , under Project Settings -> C/C++ Build -> Settings I have something like this :

enter image description here

Lib manager :

enter image description here

Path and symbols:

enter image description here

Patryk
  • 22,602
  • 44
  • 128
  • 244

1 Answers1

2

You have to add the library name without lib and .a in Libraries (-l) and adding the path in Libraries search path (-L).

However, this question is resolved also in this stack.

Also in this site you can find a lot of usefull information and the explanation on how include linking library.

edit

As reported in the documentation:

Q. How do I add a static library file to a project? (Files such as libmtm.a)

A. First you will need to copy the file into your Eclipse project. You can do that by simply dragging it into the project folder in the "Project Explorer" tree in Eclipse. To link the library (A static library is used similarly to an object file):

  1. Open Project, Properties.
  2. In that dialog select "C++ Build, Settings".
  3. Under the Tool Settings tab choose "Linker" or "MinGW C Linker" or equivalent and under that select "Libraries".
  4. Under "Libraries" press the "Add..." button (the green cross) and write the name of the library without the "lib" prefix and ".a" suffix. e.g. in order to link the library file libmtm.a write "mtm".
  5. Under "Library search path" press the "Add..." button, select workspace and select the project.
Community
  • 1
  • 1
Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146
  • So I should put e.g. "-lmtm" and "-L/relative/path/to/lib/" in defines ? – Patryk Dec 07 '12 at 08:24
  • You are right. I have found this website few days ago but this apply to Eclipse up to version 7.0.2. in 8.0.2 or 8.1.1 there is no "MinGW C Linker" tab. I think the only option will be to add "-lmtm" and "-L/path/to/lib" to defines. – Patryk Dec 07 '12 at 10:35
  • No, I have tried all of the possibilities (with -l and -L) but no luck - even in 7.0.2 Eclipse can't find the library ( only absolute path works there) – Patryk Dec 07 '12 at 12:09