سؤال

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;
}
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top