Using 'LIBS' in scons 'Program' command failed to find static library, why?

懵懂的女人 提交于 2019-12-02 14:46:23

问题


I've got a 'n.c' as main function, and 'o.c' as import function, like below:

$ cat n.c o.c
int f();
int main(){
  f();
  return 0;
}
#include<stdio.h>
int f(){
  printf("hello\n");
  return 2;
}

Then scons file like below:

Library('o.c')
Program('n.c',LIBS=['o'])

What I hope here is to compile o.c and generate libo.a(OK), and n.c will use this '.a' to generate final executable. So I specified LIBS=['o'], in hoep that it will specify an archive file to find libo.a library. But:

$ scons -Q
gcc -o n n.o -lo
/usr/bin/ld: cannot find -lo
collect2: error: ld returned 1 exit status
scons: *** [n] Error 1

Actually, scons interpreted my command to be '-lo', which is to find a dynamic shared library. This is not what I wanted, because during linking, archive is used like object files. Does '-l' work with archive files, and why scons interprets LIBS to use dynamic link shared libraries?

Thanks.


回答1:


You also need to specify the path where to search for libraries, in this case:

Program('n.c',LIBS=['o'], LIBPATH=['.'])

Please also check chapter 4 "Building and Linking with Libraries" of our UserGuide, which does not only explain how to create and work with Libraries, it further states that your claim from above "SCons interprets LIBS to use dynamic link shared libraries" is plain wrong. Otherwise the object files would end with *.os instead...



来源:https://stackoverflow.com/questions/39831985/using-libs-in-scons-program-command-failed-to-find-static-library-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!