Clang linker “找不到 -lCocoa 的库”

Clang linker "Library not found for -lCocoa"

提问人:Edwin Carlsson 提问时间:9/30/2021 更新时间:9/30/2021 访问量:126

问:

《切尔诺斯游戏引擎》系列的基础上,我尝试为MacOSX而不是Windows编写系统。

在进行 GLFW、glad 和 ImGui 编译后,使用命令找不到 -lCocoa 库。由于我使用的是 IOKit、CoreVideo 和 OpenGL,因此我认为当我跨过这座桥时会出现相同的错误。ld: library not found for -lCocoa

在他的系列中,他使用了 premake5,这是工作区的 premake5,涵盖了静态库和引擎的使用示例应用程序。

workspace "Neurex"
    architecture "x64"

    configurations {"Debug", "Release", "Dist"}

startproject "NXSandbox"
outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"

includeDir = {}
includeDir["GLFW"] = "Neurex/vendor/GLFW/include"
includeDir["glad"] = "Neurex/vendor/glad/include"
includeDir["spdlog"] = "Neurex/vendor/spdlog/include"
includeDir["imgui"] = "Neurex/vendor/imgui"
includeDir["glm"] = "Neurex/vendor/glm"

group "Dependencies"
    include "Neurex/vendor/GLFW"
    include "Neurex/vendor/glad"
    include "Neurex/vendor/imgui"
group ""


project "Neurex"
    location "Neurex"
    kind "StaticLib"
    language "C++"
    cppdialect "C++17"
    staticruntime "on"

    targetdir ("bin/" .. outputdir .. "/%{prj.name}")
    objdir ("bin-int/" .. outputdir .. "/%{prj.name}")

    pchheader "nxpch.h"
    pchsource "Neurex/src/nxpch.cpp"

    files
    {
        "%{prj.name}/src/**.h",
        "%{prj.name}/src/**.cpp",
        "%{prj.name}/vendor/glm/glm/**.hpp",
        "%{prj.name}/vendor/glm/glm/**.inl"
    }

    includedirs
    {
        "%{prj.name}/src",
        "%{includeDir.spdlog}",
        "%{includeDir.GLFW}",
        "%{includeDir.glad}",
        "%{includeDir.imgui}",
        "%{includeDir.glm}"
    }


    filter "system:windows"
        systemversion "latest"

        links
        {
            "GLFW",
            "glad",
            "imgui",
            "opengl32.lib",
        }

        defines 
        {
            "NX_PT_WIN",
            "GLFW_INCLUDE_NONE",
            "_CRT_SECURE_NO_WARNINGS"
        }

    filter "system:macosx"
        links {
            "GLFW",
            "glad",
            "imgui",
            "Cocoa",
            "CoreVideo",
            "OpenGL",
            "IOKit"
        }

        defines {
            "NX_PT_OSX",
            "GLFW_INCLUDE_NONE",
            "_CRT_SECURE_NO_WARNINGS"   
        }

    filter "configurations:Debug"
        defines "NX_DEBUG"
        symbols "on"
        runtime "Debug"

    filter "configurations:Release"
        defines "NX_RELEASE"
        optimize "on"
        runtime "Release"

    filter "configurations:Dist"
        defines "NX_DIST"
        optimize "on"
        runtime "Release"



project "NXSandbox"
    location "NXSandbox"
    kind "ConsoleApp"
    language "C++"
    cppdialect "C++17"
    staticruntime "on"

    targetdir ("bin/" .. outputdir .. "/%{prj.name}")
    objdir ("bin-int/" .. outputdir .. "/%{prj.name}")

    files {
        "%{prj.name}/src/**.h",
        "%{prj.name}/src/**.cpp"
    }

    includedirs {
        "Neurex/vendor/spdlog/include",
        "Neurex/src",
        "Neurex/vendor",
        "%{includeDir.glm}",
    }

    links {
        "Neurex"
    }

    filter "system:windows"
        systemversion "latest"

        defines { "NX_PT_WIN" }

    filter "system:macosx"
        links {
            "Cocoa",
            "IOKit",
            "OpenGL",
            "CoreVideo"
        }

        defines {
            "NX_PT_OSX",
            "GLFW_INCLUDE_NONE",
            "_CRT_SECURE_NO_WARNINGS"
        }

    filter "configurations:Debug"
        defines "NX_DEBUG"
        symbols "On"
        runtime "Debug"

    filter "configurations:Release"
        defines "NX_RELEASE"
        optimize "On"
        runtime "Release"

    filter "configurations:Dist"
        defines "NX_DIST"
        optimize "On"
        runtime "Release"

静态库编译,沙箱提供链接问题。

我正在使用 Apple Clang v13.0.0、GNU Make 3.81、premake5.0.0 alpha 16。

macOS Clang Linker-Errors 预制

评论


答:

1赞 Edwin Carlsson 9/30/2021 #1

此问题已通过在框架的声明中添加“.framework”来解决:

Cocoa -> Cocoa.framework