[英]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.