How does gcc recognize that -lfl corresponds to flex library?
when i compile lex.yy.c with lfl gcc recognizes that some .a file of the flex library might be needed to be linked with my code. similarly for yacc we specify the -ly compiler option.
in other words if i create a library, abc.a i want gcc to recognize that wheneve开发者_运维问答r a program is compiled with -labc it should link with the library abc.a. what configuration changes need to be done?
The yacc library is named liby.so
, and lives in something like /usr/lib
, which is a directory that ld
knows about.
Your abc library should be named libabc.so
(or ".a" for a static lib), and should be placed in a directory that is searched by ld
.
To add /home/foo/libs
to the list of directories searched, add -L/home/foo/libs
to the ld
command.
You don't need to configure anything. Call your library libabc.a, then use the command line:
gcc ... -L<path-to-libabc.a> -labc
Alternatively, if you want GCC to recognise the library abc and link it via -labc
, assuming abc is a static library, make sure your library file/archive abc is named libabc.a
, and it is either located in one of the directories GCC searches for .a
files, or you add a -L
flag where the parameter is the directory where libabc.a
is located in.
精彩评论