将 Dear ImGui 集成为分离项目时遇到问题;使用 Premake - 找不到“imgui.h”文件

问题描述 投票:0回答:1

编辑:我将主题更改为“将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

premake.lua(主要)

这个有效

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
c++ imgui premake
1个回答
0
投票

我集成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"
    }
© www.soinside.com 2019 - 2024. All rights reserved.