Search code examples
ccompiler-errorslinkereclipse-cdt

Trouble with linking a library - Eclipse


I have a library in my .c:

#include "Madlib.h"

I know that now I gotta link it, otherwise it doesn't work. My trouble is understanding HOW do I link it. Every post I see talks about .a libraries or with a libprefix. I got none of that. I have the header obvisouly and then a .lib.

Anyways, I tried to make my way into those posts, and got here:

Add library

Although, when I try to compile, I get this:

Invoking: Cygwin C Linker
gcc  -o "MCL.exe" ./src/example.o    -lMADLib.lib
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lMADLib.lib: No such file or directory
collect2: error: ld returned 1 exit status

What exactly is that path? How can I expand it? Should I place the .lib and .h inside the folder that it refers to? Or should I add some kind of path to the library -I entry?


Solution

  • You may have to do 2 things:

    • Add the library without the extensions, like -lMADLib instead of -lMADLib.lib
    • As Pierre Bourgery, in case the library isn't in a path where the linker searches through, add the path to the folder where the library is to the library search path, like -L<path to library folder>

    See here: https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html