如何使用Premake 5编译支持Linux LTO的库?

时间:2017-07-23 12:43:42

标签: c++ linux gcc premake lto

如此智慧,我转向你。我正在尝试在Ubuntu 16.04 LTS上使用带有Makefile和Premake 5的LTO构建一个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}" }

“送货”是错误的配置。我也bundled the whole test project in a 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一起使用,请提供帮助。

解压缩后,您将如何重现GCC错误:

  1. cd testBreaking
  2. premake5 gmake
  3. cd TestApp
  4. make config = shipping_linux_static TestCore(获取“处理lto对象所需的插件”错误)
  5. 取消注释premake5.lua的第37行,以获取“未获得GPL兼容许可证下的许可”错误
  6. 取消注释第43行使用gcc-ar而不是ar,注意它不起作用
  7. 使用gcc选项-fuse-linker-plugin无效
  8. 更多系统信息:

    • ubuntu 16.04 LTS
    • gcc 5.4,make 4.1,ar 2.26.1
    • premake 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很痛苦。

    我读到我可以create a specific premake toolset for this kind of thing,因为建议将所有gnu utils替换为gcc-对应物(例如gcc-ar而不是ar),但要快速修改premake.tools.gcc.ar = "gcc-ar"没有结果,我不确定它会有所帮助。

0 个答案:

没有答案