【问题标题】:WAF - ntldd - Unable to link static system libraryWAF - ntldd - 无法链接静态系统库
【发布时间】:2014-05-09 05:09:49
【问题描述】:

熟悉 Unix 的人都知道ldd 程序。它列出了给定可执行文件的共享库依赖项。有一个名为 ntldd 的 Windows 克隆。

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

构建脚本有效。

我想,这是一个多么理想的小程序来测试WAF。

这是我认为可行的 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"],
    )

但是没有!

WAF 认为我从未告诉它为可执行文件链接静态库 imagehlp。

来自 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

请注意,它抱怨找不到MapAndLoad 和UnMapAndLoad;这两个函数都在imagehlp。

发生了什么事?

【问题讨论】:

    标签: c gcc build waf


    【解决方案1】:

    您应该使用stlib 字典键列出您想要链接的现有系统静态库(看起来use 仅用于引用您在同一Waf 构建中生成的其他项目)。

    # a C application
    ctx\
    (
        features  = ["c", "cprogram"],
        source    = "ntldd.c",
        target    = "ntldd",
        use       = ["_ntldd"],
        stlib     = ["imagehlp"],
    )
    

    我在section 10.3 of the Waf Book 中找到了这个。 API 文档没有帮助。

    【讨论】:

    • 其实你可以在use=中引用系统库,但是必须在configure中首先配置。在检查 imagehlp 时,我错过了 uselib_store 参数。
    猜你喜欢
    • 2017-09-11
    • 1970-01-01
    • 2020-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多