Imgui: glfw dependency not needed for SDL examples

Created on 14 Jul 2017  路  4Comments  路  Source: ocornut/imgui

Hi.

I like ImGui being free of unnecessary dependencies. But the Makefile of the SDL samples (gl2, gl3) hint that I need that lib.

In fact, they work nicely without as SDL provides all it needs.

Without changing anything in the source codes, and without installing glfw, I compiled and launched the samples with this single command-line:

gl3-example:
g++ -o sdl_opengl3_example -I../../ -I../libs/gl3w -I/usr/include/SDL2 -Wall -Wformat main.cpp imgui_impl_sdl_gl3.cpp ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../libs/gl3w/GL/gl3w.c -lSDL2 -ldl -lwayland-client -lasound -lGL -lpthread

gl2-example:

g++ -o sdl_opengl2_example -I../../ -I../libs/gl3w -I/usr/include/SDL2 -Wall -Wformat main.cpp imgui_impl_sdl.cpp ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../libs/gl3w/GL/gl3w.c -lSDL2 -ldl -lwayland-client -lasound -lGL -lpthread

sorry I don't know makefiles so I could not provide a patch/fix for the makefile.

Would be cool to remove the dependencies to make it easier to build.

I used dynamic linking because SDL2 wants asound lib, and my Debian does not provide a static-link asound lib. only an .so

(note that I had to add -I/usr/include/SDL2 . why??)

build tools

Most helpful comment

Added this project to Travis and made it work for both Linux and OSX. Should be all fixed!

All 4 comments

@acda

Looks like you're right : either glfw is used, or SDL2
About the SDL2 use : the advised way is to use sdl2-config --cflags --libs

Last, about the -I /usr/include/SDL2 is probably because there is #include and it the above -I is not used, the preprocessor will never resolve the #include . BTW, sdl2-config --cflagssolves this issue.

@ocornut

As solution (tested on my machine), I'd suggest what follows :

diff --git a/examples/sdl_opengl3_example/Makefile b/examples/sdl_opengl3_example/Makefile
index e4aee57..a237c1d 100644
--- a/examples/sdl_opengl3_example/Makefile
+++ b/examples/sdl_opengl3_example/Makefile
@@ -22,9 +22,9 @@ UNAME_S := $(shell uname -s)

 ifeq ($(UNAME_S), Linux) #LINUX
        ECHO_MESSAGE = "Linux"
-       LIBS = -lGL `pkg-config --static --libs glfw3`
+       LIBS = -lGL -ldl `sdl2-config --libs`

-       CXXFLAGS = -I../../ -I../libs/gl3w `pkg-config --cflags glfw3`
+       CXXFLAGS = -I../../ -I../libs/gl3w `sdl2-config --cflags`
        CXXFLAGS += -Wall -Wformat
        CFLAGS = $(CXXFLAGS)
 endif

My 2 cents

I forgot : please notice the additional:
-ldl
Without it - on my machine, needs to be confirmed- I got a build issue saying :
/usr/bin/ld: ../libs/gl3w/GL/gl3w.o: undefined symbol reference 芦dlclose@@GLIBC_2.2.5禄
//lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Well, looks like that Makefile that I merged recently was wrong (I didn't test it) because the PR only tested for MINGW and not the other blocks.

It comes from:
https://github.com/ocornut/imgui/pull/1209

Could somebody try and test the Mac block?

I am going to add those samples projects on the Travis build setup too.

Added this project to Travis and made it work for both Linux and OSX. Should be all fixed!

Was this page helpful?
0 / 5 - 0 ratings