Question

I'm trying to build my project. I have libuv already compiled in ./libuv as libuv.a (so the relative path to the library is ./libuv/libuv.a).

When I use clang directly, it works:

$ clang++ src/**/*.cpp -std=c++11 -L./libuv -luv -I./libuv/include -I./include

However, when I build using Waf, I get a linker error indicating that ld can't find libuv:

$ CXX=clang++ ./waf configure && ./waf build
...
[2/2] cxxprogram: build/src/uv/loop.cpp.1.o -> build/a.out
/usr/bin/ld.gold: error: cannot find -luv
...
Build failed
 -> task in 'a.out' failed (exit status 1): 
    {task 140349441167440: cxxprogram loop.cpp.1.o -> a.out}
['clang++', 'src/uv/loop.cpp.1.o', '-o', '~/sf/build/a.out', '-Wl,-Bstatic', '-Llibuv', '-luv', '-Wl,-Bdynamic']

My wscript is fairly simple:

def options(opt):
    opt.load('compiler_cxx')

def configure(conf):
    conf.load('compiler_cxx')

def build(bld):
    bld.program(
        source=bld.path.ant_glob('src/**/*.cpp'),
        target='a.out',

        includes=['include', 'libuv/include'],
        stlibpath=['libuv'],
        stlib=['uv'],

        cxxflags=['-std=c++11']
    )

Why can't ld find the library when invoked through Waf, while everything works fine when not using Waf (I suspect it has to do with the -Wl,-Bstatic flag, but I'm not sure)?

Was it helpful?

Solution

Specifying the full path to the library's directory makes it work:

stlib=['uv'],
stlibpath=[os.path.join(os.getcwd(), 'libuv')],

Oh, linkers are such terrible programs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top