how to differentiate static library/compilation with dynamic?

I want to compile a program with two libraries: lpcap and levent

but it seems to me that the commands for static compilation and dynamic compilation are the same


gcc -o myprogram main.c -lpcap -levent


if I want to make sure it is static compilation, how?
and how can I determine whether the lpcap and levent are static library or dynamic library?

I notice there are four libpcap library files,
how to determine which one is used?
especially there are 3 versions of libpcap.so, which one is used if I run the above command.

1
2
3
4
/usr/lib/x86_64-linux-gnu/libpcap.a
/usr/lib/x86_64-linux-gnu/libpcap.so
/usr/lib/x86_64-linux-gnu/libpcap.so.0.8
/usr/lib/x86_64-linux-gnu/libpcap.so.1.5.3
Last edited on
gcc -o myprogram main.c -static -lpcap -levent
Is libpcap.so not a symlink? (I would expect it to be symlink to libpcap.so.1.5.3, as it's the newest version.)

Without -static you'll link to whatever the symlink libpcap.so rerers to. With -static you link to libpcap.a

Andy

GNU linker manual
https://sourceware.org/binutils/docs-2.21/ld/

On systems which support shared libraries, ld may also search for files other than libnamespec.a. Specifically, on ELF and SunOS systems, ld will search a directory for a library called libnamespec.so before searching for one called libnamespec.a. (By convention, a .so extension indicates a shared library.) Note that this behavior does not apply to :filename, which always specifies a file called filename
Last edited on
PS (Aimed at my future self, as much as anyone else...)

In the MinGW and CYGWIN cases, the search order is more confusing it seems:

libxxx.dll.a
xxx.dll.a
libxxx.a
cygxxx.dll (*)
libxxx.dll
xxx.dll

ld and WIN32 (cygwin/mingw)
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/win32.html

Incidentally, this article also provides the answer to a question asked in this thread:

Am I understanding dll and lib files right?
http://www.cplusplus.com/forum/general/164929/

yj1214 wrote:
Game libraries such as Irrlicht don't requires to link with lib files. You can just link directly with dll file.

The answer being:
The cygwin/mingw ports of ld support the direct linking, including data symbols, to a dll without the usage of any import libraries.

Andy
Last edited on
Topic archived. No new replies allowed.