[英]WAF - ntldd - Unable to link static system library
Those familiar with Unix will know the ldd
program. 那些熟悉Unix的人会知道ldd
程序。 It lists shared library dependencies of a given executable. 它列出了给定可执行文件的共享库依赖关系。 There is a Windows clone called ntldd . Windows克隆名为ntldd 。
ntldd
has a very simple build script: ntldd
有一个非常简单的构建脚本:
gcc -fno-common -g -O3 -Wall -D_WIN32_WINNT=0x501 -c libntldd.c -o libntldd.o
ar rs libntldd.a libntldd.o
gcc -fno-common -g -O3 -Wall -L. ntldd.c -lntldd -limagehlp -o ntldd.exe
The build script works. 构建脚本起作用。
What an ideal little program to test WAF with, I thought. 我认为,这是测试WAF的理想小程序。
This is the wscript I thought would work: 这是我认为可以的wscript:
#! /usr/bin/env python
from waflib import Logs
APPNAME = "ntldd"
top = "."
out = "build"
def options(ctx):
ctx.load("compiler_c")
def configure(ctx):
ctx.load("compiler_c")
ctx.env.append_value("DEFINES", "_WIN32_WINNT=0x501")
if ctx.env.CC_NAME == "gcc":
ctx.env.CFLAGS = ["-g", "-fno-common", "-O3"]
ctx.check_cc(stlib = "imagehlp", linkflags = "-static")
def build(ctx):
ctx.logger = Logs.make_logger("build/build.log", "build")
ctx.env.BINDIR = "binaries"
ctx.env.LIBDIR = ctx.env.BINDIR
# a C library
ctx\
(
features = ["c", "cstlib"],
source = "libntldd.c",
target = "_ntldd",
)
# a C application
ctx\
(
features = ["c", "cprogram"],
source = "ntldd.c",
target = "ntldd",
use = ["_ntldd", "imagehlp"],
)
But NO! 但不是!
WAF reckons I never told it to link a static library, imagehlp
, for the executable. WAF认为我从没告诉过它为可执行文件链接静态库imagehlp
。
From the build.log: 从build.log中:
['D:\\mingw-builds\\x64-4.8.1-posix-seh-rev5\\mingw64\\bin\\gcc.exe', '-Wl,--enable-auto-import', 'ntldd.c.2.o', '-o', 'C:\\Users\\Administrator\\Documents\\Projects\\ntldd\\build\\ntldd.exe', '-Wl,-Bstatic', '-L.', '-l_ntldd', '-Wl,-Bdynamic']
err: .\lib_ntldd.a(libntldd.c.1.o): In function `BuildDepTree':
C:\Users\Administrator\Documents\Projects\ntldd\build/../libntldd.c:235: undefined reference to `__imp_MapAndLoad'
C:\Users\Administrator\Documents\Projects\ntldd\build/../libntldd.c:441: undefined reference to `__imp_UnMapAndLoad'
collect2.exe: error: ld returned 1 exit status
Note that it complains that it can't find MapAndLoad
and UnMapAndLoad
; 注意,它抱怨找不到MapAndLoad
和UnMapAndLoad
; both functions are in imagehlp
. 这两个功能都在imagehlp
。
What's going on? 这是怎么回事?
You should be using the stlib
dictionary key to list existing system static libraries that you want to link (it looks like use
is only for referencing other items you have produced in the same Waf
build). 你应该使用stlib
字典键列出要链接现有系统静态库(它看起来像use
仅供参考其他项目,你都在同一生产Waf
版本)。
# a C application
ctx\
(
features = ["c", "cprogram"],
source = "ntldd.c",
target = "ntldd",
use = ["_ntldd"],
stlib = ["imagehlp"],
)
I found this in section 10.3 of the Waf Book . 我在Waf Book的10.3节中找到了这一点。 The API docs were not helpful. API文档没有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.