building and linking a shared library

When using -l<libname> to specify library to link, the linker will first search for lib<libname>.so before searching for lib<libname>.a.

In your case it doesn’t work, because the library filename is not with .so suffix.

You may create simlink

libbeat.so -> libbeat.so.1.0.1

or

libbeat.so -> libbeat.so.1
libbeat.so.1 -> libbeat.so.1.0.1

You can also use -l:libbeat.so.1.0.1 (if your linker supports it, check in man ld description of -l parameter). Another option is to specify the library without -l

g++ -o checkbeat checkbeat.cpp -I . -L. libbeat.so.1.0.1

Note that the library you link to should be put after object/source file using its symbols – otherwise the linker may not find the symbols.

Leave a Comment