-1

since there is no real tutorial on how to setup ImGui & SDL2, I came here to find answers.

I just have to paste ImGui file into my include folder to setup it right ? At least, it is what the ImGui readme file says.

When i try this :

ImGui::Begin("test");

I have this error :

undefined reference to `ImGui::Begin(char const*, bool*, int)

Code block do autofill me with ImGui functions when I start to write 'i'. Also when I do #include other files (ImGui_draw, etc. ...), I got only redefinition problems.

=> That's why my question sis lighty different from the already answered following question :

What is an undefined reference/unresolved external symbol error and how do I fix it? 

So please do not close this question. I'm looking for a solution from 2 day now and a question here is my only solution left. I will have to give up on ImGui if this question is closed.. I'm truly clueless.

Could this error be due to a conflict with SDL2's opengl ? But in this case, shouldn't just the program crash instead ?

EDIT : Now this error is solved(I used to work with an IDE who include itself the files in my include folder, I didn't knew code block didn't), I have my program launching but nothing related to ImGui happens (as expected, I didn't figured out yet how to mix SDL2 & ImGui) and another error happens now when I quit my SDL2 window :

The program crashes and display the following in the console :

Assertion failed: g.Initialized, file C:\(...)\imgui.cpp, line 3882

Some random testes: If I use ImGui before my main loop it crashes there. Same inside the loop.

  • 4
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – UnholySheep May 17 '17 at 08:56
  • Please re-read my question. The problem is not the error itself. The problem is that error showns even if code blocks found the file. – Sanchez Tanguy May 17 '17 at 09:09
  • 2
    The linked duplicate is valid here. It is fine for your IDE to complete the code as you mentioned, but still have undefined references. They are two separate things. The probability is nearly certain that you will fix your problem if you properly understand the C++ building process, which is explained in the duplicate question. – johnbakers May 17 '17 at 10:02
  • I didn't knew I had to add the files to the project I was used to another IDE who do that for me. + When this error is gone, there is another error(different one) now. – Sanchez Tanguy May 17 '17 at 10:37
  • Just have a look at line 3882 of `imgui.cpp`... – Quentin May 17 '17 at 11:15
  • There is no 3882 line ( o _ o ). I guess I won't be able to use ImGui. I have absolutly no idea what to do. – Sanchez Tanguy May 17 '17 at 11:58
  • @SanchezTanguy [here is line 3882](https://github.com/ocornut/imgui/blob/master/imgui.cpp#L3882), along with a most helpful comment ;) – Quentin May 17 '17 at 21:29
  • That line didn't existed on my file (oO). Maybe I downloaded a corrupted archive. Anyway I gave up on imgui. I'll try to find another GUI easier to setup. Or code a very basic one with SDL. Thanks for your time and answers :) ! – Sanchez Tanguy May 17 '17 at 21:53

2 Answers2

2

I just have to paste ImGui file into my include folder to setup it right ?

No. The header files are needed for your app to see what symbols are out there for valid compilation. But during linking, those symbols actually need to be there, and adding a single header file is not going to add them. You need to bring all the source files (cpp files and probably their corresponding header files) into your app and compile it all together.

Building a C++ app has two main stages: compilation and linking. Your header path has all the information for the compilation stage, but not for linking. Only actual source files (which are not header files) can contain the symbols needed to define what is declared in your headers. If you don't add those too, then your symbols are not defined, which explains your error.

Code block do autofill me with ImGui functions when I start to write 'i'.

That's because you included the header file, which is one part of the process.

I got only redefinition problems.

And just in case you are doing this, don't use #include with any .cpp files, only header files. If you #include cpp files in more than one place, you will definitely get multiple definition errors, as you indicated.

johnbakers
  • 24,158
  • 24
  • 130
  • 258
  • When you say "source files", you mean the ".cpp" ? If yes, when I include them, they also give me "redefinition problem". If no, imgui gives only .cpp and .h files. I'm lost. – Sanchez Tanguy May 17 '17 at 09:42
  • 1
    Never #include a source file. only add it to your project, but do not use #include with it. Also, yes the word "source file" refers to a .cpp file, not a header file. – johnbakers May 17 '17 at 09:42
  • I added the file and the error is gone ! But... even if the program does launch, nothing related to ImGui happens and I have this message : `Assertion failed: g.Initialized, file C:\(...)\imgui.cpp, line 3882` Should I mark this as answered and open a new question ? – Sanchez Tanguy May 17 '17 at 10:35
  • Yes that is a completely different issue. – johnbakers May 17 '17 at 15:16
  • No documentation, no tutorial and all these problems. I finally gave up on ImGui. Why is this so hard to setup libraries... And I looked for some GUI libraries going well with SDL2, found nothing... – Sanchez Tanguy May 17 '17 at 15:26
  • there are tons of examples in their git repo: https://github.com/ocornut/imgui/tree/master/examples – johnbakers May 17 '17 at 17:36
1

Quoting from imgui's README:

ImGui is self-contained within a few files that you can easily copy and compile into your application/engine:

  • imgui.cpp
  • imgui.h
  • imgui_demo.cpp
  • imgui_draw.cpp
  • imgui_internal.h
  • imconfig.h (empty by default, user-editable)
  • stb_rect_pack.h
  • stb_textedit.h
  • stb_truetype.h

So you don't only need the imgui.h header, you need all of these file, taking care of compiling and linking the cpp files into your executable.

Quentin
  • 62,093
  • 7
  • 131
  • 191
  • @SanchezTanguy `ImGui::Begin` is defined in `imgui.cpp`, so no, you didn't compile and link the required files. – Quentin May 17 '17 at 09:10
  • I tought by adding imgui.h it would link everything ! I got somewhere now ^^ But I have still errors, and there all the same : redefinitions. How can I get ride of this ? – Sanchez Tanguy May 17 '17 at 09:12
  • @SanchezTanguy which symbols are multiply defined? – Quentin May 17 '17 at 09:13
  • When I comment the includes generating redefinitions I have only imgui.h left. So the problem I started with, of course happens again. Looks like there is no solution here :/ – Sanchez Tanguy May 17 '17 at 09:17
  • I edited my post, now that problem is solved thanks to all your comments guyz, I have another error happening when I close my program. – Sanchez Tanguy May 17 '17 at 10:44