使用scons'Program'命令中的'LIBS'未能找到静态库,为什么? [英] Using 'LIBS' in scons 'Program' command failed to find static library, why?

查看:1220
本文介绍了使用scons'Program'命令中的'LIBS'未能找到静态库,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个'n.c'作为主要函数,'o.c'作为导入函数,如下所示:

  $ cat nc oc 
int f();
int main(){
f();
返回0;
}
#include< stdio.h>
int f(){
printf(hello\\\
);
返回2;
}

然后scons文件如下:

 库('o.c')
程序('n.c',LIBS = ['o'])

我希望在这里编译oc并生成libo.a(OK),nc将使用这个'.a'来生成final可执行文件。所以我指定了LIBS = ['o'],并指定一个存档文件来查找libo.a库。但是:

  $ scons -Q 
gcc -on no -lo
/ usr / bin / ld :无法找到-lo
collect2:错误:ld返回1退出状态
scons:*** [n]错误1

实际上,scons将我的命令解释为'-lo',它是查找动态共享库。
这不是我想要的,因为在链接过程中,存档被用作对象文件。 '-l'是否适用于档案文件,以及为什么scons会将LIBS解释为使用动态链接共享库?
$ b 谢谢。

解决方案

在这种情况下,您还需要指定搜索库的路径:

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

请检查我们的 UserGuide ,它不仅解释了如何创建和使用库,它进一步说明你从上面的声明SCons解释LIBS使用动态链接共享库显然是错误的。否则,目标文件将以 *。os 结尾,而不是...


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.

解决方案

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...

这篇关于使用scons'Program'命令中的'LIBS'未能找到静态库,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆