如何将库添加到wscript文件中
Waf - How to add a library to a wscript file?
我想将c++库cpp-netlib添加到wscript中。然后,如果我运行dpkg -l libcppnetlib0
,我得到:
libcppnetlib0: 0.11.0-1 amd64 C++ Network Library
运行dpkg -L libcppnetlib0
,我得到:
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/cppnetlib-uri.so.0.11.0
/usr/lib/x86_64-linux-gnu/cppnetlib-server-parsers.so.0.11.0
/usr/lib/x86_64-linux-gnu/cppnetlib-client-connections.so.0.11.0
/usr/share
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/libcppnetlib0
/usr/share/doc
/usr/share/doc/libcppnetlib0
/usr/share/doc/libcppnetlib0/copyright
/usr/share/doc/libcppnetlib0/changelog.Debian.gz
/usr/lib/x86_64-linux-gnu/libcppnetlib-server-parsers.so.0
/usr/lib/x86_64-linux-gnu/libcppnetlib-client-connections.so.0
/usr/lib/x86_64-linux-gnu/libcppnetlib-uri.so.0
因为我需要libcppnetlib-uri, libcppnetlib-server-parsers, libcppnetlib-client-connections
,在wscript中我添加了以下字段:
conf.check_cxx(lib='cppnetlib-uri',uselib_store='CPPNETLIBU', define_name='HAVE_CPPNETLIBU',mandatory=True)
conf.check_cxx(lib='cppnetlib-server-parsers',uselib_store='CPPNETLIBS', define_name='HAVE_CPPNETLIBS',mandatory=True)
conf.check_cxx(lib='cppnetlib-client-connections',uselib_store='CPPNETLIBC', define_name='HAVE_CPPNETLIBC',mandatory=True)
然后我在这里添加了三个引用(CPPNETLIBU, CPPNETLIBC, CPPNETLIBS):
libndn_cxx = dict(
target="ndn-cxx",
name="ndn-cxx",
source=bld.path.ant_glob('src/**/*.cpp',
excl=['src/security/**/*-osx.cpp',
'src/**/*-sqlite3.cpp']),
headers='src/common-pch.hpp',
use='version BOOST CRYPTOPP OPENSSL SQLITE3 RT PTHREAD CPPNETLIBC CPPNETLIBU CPPNETLIBS',
includes=". src",
export_includes="src",
install_path='${LIBDIR}')
但是,当我启动。/waf configure时,它失败了,它找不到我指定的库。
错误是:
[199/200] Linking build/examples/clientMat
examples/clientMat.cpp.2.o: In function `construct<boost::network::http::impl::normal_delegate, asio::io_service&>':
/usr/include/c++/4.9/ext/new_allocator.h:120: undefined reference to `boost::network::http::impl::normal_delegate::normal_delegate(asio::io_service&)'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libcppnetlib-client-connections.so: undefined reference to `boost::system::system_category()'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libcppnetlib-client-connections.so: undefined reference to `boost::system::generic_category()'
collect2: error: ld returned 1 exit status
我(也许?)在/usr/local/lib/pkgconfig中没有任何引用的情况下发现了这个问题。的确,运行:ls /usr/local/lib/pkgconfig
,我有一些.pc
文件,但没有关于cppnetlib。我试着写我自己的,但没有成功。
如果问题在这里,实际上我需要一个关于如何正确编写.pc
文件的帮助。
这个问题是一个很好的起点,但我没有成功:waf -如何添加外部库到wscript_build文件
您可以像https://waf.io/book/
中描述的那样使用bld.read_shlib()示例代码(main.c):
#include <stdio.h>
#include <math.h>
int main(int argc, char* argv[]) {
printf("cos(0.123456)=%fn", cos(0.123456));
return 0;
}
使用数学库构建脚本:
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
top = '.'
out = 'build'
VERSION = '0.0.0'
APPNAME = 'app'
def options(opt):
opt.load('compiler_c')
def configure(conf):
conf.load('compiler_c')
conf.check_cc(lib='m', cflags='-Wall', uselib_store='M')
conf.check(header_name='math.h', features='c cprogram')
def build(bld):
bld.read_shlib('m')
bld.program(target='app', source='main.c')
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 文本文件中的单词链表
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用新行和不使用新行读取文件
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 挂起和取消挂起一个文件DLL
- 如何确定我已使用非编码文件到达 EOF?
- 命名空间中具有.h和.cpp文件的类
- 如何使用ndk-build.cmd构建Android.so文件
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 读取文件并输入到矢量中
- 在C++中查找文件
- c++库的公共头文件中应该包含什么
- 用c++从输入文件中读取另一行
- Cppcheck生成xml转储文件
- 读取文件的最后一行并输入到链接列表时出错
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- 如何将内容数组写入文本文件?
- 如何将库添加到wscript文件中