I am learning C++, and now I’m interested in learning GUIs. I tried working with wxWidgets but to no avail, as it throws wx/wxprec.h file not found
and I am unable to resolve it without including the absolute path in every #include
, which shouldn’t be necessary.
I am now trying with hello_imgui and I’m encountering the same problems, the path to #include
is not recognised unless I feed it myself to VSCode.
I am trying to build the hello_imgui_template with Cmake, but I understand very little about it and other than to follow to the letter the instructions provided in https://github.com/pthom/hello_imgui_template.git (cloning the hello_imgui in externals ecc.) I am unable to proceed without it giving me the same errors as before 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.
I already browsed a lot of the questions/answers here, but no solution seems to fit my case.
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 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.
Thanks to anyone that helps me understand