开发者

Static library not included in resulting LLVM executable

I am trying to compile a c program using LLVM and I am having trouble getting some static libraries included. I have successfully compiled those static libraries using LLVM and, for example, libogg.a is present, as is ogg.l.bc.

However, when I try to build the final program, it does not include the static ogg library. I've tried various compiler options with the most notable being:

gcc oggvorbis.c -O3 -Wall -I$OV_DIR/include -l$OV_DIR/lib/libogg.a -l$OV_DIR/lib/libvorbis.a -o test.exe

This results in the following output (directories shortened for brevity):

$OV_DIR/include/vorbis/vorbisfile.h:75: warning: ‘OV_CALLBACKS_DEFAULT’ defined but not used
$OV_DIR/include/vorbis/vorbisfile.h:82: warning: ‘OV_CALLBACKS_NOCLOSE’ defined but not used
$OV_DIR/include/vorbis/vorbisfile.h:89: warning: ‘OV_CALLBACKS_STREAMONLY’ defined but not used
$OV_DIR/include/vorbis/vorbisfile.h:96: warning: ‘OV_CALLBACKS_STREAMONLY_NOCLOSE’ defined but not used
llvm-ld: warning: Cannot find library '$OV_DIR/lib/ogg.l.bc'
ll开发者_如何学编程vm-ld: warning: Cannot find library '$OV_DIR/lib/vorbis.l.bc'
WARNING: While resolving call to function 'main' arguments were dropped!

I find this perplexing because $OV_DIR/lib/ogg.l.bc DOES exist, as does vorbis.l.bc and they are both readable (as are their containing directories) by everyone.

Does anyone have any idea with what I am doing wrong?

Thanks,

Matt


As unwind said, -l is followed by the library name.

For example, in linux library naming conventions, if a library is named libogg,

-logg will find and choose the *best match in the library directories.

You can add a directory into the list:

  1. -L option is one of the way to add the following folder to the list temporarily.
  2. The environment variable LD_LIBRARY_PATH also affects the list on most of Linux/Unix > with GNU tools.

gcc may find both static and shared library files whose name matches with the requested library name.

For example,

libogg.a libogg.so

That's why there is a gcc option, -static

-static
On systems that support dynamic linking, this prevents linking with the shared libraries. On other systems, this option has no effect.

If you just want to use a shared or static library file - directly, just as an object file, then give their path without any option, like

gcc oggvorbis.c the_path/libogg.a


I don't think the -l option expects paths. You should split those out, and use the -L option to set the paths, then just use plain library names with -l:

$ gcc oggvorbis.c -O3 -Wall -I$OV_DIR/include -L$OV_DIR/lib -logg -lvorbis -o test.exe

Also note that when used like this, you don't include the "lib" and ".a" parts of the library name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜