Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using precompiled library packages

Tags:

c++

aptitude

I figured the following out the hard way, because I didn't know what resource to look at. What should I have read?

I used aptitude to install the c++ library package libexample5.3 and libexample5.3-dev

  • libexample5.3 puts the actual object file (libexample.so.5.3) in /usr/lib/
  • libexample5.3-dev puts header file(s) (example.h) in /usr/include/

To link libexample into test.cpp, compile with:

g++ -o test test.cpp -lexample

But first all the entities linked to must be declared:

#include <example.h> //contains declarations of everything provided by libexample
int main() {
    return example::CONSTANT_2;
}
like image 936
Kietz Avatar asked Aug 25 '26 14:08

Kietz


1 Answers

For the libexample/libexample-dev stuff, the position of shared libraries and the like see the Debian policy manual; for the working of the -l flag, see the g++ manpage; for the fact that you have to #include some header to use a library, that's usual practice, but it's usually documented anyway in the library documentation.

like image 59
Matteo Italia Avatar answered Aug 28 '26 06:08

Matteo Italia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!