代码之家  ›  专栏  ›  技术社区  ›  Seon Il

C/C++项目不是在linux中构建的,而是在windows上构建和运行的

  •  0
  • Seon Il  · 技术社区  · 1 年前

    我有一个工作空间,里面有两个项目“Physx2D”和“SandBox”。第一个构建在共享库中,第二个构建在控制台应用程序中。SandBox需要Physx2D库,并设置为启动项目。

    我正在使用glfw3库,很高兴使用opengl函数。

    问题是该项目在windows上成功构建和运行,但在linux上失败了。 更详细地说,Physx2D库构建成功。这期杂志是在编辑SandBox之后发行的。它无法链接,并引发警告和多个链接错误,所有这些错误都表示Physx2D库中函数中“glad_******”的未定义引用。例如。

    警告:

    /usr/bin/ld: ../bin-int/Debug-linux-x86_64/SandBox/main.o warning: relocation against 'glad_glClearColor' in read-only section '.text._ZN7Physx2D6Window10FillScreenENS_5vec4IfEE[_ZN7Physx2D6Window10FillScreenENS_5tvec4IfEE]'
    

    错误:

    /usr/bin/ld: ../bin-int/Debug-linux-x86_64/SandBox/CA_gpu.o : in function 'Physx2D::Shader::use()':
    ..project_directory_of_sandbox ../Physx2D/src/renderer/shader.h:24: undefined reference to 'glad_glUseProgram'
    

    在链接过程中会抛出多个遵循相同模式的错误。

    我正在使用premake为gmake2生成项目makefile。

    这是我的预制脚本。

    workspace "Physx2D"
        architecture "x64"
    
        configurations {Debug","Release"}
    
        outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"
    
        project "Physx2D"
            location "Physx2D/"
            kind "SharedLib"
            language "C++"
            cppdialect "C++20"
            staticruntime "off"
    
            targetdir ("bin/" .. outputdir .. "/%{prj.name}")
            objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
    
            pchheader "pch.h"
            pchsource "%{prj.name}/src/pch.cpp"
    
            files {
                "%{prj.name}/libraries/**.*",
                "%{prj.name}/src/**.*"
            }
    
            includedirs {
                "%{prj.name}/libraries/include",
                "%{prj.name}/src"
            }
    
            libdirs {"%{prj.name}/libraries/lib_%{cfg.system}"}
    
            filter "system:windows"
                systemversion "latest"
                links {"glfw3", "opengl32"}
                postbuildcommands {"{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/SandBox"}
                defines {"PHSX2D_BUILD_DLL","PHSX2D_PLATFORM_WINDOWS"}
            
            filter "system:linux"
                systemversion "latest"
                buildoptions { "-fvisibility=hidden"}
                links {"glfw3", "GL"}
                postbuildcommands {"{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/SandBox"}
                defines { "PHSX2D_BUILD_DLL", "PHSX2D_PLATFORM_LINUX"}
    
            filter "configurations:Debug"
                defines {"PHSX2D_DEBUG", "PHSX2D_ASSERT_ENABLE"}
                symbols "on"
    
            filter "configurations:Release"
                defines {"PHSX2D_RELEASE", "PHSX2D_ASSERT_ENABLE"}
                optimize "on"
    
            filter "files:**/libraries/src/**.*"
                flags { "NoPCH" }
    
        project "SandBox"
            location "SandBox"
            kind "ConsoleApp"
            language "C++"
            cppdialect "C++20"
            staticruntime "off"
    
            targetdir ("bin/" .. outputdir .. "/%{prj.name}")
            objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
    
            files {
                "%{prj.name}/src/**.*",
                "%{prj.name}/res/**.*",
                "%{prj.name}/applications/**.*"
            }
    
            includedirs {
                "Physx2D/libraries/include",
                "Physx2D/src"
            }
    
            filter "system:windows"
                systemversion "latest"
                links {"Physx2D"}
                defines {"PHSX2D_PLATFORM_WINDOWS"}
        
        filter "system:linux"
                systemversion "latest"
                links {"Physx2D"}
                defines {"PHSX2D_PLATFORM_LINUX"}
            
        filter "configurations:Debug"
                defines {"PHSX2D_DEBUG", "PHSX2D_ASSERT_ENABLE"}
                symbols "on"
    
        filter "configurations:Release"
                defines {"PHSX2D_RELEASE", "PHSX2D_ASSERT_ENABLE"}
                optimize "on"
    

    我认为这个问题与项目设置无关。在快速查看了这些问题并进行了几次搜索后,我发现问题是在链接过程中找不到在greed.h中声明的函数的定义。我在Physx2D项目中的一个文件夹中有一个高兴的.c,我已经在premakescript的项目文件中包含了这个文件夹。此外,如果问题是为什么在构建Physx2D时没有产生任何问题。

    如果这不是问题所在,那么问题是什么以及如何解决。

    0 回复  |  直到 1 年前