9

Embarrassingly basic question. sudo apt-get install libmemcached6 - where do the .h's and .o's or .so's live in a typical install on a Linux machine (Ubuntu)? And, how do I make sure g++ can pick them up?

2
  • g++ can pick them up if they are properly installed because they should be in the PATH. Otherwise, you could compile the library yourself statically and place the output somewhere in a folder of your choice. Commented May 24, 2012 at 0:01
  • The question is which folder to put them in Commented May 18, 2020 at 4:48

3 Answers 3

19

They go to /usr/include and /usr/lib. If you use the -l option (for the libraries) it should find them from these standard places. If you include using <file.h> it should also get it from the right place.

Sign up to request clarification or add additional context in comments.

8 Comments

Found the so in /usr/lib. No header in /usr/include. Is this likely something not included in an apt-get install and I'll just need to acquire the source myself?
mostprobably your library has a -dev version that installs the header and this one just installs the runtime requirements (aka the .so) try doing apt-cache search libmemcached6 and see if there's a libmemcached6-dev package for development files. that will add the header file
Thanks, I needed the -dev version. g++ myfile.cpp works clean now.
Linking with -lmemcached seems like it compiles but fails to link the C functions in, not sure how to tell where to find them (or where they are.)
@djechlin, try running objdump -T /usr/lib/libmemcached.so.6 and checking to make sure the names match what you have in your code.
|
13

On Ubuntu (and other Debian variants) you can use the dpkg command to find out. For example:

$ dpkg -L libxml2
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libxml2
/usr/share/doc/libxml2/AUTHORS
/usr/share/doc/libxml2/NEWS.gz
/usr/share/doc/libxml2/TODO.gz
/usr/share/doc/libxml2/copyright
/usr/share/doc/libxml2/README
/usr/share/doc/libxml2/changelog.Debian.gz
/usr/share/doc/libxml2/README.Debian
/usr/lib
/usr/lib/libxml2.so.2.7.8
/usr/lib/libxml2.so.2

As you can see, Debian packages don't typically include the .h files; those are normally in corresponding -dev packages. So you can find the header files here:

$ dpkg -L libxml2-dev
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libxml2-dev
/usr/share/doc/libxml2-dev/AUTHORS
/usr/share/doc/libxml2-dev/NEWS.gz
/usr/share/doc/libxml2-dev/TODO.gz
/usr/share/doc/libxml2-dev/copyright
/usr/share/doc/libxml2-dev/README
/usr/share/doc/libxml2-dev/changelog.Debian.gz
/usr/share/aclocal
/usr/share/aclocal/libxml2.m4
/usr/share/man
/usr/share/man/man3
/usr/share/man/man3/libxml.3.gz
/usr/share/man/man1
/usr/share/man/man1/xml2-config.1.gz
/usr/include
/usr/include/libxml2
/usr/include/libxml2/libxml
/usr/include/libxml2/libxml/HTMLtree.h
/usr/include/libxml2/libxml/tree.h
/usr/include/libxml2/libxml/xmlreader.h
/usr/include/libxml2/libxml/xmlschemastypes.h
...

As for gcc, the manual explains how it searches for header files. Note that this is different and separate from using -l to instruct the linker to link with a certain library.

Comments

1

On Linux and the majority of the Unix-based systems, the libraries may be found on either of these two locations:

  1. /usr/lib/
  2. /usr/local/lib/

The difference between these two locations is that the latter is used for the third party libraries. So if you have published your own library or have installed one from a third party repository (for instance ppa),those files should go to /usr/local/lib.

The storage of header files can be understood using the above analogy. The folders are:

  1. /usr/include/
  2. /usr/local/include/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.