1

太聪明了,我转向你。我正在尝试在 Ubuntu 16.04 LTS 上使用 LTO 和 Makefiles 和 Premake 5 构建一个 64 位静态库。

这是我正在使用的预制脚本:

-- premake5.lua
workspace "TestApp"

    location "TestApp" -- The directory of generated files - .sln, etc.
    configurations { "Debug", "Shipping" }
    platforms { "Linux_Static", "Linux_DLL" }
    targetdir "TestApp/Build/%{cfg.platform}/%{cfg.buildcfg}"
    objdir "TestApp/Build/"
    language "C++"

    architecture "x86_64"
    system "linux"

    filter "platforms:*Static"
        kind "StaticLib"

    filter "platforms:*DLL"
        kind "SharedLib"

    filter "kind:SharedLib"
        defines { "TEST_USE_DLL", "TEST_DLL_EXPORT" }

    -- Configuration filters
    configuration "*"
        flags { "ExtraWarnings", "C++14", "MultiProcessorCompile", "ShadowedVariables", "UndefinedIdentifiers" }

    configuration { "Debug" }
        symbols "On"
        defines { "TEST_DEBUG" }
        optimize "Debug"

    configuration "Shipping"
        defines { "TEST_SHIPPING" }
        optimize "Full"
        flags { "LinkTimeOptimization" }
        -- step 1
        --buildoptions "--plugin=$$(gcc --print-file-name=liblto_plugin.so)"

        -- step 2
        --toolset "clang"

        -- step 3
        --premake.tools.gcc.ar = "gcc-ar"

-- Projects
project "TestCore"
    location "TestApp/Core"
    files { "TestApp/Core/*.h", "TestApp/Core/*.cpp" }
    includedirs { "TestApp/" }


project "UnitTests"
    location "TestApp/Tests"
    kind "ConsoleApp"
    links { "TestCore" }
    objdir "TestApp/Tests/Build/"

    files { "TestApp/Tests/UnitTests/*.cpp", "TestApp/ThirdParty/Catch/*" }
    includedirs { "TestApp/ThirdParty/Catch", "TestApp/" }

    removedefines { "TEST_DLL_EXPORT" }

    filter { "platforms:*DLL", "system:linux" }
    runpathdirs { "Build/%{cfg.platform}/%{cfg.buildcfg}" }

“运送”是错误的配置。我还将整个测试项目捆绑在一个 zip中,以便您尝试重现该问题。

我在编译 TestCore 库时遇到的错误首先是plugin needed to handle lto object,然后是plugin /usr/lib/gcc/x86_64-linux-gnu/5/liblto_plugin.so is not licensed under a GPL-compatible license

我们对于它可以做些什么呢 ?如果您有任何知识使其适用于 GCC,请提供帮助。

解压缩 zip 后如何重现 GCC 错误:

  1. cd testBreaking
  2. premake5 gmake
  3. cd 测试应用程序
  4. make config=shipping_linux_static TestCore(得到“处理lto对象所需的插件”错误)
  5. 取消注释 premake5.lua 的第 37 行以获得“未在 GPL 兼容许可下获得许可”错误
  6. 取消注释第 43 行以使用 gcc-ar 而不是 ar,请注意它也不起作用
  7. 使用 gcc 选项 -fuse-linker-plugin 没有帮助

更多系统信息:

  • Ubuntu 16.04 LTS
  • gcc 5.4,制作 4.1,ar 2.26.1
  • 预制 5.0.0-alpha11

我让它与 Clang 一起工作。使用toolset clang运输配置(使用 LLVM 3.9),该库似乎编译得很好。我得到了另一个错误:

error adding symbols: Archive has no index; run ranlib to add one

我设法通过调用来解决这个问题ranlib Build/Linux_Static/Shipping/libTestCore.a --plugin /usr/lib/llvm-3.9/lib/LLVMgold.so,然后再次调用。

所以它使用 Clang 很痛苦。

我读到我可以为这种事情创建一个特定的预制工具集,因为建议用它们的gcc-对应物替换所有 gnu utils(例如,gcc-ar而不是ar),但是快速修补premake.tools.gcc.ar = "gcc-ar"没有结果,我不太确定它会有所帮助.

4

0 回答 0