[Qbs] Linking static lib with PkgConfig and --as-needed
dizygotheca
dizygotheca at ntlworld.com
Sun Jan 15 02:42:36 CET 2017
I'm struggling to link a static lib that depends on an external library.
Using Qbs 1.7.0 with Gcc 5.4.0 on Linux.
It seems to me that PkgConfigProbe should strip "-l" out of the libs so
that cpp.staticLibraries can be used. Disabling the as-needed shouldn't
be necessary.
Or am I missing something ?
example.qbs:
import qbs
import qbs.Probes as Probes
Project {
minimumQbsVersion: "1.6"
CppApplication {
files: "main.cpp"
Depends {name: "static"}
cpp.linkerFlags: "-v"
}
StaticLibrary {
name: "static"
Depends {name: "cpp"}
files: "lib.*"
Probes.PkgConfigProbe {id: ext; name: "libudev" }
Export {
// Q: How to export external link library dependancy ?
Depends {name: "cpp"}
// 1. Fails: Cannot find -l-ludev
// cpp.staticLibraries: ext.libs
// 2. Fails: linkerFlags appear before input artifacts
// so as-needed flag discards -ludev
// cpp.linkerFlags: ext.libs
// 3. Success, but only if we know lib name
// cpp.staticLibraries: ext.found ? "udev" : original
// 4. Success: work-around for wrong Qbs ordering
cpp.linkerFlags: ["--no-as-needed"].concat(ext.libs)
}
}
}
main.cpp:
#include "lib.h"
int main(int argc, char *argv[])
{
open();
}
lib.h:
void open();
lib.cpp:
#include "lib.h"
#include <libudev.h>
void open()
{
struct udev *udev = udev_new();
}
More information about the Qbs
mailing list