Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imgui_widgets.cpp missing header inclusion? (Linux) #2054

Closed
ebachard opened this issue Aug 31, 2018 · 6 comments
Closed

imgui_widgets.cpp missing header inclusion? (Linux) #2054

ebachard opened this issue Aug 31, 2018 · 6 comments

Comments

@ebachard
Copy link

ebachard commented Aug 31, 2018

Hello,

After a resync with Dear ImGui 1.64, I got a build breakage on Linux (x86_64, SDL2 + OpenGL3)

Shorted log says " intptr_t was not declared in this scope" (see the full log at the bottom)

Same issue tested with both:

  • gcc and g++ 5.4.0 (gcc --version says : gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
  • gcc-7 and g++-7 (g++ --version says g++-7.1 Ubuntu 7.1.0-10ubuntu1~16.04.york0) 7.1.0).

In the full log, you'll see that I'm using:

  • -std=c++11 option with g++
  • -std=c99 option building the C files

Same breakage occurs with -std=c99 (gcc) and g++ -std=c++11, -std=c++14 and -std=c++17 options.

Workaround : add #include <stdint.h> in imgui_widgets.cpp, solves the issue, but trying to figure out what exactly happened lead me in imgui.h, where there is the following macro (see below).

#if defined(_MSC_VER) && !defined(__clang__)
typedef signed   __int64    ImS64;  // 64-bit signed integer (pre and post C++11 with Visual Studio)
typedef unsigned __int64    ImU64;  // 64-bit unsigned integer (pre and post C++11 with Visual Studio)
#elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100)
#include <stdint.h>
typedef int64_t             ImS64;  // 64-bit signed integer (pre C++11)
typedef uint64_t            ImU64;  // 64-bit unsigned integer (pre C++11)
#else

BTW : shouldn't it be 201100L ?

In fact, I'd love to keep Dear ImGui source code unmodified, and build it directly (no patch, to simplify miniDart maintainability).

Searching a bit, I found one interesting link : https://developercommunity.visualstudio.com/content/problem/120156/-cplusplus-macro-still-defined-as-pre-c11-value.html

And after some tries, and FYI, what works for me is :

diff --git a/imgui.h b/imgui.h
index 97f79a8..5dc4202 100644
--- a/imgui.h
+++ b/imgui.h
@@ -122,10 +122,10 @@ typedef unsigned int        ImU32;  // 32-bit unsigned integer (often used to st
 typedef signed   __int64    ImS64;  // 64-bit signed integer (pre and post C++11 with Visual Studio)
 typedef unsigned __int64    ImU64;  // 64-bit unsigned integer (pre and post C++11 with Visual Studio)
 #elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100)
-#include <stdint.h>
 typedef int64_t             ImS64;  // 64-bit signed integer (pre C++11)
 typedef uint64_t            ImU64;  // 64-bit unsigned integer (pre C++11)
 #else
+#include <stdint.h>
 typedef signed   long long  ImS64;  // 64-bit signed integer (post C++11)
 typedef unsigned long long  ImU64;  // 64-bit unsigned integer (post C++11)
 #endif

Question : is there a problem for you to include stdint.h everywhere ? Most of linux distributions provide c++11 and there are probably guards in stdint.h imho, but I can be wrong.

Waiting for your opinion :-)

Last but not least, the full log:

$ make
rm -rf *.o build/miniDart build/miniDart_s build/_s build/miniDart_debug build/miniDart  build/miniDart.exe build/miniDart_debug.exe _0.9.09_yuv2rgb_builds
rm -rf build/dbg*.dSYM
rm -rf miniDart_0.9.09_yuv2rgb_builds
echo Fichiers binaires supprimés.
Fichiers binaires supprimés.
gcc -O3 -march=native -mtune=native -Wall -fPIC -std=c99 -DBUILDING_LINUX_VERSION -DBUILDING_FRENCH  -D__Linux -DNATIVE_BUILD  -DHIGH_DEFINITION_CAPTURE -c -I./inc -I./localization -I./src/3rdparty/imgui -I./src/3rdparty/imgui/gl3w -I./src/3rdparty/stb -I./src/3rdparty/nativefiledialogs -I./src/3rdparty/tinyxml2/src -I./fonts/Icons/FontAwesome -I./src/3rdparty/yuv2rgb -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/mirclient -I/usr/include/mircore -I/usr/include/mircookie -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -Wall -fPIC -std=c99 -DBUILDING_LINUX_VERSION -DBUILDING_FRENCH  -D__Linux -DNATIVE_BUILD  -DHIGH_DEFINITION_CAPTURE  src/3rdparty/nativefiledialogs/nfd_common.c src/3rdparty/nativefiledialogs/nfd_gtk.c src/3rdparty/yuv2rgb/yuv_rgb.c src/3rdparty/yuv2rgb/test_yuv_rgb.c
g++ -O3 -march=native -mtune=native  -I./inc -I./localization -I./src/3rdparty/imgui -I./src/3rdparty/imgui/gl3w -I./src/3rdparty/stb -I./src/3rdparty/nativefiledialogs -I./src/3rdparty/tinyxml2/src -I./fonts/Icons/FontAwesome -I./src/3rdparty/yuv2rgb -Wall -fPIC -std=c++11 -DBUILDING_LINUX_VERSION -DBUILDING_FRENCH  -D__Linux -DNATIVE_BUILD  -DHIGH_DEFINITION_CAPTURE  -c -lm -lGL -ldl `pkg-config opencv --cflags --libs` -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/mirclient -I/usr/include/mircore -I/usr/include/mircookie -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -I/usr/local/include -L/usr/local/lib -lavutil -lavformat -lavcodec -lavfilter -lswscale -lswresample  -lSDL2_image-2.0 -lSDL2_ttf -I/usr/include/SDL2 -D_REENTRANT -L/usr/lib/x86_64-linux-gnu -lSDL2 src/setlabel.cpp src/capturedev.cpp src/resetCaptureDev.cpp src/sdl_utils.cpp src/input.cpp src/timer.cpp src/colors.cpp src/videoreader.cpp src/open_file_dialog.cpp src/imgui_helpers.cpp src/application.cpp src/surface.cpp src/helpers.cpp src/pick_folder.cpp src/main.cpp src/3rdparty/nativefiledialogs/nfd_win.cpp src/3rdparty/imgui/imgui_tabs.cpp src/3rdparty/imgui/imgui_draw.cpp src/3rdparty/imgui/imgui_widgets.cpp src/3rdparty/imgui/imgui_impl_opengl3.cpp src/3rdparty/imgui/imgui_impl_sdl.cpp src/3rdparty/imgui/imgui.cpp src/3rdparty/imgui/imgui_demo.cpp src/3rdparty/imgui/gl3w/gl3w.c
src/3rdparty/imgui/imgui_widgets.cpp: In function ‘bool ImGui::Combo(const char*, int*, bool (*)(void*, int, const char**), void*, int, int)’:
src/3rdparty/imgui/imgui_widgets.cpp:1237:24: error: ‘intptr_t’ was not declared in this scope
         PushID((void*)(intptr_t)i);
                        ^
src/3rdparty/imgui/imgui_widgets.cpp: In function ‘bool ImGui::CollapsingHeader(const char*, bool*, ImGuiTreeNodeFlags)’:
src/3rdparty/imgui/imgui_widgets.cpp:4763:47: error: ‘intptr_t’ was not declared in this scope
         if (CloseButton(window->GetID((void*)(intptr_t)(id+1)), button_center, button_radius))
                                               ^
/home/eric/Devel/minidart/miniDart_0.99/Makefile:311 : la recette pour la cible « C++_FILES » a échouée
make: *** [C++_FILES] Erreur 1


@ocornut ocornut changed the title [Linux] [1.64] [widget.cpp] Missing header inclusion ? imgui_widgets.cpp missing header inclusion? (Linux) Aug 31, 2018
@ebachard
Copy link
Author

git pull + a new build => everything is ok : issue fixed, thanks 👍

The issue can be closed.

@ocornut
Copy link
Owner

ocornut commented Aug 31, 2018

Thanks @ebachard for the detailed report.
As you pointed out I have fixed the issue in imgui_widgets.cpp with an include in there, matching the include used in the other imgui.cpp files.

I'm not sure to understand why your proposed patch is removing the #include <stdint.h> in one of the block however.

I wasn't aware of MSVC not actually defining __cplusplus to its proper value until recently, however as you noticed that code in imgui.h doesn't use the __cplusplus when the _MSC_VER path is taken anyway.

@ocornut ocornut closed this as completed Aug 31, 2018
@ebachard
Copy link
Author

ebachard commented Aug 31, 2018

@ocornut : in fact, I provided a diff (I thought you are used to read patch language ;-) ), but it was only a workaround description. Apologies if I was not clear.

@ocornut
Copy link
Owner

ocornut commented Aug 31, 2018

I read patch language, but your diff REMOVE the include from one of the block and add it to the other:

diff --git a/imgui.h b/imgui.h
index 97f79a8..5dc4202 100644
--- a/imgui.h
+++ b/imgui.h
@@ -122,10 +122,10 @@ typedef unsigned int        ImU32;  // 32-bit unsigned integer (often used to st
 typedef signed   __int64    ImS64;  // 64-bit signed integer (pre and post C++11 with Visual Studio)
 typedef unsigned __int64    ImU64;  // 64-bit unsigned integer (pre and post C++11 with Visual Studio)
 #elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100)
-#include <stdint.h>
 typedef int64_t             ImS64;  // 64-bit signed integer (pre C++11)
 typedef uint64_t            ImU64;  // 64-bit unsigned integer (pre C++11)
 #else
+#include <stdint.h>
 typedef signed   long long  ImS64;  // 64-bit signed integer (post C++11)
 typedef unsigned long long  ImU64;  // 64-bit unsigned integer (post C++11)
 #endif

To answer your question: "is there a problem for you to include stdint.h everywhere ?" any include in imgui.h that we can avoid is best to avoid.

@ebachard
Copy link
Author

If you prefer, and to avoid confusion, I can edit my post, and either remove the diff, or post one with the include outside ?

@ocornut
Copy link
Owner

ocornut commented Aug 31, 2018

There's no need as the include was added in the imgui_widgets.cpp file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants