Where is the function definition of system headers?

When we write a C or C++ code, it is very common we include system headers at the beginning, such as;

#include <stdio.h>
#include <stdlib.h>
#include <string>

In Linux, these headers are usually in /usr/include, which belongs to search path. However, these are just header files. Where are the source codes or library of these header files?

Thank you.
They are defined in system libraries, such as libc or libstdc++. They are linked in by the linker after your sources are compiled. I would expect them to be found in the /usr/lib directory.
Thank you. I can see a lot of .so and .a files are in /usr/lib

So when g++ or gcc link them, they will automatically search these paths to find the library files ?
Any idea how to check what paths g++ or gcc will go thru to search the library files?

Thank you a lot.
ld -verbose | grep SEARCH

gcc -print-search-dirs

http://coliru.stacked-crooked.com/a/fcb66a6f01026dda

Thank you very much!

I have another questions.

When I write the makefile to compile the codes, if in my codes I have used the library in /usr/lib, for example : libpcap.a or libpcap.so. Do I have to add flag : -lpcap in my makefile ?

Generally speaking is, if I use a library file (either .a or .so), I need add the corresponding flags to makefile as gcc or g++ option, correct?

Thank you.
> if in my codes I have used the library in /usr/lib, for example : libpcap.a or libpcap.so.
> Do I have to add flag : -lpcap in my makefile ?
> if I use a library file (either .a or .so), I need add the corresponding flags to makefile as gcc or g++ option, correct?

Yes.

If the library is not in one of the directories listed with ld -verbose | grep SEARCH, you would also need to add the directory containing the library with the -L option.
https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gcc/Directory-Options.html#Directory-Options
Thank you!
Topic archived. No new replies allowed.