[英]Premake undefined reference error on linux
不幸的是,我在 Ubuntu Linux 上遇到了 GLFW 問題,但在 Windows 上它運行良好。
我正在運行 premak5 gmake 和 make(這是我得到編譯器錯誤的地方)。
這是我得到的錯誤:
Creating ../bin-int/Debug-linux-x86_64/UiApp
UiApp.cpp
Linking UiApp
../bin/Debug-linux-x86_64/UiEngine/libUiEngine.so: undefined reference to `_glfwPlatformLoadModule'
../bin/Debug-linux-x86_64/UiEngine/libUiEngine.so: undefined reference to `_glfwSelectPlatform'
../bin/Debug-linux-x86_64/UiEngine/libUiEngine.so: undefined reference to `_glfwPlatformFreeModule'
../bin/Debug-linux-x86_64/UiEngine/libUiEngine.so: undefined reference to `_glfwPlatformGetModuleSymbol'
我認為這與鏈接器錯誤有關,但我找不到任何可靠的解決方案。 我通過將 pthread 和 dl 等其他引用錯誤添加到 premake 文件來修復它們。
我的文件結構:
這是我的預制文件:
主要預制:
workspace "UiModule"
architecture "x86_64"
startproject "UiApp"
configurations
{
"Debug",
"Release"
}
outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"
IncludeDir = {}
IncludeDir["GLFW"] = "vendor/GLFW/include"
IncludeDir["imgui"] = "vendor/imgui"
include "UiEngine/vendor/GLFW"
include "UiEngine/vendor/imgui"
include "UiEngine"
include "UiApp"
UiEngine Premake:
project "UiEngine"
kind "SharedLib"
language "C++"
cppdialect "C++17"
staticruntime "off"
targetdir ("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}")
objdir ("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}")
files
{
"src/**.h",
"src/**.cpp",
}
defines
{
"_CRT_SECURE_NO_WARNINGS",
"GLFW_INCLUDE_NONE"
}
includedirs
{
"src",
"%{IncludeDir.GLFW}",
"%{IncludeDir.imgui}"
}
filter "system:windows"
cppdialect "C++17"
staticruntime "On"
systemversion "latest"
links
{
"GLFW",
"imgui",
"opengl32.lib"
}
defines
{
"UI_PLATFORM_WINDOWS",
"UI_BUILD_DLL"
}
postbuildcommands
{
("{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/UiApp")
}
filter "system:linux"
cppdialect "C++17"
staticruntime "On"
systemversion "latest"
links
{
"GLFW",
"imgui",
}
defines
{
"_X11"
}
filter "configurations:Debug"
defines "HZ_DEBUG"
runtime "Debug"
symbols "on"
filter "configurations:Release"
defines "HZ_RELEASE"
runtime "Release"
optimize "on"
GLFW 預制:
project "GLFW"
kind "StaticLib"
language "C"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
includedirs { "include/" }
files
{
"include/GLFW/glfw3.h",
"include/GLFW/glfw3native.h",
"src/internal.h",
"src/platform.h",
"src/mappings.h",
"src/context.c",
"src/init.c",
"src/input.c",
"src/monitor.c",
"src/platform.c",
"src/vulkan.c",
"src/window.c",
"src/egl_context.c",
"src/osmesa_context.c",
"src/null_platform.h",
"src/null_joystick.h",
"src/null_init.c",
"src/null_monitor.c",
"src/null_window.c",
"src/null_joystick.c"
}
filter "system:linux"
pic "On"
systemversion "latest"
staticruntime "On"
files
{
"src/x11_init.c",
"src/x11_monitor.c",
"src/x11_window.c",
"src/xkb_unicode.c",
"src/posix_time.c",
"src/posix_thread.c",
"src/glx_context.c",
"src/egl_context.c",
"src/osmesa_context.c",
"src/linux_joystick.c"
}
defines
{
"_GLFW_X11"
}
filter "system:windows"
systemversion "latest"
staticruntime "On"
-- buildoptions{
-- "/MT"
-- }
files
{
"src/win32_init.c",
"src/win32_module.c",
"src/win32_joystick.c",
"src/win32_monitor.c",
"src/win32_time.h",
"src/win32_time.c",
"src/win32_thread.h",
"src/win32_thread.c",
"src/win32_window.c",
"src/wgl_context.c",
"src/egl_context.c",
"src/osmesa_context.c"
}
defines
{
"_GLFW_WIN32",
"_CRT_SECURE_NO_WARNINGS"
}
filter "configurations:Debug"
runtime "Debug"
symbols "On"
filter "configurations:Release"
runtime "Release"
optimize "On"
UiApp 預制:
project "UiApp"
kind "ConsoleApp"
language "C++"
targetdir ("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}")
objdir ("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}")
files
{
"src/**.h",
"src/**.cpp"
}
includedirs
{
"%{wks.location}/UiEngine/src",
"%{IncludeDir.imgui}",
"%{wks.location}/UiEngine/vendor/GLFW/include"
}
filter "system:linux"
cppdialect "C++17"
staticruntime "On"
systemversion "latest"
links
{
"dl",
"pthread",
"GLFW",
"imgui",
"UiEngine"
}
defines
{
"_X11"
}
filter "system:windows"
cppdialect "C++17"
staticruntime "On"
systemversion "latest"
defines
{
"UI_PLATFORM_WINDOWS"
}
filter "configurations:Debug"
defines "HZ_DEBUG"
symbols "On"
filter "configurations:Release"
defines "HZ_RELEASE"
optimize "On"
該問題是由 GLFW Premake.lua 文件中的文件丟失引起的。 編譯器找不到模塊,因為您沒有包含它。
這些模塊定義在 glfw/src/posix_module.c
`_glfwPlatformLoadModule'
`_glfwPlatformGetModuleSymbol'
`_glfwPlatformFreeModule'
並且這個模塊與 glfw/src/internal.h 和 glfw/src/platform.h 文件有關
`_glfwSelectPlatform'
在 linux 過濾器下將這些文件添加到 glfw 的 premake 文件中后,您就可以開始了。
最終的預制文件將如下所示;
filter "system:linux"
pic "On"
systemversion "latest"
staticruntime "On"
files
{
"src/x11_init.c",
"src/x11_monitor.c",
"src/x11_window.c",
"src/xkb_unicode.c",
"src/posix_time.c",
"src/posix_module.c", // Here
"src/posix_thread.c",
"src/glx_context.c",
"src/egl_context.c",
"src/osmesa_context.c",
}
我也將相關問題留給其他人。
對於其他缺少的庫,您可以查看 glfw github repo。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.