Linking include files in GCC
I can never remember what to type when linking include files in GCC, in fact the only one I can remember is -lm
for math.h
. The one I am specifically concerned with right now is sys/time.h
.
This page clears things up some, but I would still like a list.
Does anyone know of开发者_运维问答 a good list of linking options?
EDIT:
Maybe my question was not clear. I want to know what I need to type at the command line (like -lm
for math or -lpthread
for pthread) for the various libraries I might need to link when making C programs.
The functionality provided in <sys/time.h>
is implemented in libc.so
(C library). You don't need to link anything else in as gcc should automatically link to libc.so
by itself. There is no 'linking of include files', rather you are linking against libraries that contain the symbols defined by code.
The -l
flag is one of GCC's linker options and is used to specify additional libraries to link against.
edit because my gcc was performing optimizations on my source code at compile time
Also, the information in that link is a little outdated - you should not need an explicit link to libm
(which is what -l m
or -lm
does) in modern GCC.
I'm not sure i understand your question but -lm is not an ld option, -l is an option and -lx links libx.a (or .so, it depends). you might want to look at the ld manual for a full list of options.
I think all other standard libraries other than math are included in libc.so(.a) (-lc)
精彩评论