waf -how to add external library to wscript_build file

匿名 (未验证) 提交于 2019-12-03 01:41:02

问题:

I tried to add an external library to my waf: the winmm.lib library

it looks like this now:

srcs = ['timers.cpp']  LIBS ='winmm.lib'; create_lib('timers', srcs,LIBS) 

it doesn't work. It says I vmp library 'winmm.lib.py' was not found in the current library.

can someone help?

回答1:

I have never heard of "create_lib" in waf, so I have no idea what that function is or does, but I'll try to answer your question anyway. Below I have a very basic wscript that is my typical way of setting up a simple project (on linux). If waf is as platform independent as it claims, then this should work for windows as well; I have not tested it. This should create a simple shared library.

def options(opt):     opt.load('compiler_cxx')  def configure(cfg):     cfg.load('compiler_cxx')     cfg.check(compiler='cxx',               lib='winmm',               mandatory=True,                uselib_store='WINMM') def build(bld)     srcs = ['timers.cpp']     libs = ['WINMM']     incs = ['.']     bld(features=['cxx','cxxshlib'],         source=srcs,         includes=incs,         target='timers',,         use=libs,         ) 

In the future please provide your whole wscript and the stack trace so its easier to answer your question.



回答2:

I figured this out and the steps are as follows:

Added following check in the configure function in wscript file. This tells the script to check for the given library file (libmongoclient in this case), and we store the results of this check in MONGOCLIENT.

conf.check_cfg(package='libmongoclient', args=['--cflags', '--libs'], uselib_store='MONGOCLIENT', mandatory=True) 

After this step, we need to add a package configuration file (.pc) into /usr/local/lib/pkgconfig path. This is the file where we specify the paths to lib and headers. Pasting the content of this file below.

prefix=/usr/local  libdir=/usr/local/lib  includedir=/usr/local/include/mongo  Name: libmongoclient  Description: Mongodb C++ driver  Version: 0.2  Libs: -L${libdir} -lmongoclient  Cflags: -I${includedir} 

Added the dependency into the build function of the sepcific program which depends on the above library (i.e. MongoClient). Below is an example.

mobility = bld( target='bin/mobility', features='cxx cxxprogram', source='src/main.cpp', use='mob-objects MONGOCLIENT', ) 

After this, run the configure again, and build your code.



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