ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.13k stars 10.3k forks source link

Can't build example on Linux invalid conversion from ‘void (*)()’ to ‘void*’ #411

Closed anthonybakermpls closed 8 years ago

anthonybakermpls commented 8 years ago

Trying to build the SDL opengl 3 example gives the following error:

$c++ sdl2-config --cflags -I ../.. -I ../libs/gl3w main.cpp imgui_impl_sdlgl3.cpp ../../imgui.cpp ../libs/gl3w/GL/gl3w.c sdl2-config --libs -lGL -o sdl2example ../libs/gl3w/GL/gl3w.c: In function ‘void_ getproc(const char)’: ../libs/gl3w/GL/gl3w.c:85:25: error: invalid conversion from ‘void (_)()’ to ‘void’ [-fpermissive] res = glXGetProcAddress((const GLubyte ) proc);

when i do -fpermissive:

$c++ -fpermissive sdl2-config --cflags -I ../.. -I ../libs/gl3w main.cpp imgui_impl_sdlgl3.cpp ../../imgui.cpp ../libs/gl3w/GL/gl3w.c sdl2-config --libs -lGL -o sdl2example
../libs/gl3w/GL/gl3w.c: In function ‘void_ getproc(const char)’: ../libs/gl3w/GL/gl3w.c:85:25: warning: invalid conversion from ‘void (_)()’ to ‘void’ [-fpermissive] res = glXGetProcAddress((const GLubyte ) proc); ^ /usr/bin/ld: /tmp/ccT2hT7y.o: undefined reference to symbol '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

Note the sdl_opengl_example/ works fine.

anthonybakermpls commented 8 years ago

Found the fix: http://askubuntu.com/questions/334884/while-compiling-truecrypt-i-get-undefined-reference-to-symbol-dlcloseglibc

need -ldl in your build command in the readme for this.

c++ -fpermissive sdl2-config --cflags -I ../.. -I ../libs/gl3w main.cpp imgui_impl_sdl_gl3.cpp ../../imgui*.cpp ../libs/gl3w/GL/gl3w.c sdl2-config --libs -lGL -ldl -o sdl2example

anthonybakermpls commented 8 years ago

Sorry I don't use github that much.. I guess I should leave this open with a suggested fix? I don't really even know how to do pull requests.

solution is to add -ldl to build command in your readme for this.

anthonybakermpls commented 8 years ago

So does this mean imgui doesn't support opengl 3 natively or what is going on with these function mappings that cause this problem in the first place?

ocornut commented 8 years ago

This code has nothing to do with imgui, gl3w is a wrapper to call OpenGL3 functions because modern OpenGL was designed to be tedious to use. (And thankfully libraries like gl3w are alleviating this pain)

ocornut commented 8 years ago

How does the makefile for the opengl3 example perform for you? It also use gl3w.c and I haven't heard of issue with it (but I don't use Linux myself).

ocornut commented 8 years ago

It looks like the problem is that gl3w.c is C not C++ and that code uses function pointer casting feature that is obsoleted in C++ and that file is compiled in C++ with the command-line.

ocornut commented 8 years ago

Could you remove the permissive flag and try adding a cast to void* on line 85 of gl3w.c see if it fixes it?

    res = glXGetProcAddress((const GLubyte *) proc);

change to

    res = (void*)glXGetProcAddress((const GLubyte *) proc);

Thanks! If that fixes it we should probably submit the fix to https://github.com/skaslev/gl3w

anthonybakermpls commented 8 years ago

If I put that explicit cast in there, remove -fpermissive and the -ldl switches, it doesn't error or warn on the assignment but it breaks on the dlclose symbol.

c++ sdl2-config --cflags -I ../.. -I ../libs/gl3w main.cpp imgui_impl_sdl_gl3.cpp ../../imgui*.cpp ../libs/gl3w/GL/gl3w.c sdl2-config --libs -lGL -o sdl2example
/usr/bin/ld: /tmp/ccuwMg9O.o: undefined reference to symbol '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

ocornut commented 8 years ago

Yeah, -ldl is still required by gl3w on Linux so I added that to the README and will add the cast now. Thanks!

anthonybakermpls commented 8 years ago

oh, and it looks like -fpermissive is required too with the -ldl. The makefile with the opengl3 example works perfectly I was comparing that before to try and figure out why that worked and this one didn't but I couldn't see anything.

anthonybakermpls commented 8 years ago

This looks like a really cool library. Thanks for sharing it.

ocornut commented 8 years ago

Sorry - can you clarify, even with the explicit cast -fpermissive is required? You are still getting the same error/warning with the cast? (I'd rather fix gl3w here than suggest that a flag is required).

(The Makefile will use regular C compiler for the .c file where the command-line uses C++ for both)

anthonybakermpls commented 8 years ago

Okay, with explicit cast in gl3w.c, -fpermissive is not needed but -ldl is required.

ocornut commented 8 years ago

Thanks, fixed now. By looking at gl3w it looks like they have actually fixed the code in the recent versions and I'm not up to date there because I just grabbed a pregenerated gl3w.c from somewhere.

I'd rather not update it right now because every minor changes related to building examples it causing new issues of this kind.