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

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

问题描述

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

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;
}

然后 scons 文件如下:

Then scons file like below:

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

我这里希望的是编译o.c并生成libo.a(OK),n.c会用这个'.a'来生成最终的可执行文件.所以我指定了 LIBS=['o'],希望它能指定一个存档文件来查找 libo.a 库.但是:

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

其实scons把我的命令解释为'-lo',也就是查找动态共享库.这不是我想要的,因为在链接期间,存档就像目标文件一样使用.'-l' 是否适用于存档文件,为什么 scons 将 LIBS 解释为使用动态链接共享库?

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?

谢谢.

推荐答案

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

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

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

另请查看我们用户指南<的第 4 章构建和链接库"/a>,它不仅解释了如何创建和使用库,还进一步指出您上面的SCons 将 LIBS 解释为使用动态链接共享库"的说法完全错误.否则目标文件将以 *.os 结尾...

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天全站免登陆