1

首先,我使用的是 premake5 和 VisualStudio 2013。请不要因为那个而跳到我身上(因为 premake5 仍然是 alpha 版本)。我已经搜索过但找不到答案,而不是真正有效的答案。

我需要使用 premake 将静态库嵌入到自定义静态库中。我在更新库后转换了一些旧代码,只想将自定义库与应用程序链接起来。我不想将自定义库和它处理的所有其他库链接到应用程序配置。premake5 的其他所有功能都运行良好。

我可以使用链接指令将其链接到应用程序,例如:links { "SDL2", "SDL2main", "SDL2_image" }

这适用于静态库的正常包含,但我需要一种方法将这些示例库嵌入到自定义静态库中。

我可以将 premake 创建的结果项目文件放入 Visual Studio 并手动修改项目以按照我需要的方式添加库,但我不想每次需要重新生成项目时都必须这样做。

我需要的结果是 premake 将以下 XML 生成到项目 xml 文件中的一种方式:

    <ItemGroup>
    <Library Include="..\deps\SDL2\lib\x86\SDL2.lib">
      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Win64|x64'">true</ExcludedFromBuild>
    </Library>
    <Library Include="..\deps\SDL2\lib\x86\SDL2main.lib">
        <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Win64|x64'">true</ExcludedFromBuild>
    </Library>
    <Library Include="..\deps\SDL2_image\lib\x86\SDL2_image.lib" />
        <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Win64|x64'">true</ExcludedFromBuild>
    </Library>
  </ItemGroup>

这是在 Visual Studio 中手动编辑项目的结果。我从 x64 构建中添加了库的排除,因为最终我还必须使用这些库的 x64 版本。如果我严重忽略了某些事情,那就太好了,但我需要能够让它发挥作用。

我在这里忽略了一些非常简单的事情吗?

4

1 回答 1

1

Premake 不支持开箱即用地将静态库链接在一起,因为这种行为不能移植到其他工具集。但是,您可以在项目脚本中安装一个小扩展以使其工作:

---
-- Allow static library projects to link in their dependencies. Visual Studio
-- doesn't support this out of the box, so I need to manually add items to
-- the list of additional dependencies.
---

local p = premake

function myAdditionalStaticDependencies(cfg)
    local links = p.config.getlinks(cfg, "siblings", "fullpath")
    if #links > 0 then
        links = path.translate(table.concat(links, ";"))
        p.x('<AdditionalDependencies>%s;%%(AdditionalDependencies)</AdditionalDependencies>', links)
    end
end

p.override(p.vstudio.vc2010.elements, "lib", function(base, cfg, explicit)
    local calls = base(cfg, explicit)
    if cfg.kind == p.STATICLIB then
        table.insert(calls, myAdditionalStaticDependencies)
    end
    return calls
end)
于 2015-09-03T18:38:04.983 回答