문제

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