Reputation: 31
I am trying to build the hello_imgui_template with Cmake, but I am unable to proceed without it giving me hello_imgui/hello_imgui.h file not found
.
Just to try it out I manually inserted the absolute paths in every #include
so that at least it changes the error, which it did.
Now the hello_world.main.cpp complies with fatal error: too many errors emitted, stopping now [-ferror-limit=] 8 warnings and 20 errors generated
of which several are
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/dpi_aware.h:123:1: error: unknown type name 'ImVec2'
ImVec2 EmToVec2(float x, float y);
also /Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui_logger.h:27:29: error: use of undeclared identifier 'ImVec2'
.
I really do not understand where this error is coming from and how to resolve it.
My c_cpp_properties.json:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${default}",
"${workspaceFolder}/**",
"/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
Where you can see I already tried editing in Include path the folders
My settings.json:
{
"C_Cpp.default.compilerPath": "/usr/bin/clang++"
}
My hello_imgui.main.cpp:
#include "/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui.h"
int main(int , char *[])
{
auto guiFunction = []() {
ImGui::Text("Hello, "); // Display a simple label
HelloImGui::ImageFromAsset("world.jpg"); // Display a static image
if (ImGui::Button("Bye!")) // Display a button
// and immediately handle its action if it is clicked!
HelloImGui::GetRunnerParams()->appShallExit = true;
};
HelloImGui::Run(guiFunction, "Hello, globe", true);
return 0;
}
The CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(helloworld_with_helloimgui)
set(CMAKE_CXX_STANDARD 17)
# Build hello_imgui
# =================
# 1/ Option 1: if you added hello_imgui as a subfolder, you can add it to your project with:
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/hello_imgui)
add_subdirectory(external/hello_imgui)
endif()
# 2/ Option 2: simply fetch hello_imgui during the build
if (NOT TARGET hello_imgui)
message(STATUS "Fetching hello_imgui")
include(FetchContent)
FetchContent_Declare(hello_imgui GIT_REPOSITORY https://github.com/pthom/hello_imgui.git GIT_TAG master)
FetchContent_MakeAvailable(hello_imgui)
endif()
# 3/ Option 3: via vcpkg
# i/ You can install hello_imgui via vcpkg with:
# vcpkg install "hello-imgui[opengl3-binding,glfw-binding]"
# ii/ Then you can use it inside CMake with:
# find_package(hello-imgui CONFIG REQUIRED)
# Build your app
# ==============
hello_imgui_add_app(hello_world_ hello_world.main.cpp)
# hello_imgui_add_app is a helper function, similar to cmake's "add_executable"
# Usage:
# hello_imgui_add_app(app_name file1.cpp file2.cpp ...)
#
# Features:
# * It will automatically link the target to the required libraries (hello_imgui, OpenGl, glad, etc)
# * It will embed the assets (for desktop, mobile, and emscripten apps)
# * It will perform additional customization (app icon and name on mobile platforms, etc)
# Now you can build your app with
# mkdir build && cd build && cmake .. && cmake --build .
If someone is curious, yes I already build the app with the command you see above, but the errors persist.
The build log is:
[proc] Esecuzione del comando: /opt/homebrew/bin/cmake --version
[proc] Esecuzione del comando: /opt/homebrew/bin/cmake -E capabilities
[variant] Il nuovo set di varianti è stato caricato
[kit] I 1 kit sono stati caricati da /Users/alessandrodoro/.local/share/CMakeTools/cmake-tools-kits.json
[proc] Il comando: ninja --version non è riuscito con errore: Error: spawn ninja ENOENT
[proc] Il comando: ninja-build --version non è riuscito con errore: Error: spawn ninja-build ENOENT
[main] Configurazione del progetto: hello_imgui_template-1
[proc] Esecuzione del comando: /opt/homebrew/bin/cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE --no-warn-unused-cli -S/Users/alessandrodoro/hello_imgui_template-1 -B/Users/alessandrodoro/hello_imgui_template-1/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- HELLOIMGUI_WITH_TEST_ENGINE=OFF
[cmake] -- Library hello_imgui
[cmake] -- Added installable dependency stb_hello_imgui, HELLOIMGUI_INSTALLABLE_DEPENDENCIES=stb_hello_imgui
[cmake] -- HELLOIMGUI_USE_IMGUI_CMAKE_PACKAGE is OFF
[cmake] -- Added installable dependency imgui, HELLOIMGUI_INSTALLABLE_DEPENDENCIES=stb_hello_imgui;imgui
[cmake] -- HelloImGui: downloading and building freetype
[cmake] CMake Deprecation Warning at build/_deps/freetype-src/CMakeLists.txt:113 (cmake_minimum_required):
[cmake] Compatibility with CMake < 3.5 will be removed from a future version of
[cmake] CMake.
[cmake]
[cmake] Update the VERSION argument <min> value or use a ...<max> suffix to tell
[cmake] CMake that the project does not need compatibility with older versions.
[cmake]
[cmake]
[cmake] -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
[cmake] CMake Warning at build/_deps/freetype-src/builds/cmake/FindHarfBuzz.cmake:99 (message):
[cmake] Required version (2.0.0) is higher than found version ()
[cmake] Call Stack (most recent call first):
[cmake] build/_deps/freetype-src/CMakeLists.txt:258 (find_package)
[cmake]
[cmake]
[cmake] -- Could NOT find BrotliDec (missing: BROTLIDEC_INCLUDE_DIRS BROTLIDEC_LIBRARIES)
[cmake] CMake Deprecation Warning at build/_deps/lunasvg-src/CMakeLists.txt:1 (cmake_minimum_required):
[cmake] Compatibility with CMake < 3.5 will be removed from a future version of
[cmake] CMake.
[cmake]
[cmake] Update the VERSION argument <min> value or use a ...<max> suffix to tell
[cmake] CMake that the project does not need compatibility with older versions.
[cmake]
[cmake]
[cmake] -- Added installable dependency lunasvg, HELLOIMGUI_INSTALLABLE_DEPENDENCIES=stb_hello_imgui;imgui;lunasvg
[cmake] -- Added installable dependency hello_imgui, HELLOIMGUI_INSTALLABLE_DEPENDENCIES=stb_hello_imgui;imgui;lunasvg;hello_imgui
[cmake] -- HelloImGui: using nlohmann_json from external/nlohmann_json
[cmake] -- Added installable dependency nlohmann_json, HELLOIMGUI_INSTALLABLE_DEPENDENCIES=stb_hello_imgui;imgui;lunasvg;hello_imgui;nlohmann_json
[cmake] -- Found system lib glfw3
[cmake] -- Added installable dependency glad, HELLOIMGUI_INSTALLABLE_DEPENDENCIES=stb_hello_imgui;imgui;lunasvg;hello_imgui;nlohmann_json;glad
[cmake] --
[cmake] ===========================================================================
[cmake] Hello ImGui build options:
[cmake] ===========================================================================
[cmake] Platform Backend(s): HELLOIMGUI_USE_GLFW3
[cmake] Rendering Backend(s): HELLOIMGUI_HAS_OPENGL3
[cmake] ---------------------------------------------------------------------------
[cmake] Options:
[cmake] HELLOIMGUI_USE_FREETYPE: ON (Use target freetype)
[cmake] HELLOIMGUI_WITH_TEST_ENGINE: OFF
[cmake] BUILD_DEMOS - TESTS - DOCS: OFF - OFF - OFF
[cmake] ---------------------------------------------------------------------------
[cmake] ImGui:
[cmake] Build ImGui: ON
[cmake] ImGui source dir: external/imgui
[cmake] ---------------------------------------------------------------------------
[cmake] nlohmann_json: Using external/nlohmann_json
[cmake] ---------------------------------------------------------------------------
[cmake] OpenGL - use glad loader ON
[cmake] ---------------------------------------------------------------------------
[cmake] Platform Backend(s):
[cmake] Glfw: Use system Library
[cmake] ---------------------------------------------------------------------------
[cmake] macOS:
[cmake] HELLOIMGUI_MACOS_NO_BUNDLE: OFF
[cmake] ===========================================================================
[cmake] -- Configuring done (5.0s)
[cmake] -- Generating done (0.2s)
[cmake] -- Build files have been written to: /Users/alessandrodoro/hello_imgui_template-1/build
I cannot share the header file where I get the errors (dpi_aware.h)as the body of the text reaches well over 30000 characters, but you can find it in https://github.com/pthom/hello_imgui.git
The complete log after compiling is:
(base) alessandrodoro@MBP-Alessandro hello_imgui_template-1 % cd "/Users/alessandrodoro/hello_imgui_template-1/" && g++ tempCodeRunnerFile.cpp -o
tempCodeRunnerFile && "/Users/alessandrodoro/hello_imgui_template-1/"tempCodeRunnerFile
In file included from tempCodeRunnerFile.cpp:1:
In file included from /Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui.h:9:
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/dpi_aware.h:59:31: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
float dpiWindowSizeFactor = 0.0f;
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/dpi_aware.h:70:30: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
float fontRenderingScale = 0.0f;
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/dpi_aware.h:75:35: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
bool onlyUseFontDpiResponsive = false;
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/dpi_aware.h:85:37: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
int fontOversampleH = 0; // Default is 2 in ImFontConfig
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/dpi_aware.h:86:37: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
int fontOversampleV = 0; // Default is 1 in ImFontConfig
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/dpi_aware.h:123:1: error: unknown type name 'ImVec2'
ImVec2 EmToVec2(float x, float y);
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/dpi_aware.h:124:1: error: unknown type name 'ImVec2'
ImVec2 EmToVec2(ImVec2 v);
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/dpi_aware.h:124:17: error: unknown type name 'ImVec2'
ImVec2 EmToVec2(ImVec2 v);
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/dpi_aware.h:132:1: error: unknown type name 'ImVec2'
ImVec2 PixelsToEm(ImVec2 pixels);
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/dpi_aware.h:132:19: error: unknown type name 'ImVec2'
ImVec2 PixelsToEm(ImVec2 pixels);
^
In file included from tempCodeRunnerFile.cpp:1:
In file included from /Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui.h:11:
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui_assets.h:31:17: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
void * data = nullptr;
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui_assets.h:32:21: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
size_t dataSize = 0;
^
In file included from tempCodeRunnerFile.cpp:1:
In file included from /Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui.h:15:
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui_logger.h:17:10: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]
enum class LogLevel
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui_logger.h:27:17: error: unknown type name 'ImVec2'
void LogGui(ImVec2 size=ImVec2(0.f, 0.f));
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui_logger.h:27:29: error: use of undeclared identifier 'ImVec2'
void LogGui(ImVec2 size=ImVec2(0.f, 0.f));
^
In file included from tempCodeRunnerFile.cpp:1:
In file included from /Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui.h:17:
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/image_from_asset.h:29:50: error: unknown type name 'ImVec2'
void ImageFromAsset(const char *assetPath, const ImVec2& size = ImVec2(0, 0),
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/image_from_asset.h:29:65: error: use of undeclared identifier 'ImVec2'
void ImageFromAsset(const char *assetPath, const ImVec2& size = ImVec2(0, 0),
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/image_from_asset.h:30:27: error: unknown type name 'ImVec2'
const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1),
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/image_from_asset.h:30:41: error: use of undeclared identifier 'ImVec2'
const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1),
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/image_from_asset.h:30:61: error: unknown type name 'ImVec2'
const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1),
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/image_from_asset.h:30:75: error: use of undeclared identifier 'ImVec2'
const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1),
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/image_from_asset.h:31:27: error: unknown type name 'ImVec4'
const ImVec4& tint_col = ImVec4(1,1,1,1),
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/image_from_asset.h:31:46: error: use of undeclared identifier 'ImVec4'
const ImVec4& tint_col = ImVec4(1,1,1,1),
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/image_from_asset.h:32:27: error: unknown type name 'ImVec4'
const ImVec4& border_col = ImVec4(0,0,0,0));
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/image_from_asset.h:32:48: error: use of undeclared identifier 'ImVec4'
const ImVec4& border_col = ImVec4(0,0,0,0));
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/image_from_asset.h:36:56: error: unknown type name 'ImVec2'
bool ImageButtonFromAsset(const char *assetPath, const ImVec2& size = ImVec2(0, 0),
^
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/image_from_asset.h:36:71: error: use of undeclared identifier 'ImVec2'
bool ImageButtonFromAsset(const char *assetPath, const ImVec2& size = ImVec2(0, 0),
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
8 warnings and 20 errors generated.
The structure of my files are:
> .vscode
> assets
> build
> external
> build
> hello_imgui
>src
>hello_imgui
... here are the .h files
CmakeLists.txt
hello_world.main.cpp
I cannot resolve the #include
problems I'm facing and when I use brute force to resolve this error the ImVec2
error appears.
Edit: Error Log -
(base) alessandrodoro@MBP-Alessandro hello_imgui_template-1 % cmake --build build
[ 19%] Built target lunasvg
[ 21%] Built target stb_hello_imgui
[ 48%] Built target freetype
[ 53%] Built target imgui
[ 54%] Built target glad
[ 55%] Building CXX object external/hello_imgui/src/hello_imgui/CMakeFiles/hello_imgui.dir/impl/dpi_aware.cpp.o
In file included from /Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/impl/dpi_aware.cpp:2:
In file included from /Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/../hello_imgui/dpi_aware.h:3:
In file included from /Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui.h:25:
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/runner_params.h:250:5: error: unknown type name 'DpiAwareParams'
DpiAwareParams dpiAwareParams;
^
1 error generated.
make[2]: *** [external/hello_imgui/src/hello_imgui/CMakeFiles/hello_imgui.dir/impl/dpi_aware.cpp.o] Error 1
make[1]: *** [external/hello_imgui/src/hello_imgui/CMakeFiles/hello_imgui.dir/all] Error 2
make: *** [all] Error 2
(base) alessandrodoro@MBP-Alessandro hello_imgui_template-1 %
* History restored
(base) alessandrodoro@MBP-Alessandro hello_imgui_template-1 % cmake --build build
[ 19%] Built target lunasvg
[ 21%] Built target stb_hello_imgui
[ 48%] Built target freetype
[ 53%] Built target imgui
[ 54%] Built target glad
[ 55%] Building CXX object external/hello_imgui/src/hello_imgui/CMakeFiles/hello_imgui.dir/impl/dpi_aware.cpp.o
In file included from /Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/impl/dpi_aware.cpp:2:
In file included from /Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/../hello_imgui/dpi_aware.h:3:
In file included from /Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/hello_imgui.h:25:
/Users/alessandrodoro/hello_imgui_template-1/external/hello_imgui/src/hello_imgui/runner_params.h:250:5: error: unknown type name 'DpiAwareParams'
DpiAwareParams dpiAwareParams;
^
1 error generated.
make[2]: *** [external/hello_imgui/src/hello_imgui/CMakeFiles/hello_imgui.dir/impl/dpi_aware.cpp.o] Error 1
make[1]: *** [external/hello_imgui/src/hello_imgui/CMakeFiles/hello_imgui.dir/all] Error 2
make: *** [all] Error 2
Upvotes: 1
Views: 185
Reputation: 31020
Ignoring your failures with the VSCode file runner (seriously, don't use that), it looks like you missed the hint in your CMakeLists.txt. You can build your CMake project using
cmake --build build
and run it by running
build/hello_world_
Upvotes: 2