Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc: Link Library In Same Folder As Source Files

Tags:

c

linux

unix

gcc

I'm trying to compile a C project using gcc. All source files and the .a library file are in the same folder. How can I successfully compile the project?

enter image description here

I've tried:

gcc -o test main.c IPT.c logitem_list.c -L -./ -libpt

But I receieve error:

/usr/bin/ld: cannot find -libpt
collect2: error: ld returned 1 exit status
like image 524
Stephen Lasky Avatar asked Jun 22 '16 14:06

Stephen Lasky


1 Answers

You specify the directory to -L and the 'core' name to -l:

gcc -o test main.c IPT.c logitem_list.c -L . -lpt

When given -lpt, the linker looks for libpt.a or libpt.so or equivalents (extensions like .dylib or .sl or .dll or .lib on other platforms).

The -L -./ is suggesting that the linker look in a directory called 'dash dot', which is unlikely to exist and isn't where libpt.a is found anyway.

like image 172
Jonathan Leffler Avatar answered Oct 01 '22 09:10

Jonathan Leffler