编辑:我将主题更改为“将imgui集成为StaticLib|SharedLib”
目前,我在使用 Premake 作为构建系统将 Dear ImGui 作为 StaticLib 集成到我的 C++ 项目中时遇到了困难。
我已经集成了其他库,例如 GLFW(来自系统)、Glad、ViennaCL 和 Eigen,使用的模式与我为 Dear ImGui 申请的模式相同。当调用
useImGUI("opengl3", "GLFW")
时,编译成功。但是,当尝试将 ImGui 集成为单独的项目然后链接它时,会发生错误。
../src/main.cpp:10:10: fatal error: imgui.h: Nonexistent file or directory
10 | #include "imgui.h"
数据:
├── build
│ ├── Makefile
│ ├── MyProject.make
│ └── obj
├── cr.sh
├── include
│ └── test.hpp
├── premake.lua
├── README.md
├── src
│ ├── main.cpp
│ └── test.cpp
└── vendor
├── boost
├── eigen
├── glad
├── glfw
├── imgui
├── premake.lua
└── viennaCL
这个有效
dofile "vendor/premake.lua"
workspace "MeuProjeto"
-- foo
project "glad"
-- foo
project "MeuProjeto"
-- foo
useEigen()
useViennaCL()
useImGUI("opengl3", "glfw")
useGLFW()
useBoost('accumulators')
links { "glad" }
这不起作用
dofile "vendor/premake.lua"
workspace "MeuProjeto"
-- foo
project "glad"
-- foo
project "imgui"
kind "StaticLib"
language "C++"
useImGUI("opengl3", "glfw")
project "MeuProjeto"
-- foo
useEigen()
useViennaCL()
useGLFW()
links { "imgui" }
useBoost('accumulators')
links { "glad" }
这也不起作用
project "MeuProjeto"
-- foo
useEigen()
useViennaCL()
useGLFW()
useImGUI("opengl3", "glfw")
useBoost('accumulators')
links { "glad" }
function useImGUI(...)
local targets = {...}
for _, target in ipairs(targets) do
files {
"vendor/imgui/*.cpp",
"vendor/imgui/*.h",
"vendor/imgui/backends/imgui_impl_" .. target .. "*",
}
end
externalincludedirs { "vendor/imgui", "vendor/imgui/backends" }
end
我集成Imgui的方式是将其编译为lib,然后将该lib链接到主项目..
Imgui->Premake5.lua
project "ImGui"
kind "StaticLib"
language "C++"
staticruntime "off"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
files
{
"imconfig.h",
"imgui.h",
"imgui.cpp",
"imgui_draw.cpp",
"imgui_internal.h",
"imgui_tables.cpp",
"imgui_widgets.cpp",
"imstb_rectpack.h",
"imstb_textedit.h",
"imstb_truetype.h",
"imgui_demo.cpp"
}
......
然后将其链接到主项目工作区..
Workspace "apllication_workspace"
architecture "x64"
configurations
{
"Debug",
"Release",
"Dist"
}
include "vendor/imgui"
<other premake libs>
project "Application"
location " Application"
includedirs
{
"vendor/imgui",
<other libs>
}
links
{
"GLFW",
"Glad",
"ImGui"
}