Hi all!
I’m new to nim and saw that there is imgui for GUI.
But running the example (after fixing the missing ptr in the code) does not work. Where should I get cimgui.soif I’m under linux mint 20?
~ ⌚ 18:14:43 $ nimble install https://github.com/nimgl/imgui.git Downloading https://github.com/nimgl/imgui.git using git Verifying dependencies for [email protected] Installing [email protected] Prompt: [email protected] already exists. Overwrite? [y/N] y Answer: Success: imgui installed successfully. ~ ⌚ 18:16:51 $ nim r i.nim Hint: used config file '/home/pihentagy/.choosenim/toolchains/nim-1.4.0/config/nim.cfg' [Conf] Hint: used config file '/home/pihentagy/.choosenim/toolchains/nim-1.4.0/config/config.nims' [Conf] Hint: 7732 lines; 0.039s; 12.242MiB peakmem; Debug build; proj: /home/pihentagy/i.nim; out: /home/pihentagy/.cache/nim/i_d/i [SuccessX] Hint: /home/pihentagy/.cache/nim/i_d/i [Exec] could not load: cimgui.so (compile with -d:nimDebugDlOpen for more information) Error: execution of an external program failed: '/home/pihentagy/.cache/nim/i_d/i ' ~ ⌚ 18:17:02 $
You do not need to load IMGUI from a shared library at all. If you build using the cpp backend, nimgl will build IMGUI from source and statically link it. See my example project here:
Thanks, tried it, but got a more scary output. I know it's less about nim and more about imgui but hope someone can head me to the right direction.
/tmp/imgui_nim on master ⌚ 13:08:59
$ nimble run imgui_nim
Verifying dependencies for [email protected]
Installing [email protected]
Downloading https://github.com/nimgl/nimgl using git
Verifying dependencies for [email protected]
Installing [email protected]
Success: nimgl installed successfully.
Installing pararules@>= 0.3.0
Downloading https://github.com/paranim/pararules using git
Verifying dependencies for [email protected]
Installing [email protected]
Success: pararules installed successfully.
Building imgui_nim/imgui_nim using cpp backend
/tmp/imgui_nim/src/core.nim(2, 11) Warning: imported and not used: 'glfw' [UnusedImport]
/usr/bin/ld: cannot find -lXxf86vm
collect2: error: ld returned 1 exit status
Error: execution of an external program failed: 'g++ -o /tmp/imgui_nim/imgui_nim /home/pihentagy/.cache/nim/imgui_nim_d/vulkan.c.o /home/pihentagy/.cache/nim/imgui_nim_d/x11_init.c.o /home/pihentagy/.cache/nim/imgui_nim_d/x11_monitor.c.o /home/pihentagy/.cache/nim/imgui_nim_d/x11_window.c.o /home/pihentagy/.cache/nim/imgui_nim_d/glx_context.c.o /home/pihentagy/.cache/nim/imgui_nim_d/xkb_unicode.c.o /home/pihentagy/.cache/nim/imgui_nim_d/linux_joystick.c.o /home/pihentagy/.cache/nim/imgui_nim_d/posix_time.c.o /home/pihentagy/.cache/nim/imgui_nim_d/egl_context.c.o /home/pihentagy/.cache/nim/imgui_nim_d/osmesa_context.c.o /home/pihentagy/.cache/nim/imgui_nim_d/posix_thread.c.o /home/pihentagy/.cache/nim/imgui_nim_d/context.c.o /home/pihentagy/.cache/nim/imgui_nim_d/init.c.o /home/pihentagy/.cache/nim/imgui_nim_d/input.c.o /home/pihentagy/.cache/nim/imgui_nim_d/monitor.c.o /home/pihentagy/.cache/nim/imgui_nim_d/window.c.o /home/pihentagy/.cache/nim/imgui_nim_d/cimgui.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/imgui.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/imgui_draw.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/imgui_demo.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/imgui_widgets.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/stdlib_assertions.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/stdlib_dollars.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/stdlib_io.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/stdlib_system.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/@m..@s..@s..@shome@[email protected]@[email protected]@snimgl@[email protected] /home/pihentagy/.cache/nim/imgui_nim_d/@m..@s..@s..@shome@[email protected]@[email protected]@[email protected] /home/pihentagy/.cache/nim/imgui_nim_d/stdlib_math.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/stdlib_algorithm.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/stdlib_strutils.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/stdlib_dynlib.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/@m..@s..@s..@shome@[email protected]@[email protected]@[email protected] /home/pihentagy/.cache/nim/imgui_nim_d/stdlib_hashes.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/stdlib_tables.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/stdlib_sets.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/@m..@s..@s..@shome@[email protected]@[email protected]@[email protected] /home/pihentagy/.cache/nim/imgui_nim_d/@m..@s..@s..@shome@[email protected]@[email protected]@[email protected] /home/pihentagy/.cache/nim/imgui_nim_d/@m..@s..@s..@shome@[email protected]@[email protected]@snimgl@simgui@simpl_opengl.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/@mcore.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/@m..@s..@s..@shome@[email protected]@[email protected]@snimgl@[email protected] /home/pihentagy/.cache/nim/imgui_nim_d/@m..@s..@s..@shome@[email protected]@[email protected]@snimgl@simgui@simpl_glfw.nim.cpp.o /home/pihentagy/.cache/nim/imgui_nim_d/@mimgui_nim.nim.cpp.o -pthread -lGL -lX11 -lXrandr -lXxf86vm -lXi -lXcursor -lm -lXinerama -lm -lrt -Xlinker -rpath . -ldl'
Tip: 357 messages have been suppressed, use --verbose to show them.
Error: Build failed for package: imgui_nim
... Execution failed with exit code 1
... Command: /home/pihentagy/.nimble/bin/nim cpp --colors:on --noNimblePath -d:NimblePkgVersion=0.1.0 --path:/home/pihentagy/.nimble/pkgs/nimgl-1.1.1 --path:/home/pihentagy/.nimble/pkgs/pararules-0.9.0 --hints:off -o:/tmp/imgui_nim/imgui_nim /tmp/imgui_nim/src/imgui_nim.nim
/tmp/imgui_nim on master ⌚ 13:11:22
Based on a quick search it looks like you need to install X11 / opengl libraries. If you're on a debian based system try this:
sudo apt-get install xorg-dev libglu1-mesa-dev
I do installed those, but the error message remains the same. Maybe I should complain at the developers of imgui
~ ⌚ 19:12:33
$ sudo apt-get install xorg-dev libglu1-mesa-dev
[sudo] password for pihentagy:
Reading package lists... Done
Building dependency tree
Reading state information... Done
libglu1-mesa-dev is already the newest version (9.0.1-1build1).
The following packages were automatically installed and are no longer required:
linux-headers-5.4.0-52 linux-headers-5.4.0-52-generic linux-image-5.4.0-52-generic
linux-modules-5.4.0-52-generic linux-modules-extra-5.4.0-52-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libdmx-dev libdmx1 libfontenc-dev libfs-dev libfs6 libpciaccess-dev libxaw7-dev libxfont-dev
libxmu-dev libxmu-headers libxmuu-dev libxpm-dev libxres-dev libxss-dev libxt-dev libxtst-dev
libxv-dev libxvmc-dev libxxf86dga-dev libxxf86vm-dev mesa-common-dev x11proto-record-dev
x11proto-scrnsaver-dev x11proto-xf86dga-dev x11proto-xf86vidmode-dev xserver-xorg-dev
Suggested packages:
libxaw-doc libxt-doc
The following NEW packages will be installed:
libdmx-dev libdmx1 libfontenc-dev libfs-dev libfs6 libpciaccess-dev libxaw7-dev libxfont-dev
libxmu-dev libxmu-headers libxmuu-dev libxpm-dev libxres-dev libxss-dev libxt-dev libxtst-dev
libxv-dev libxvmc-dev libxxf86dga-dev libxxf86vm-dev mesa-common-dev x11proto-record-dev
x11proto-scrnsaver-dev x11proto-xf86dga-dev x11proto-xf86vidmode-dev xorg-dev xserver-xorg-dev
0 upgraded, 27 newly installed, 0 to remove and 1 not upgraded.
Need to get 2.048 kB of archives.
After this operation, 9.823 kB of additional disk space will be used.
Do you want to continue? [Y/n]
I do installed those, but the error message remains the same. Maybe I should complain at the developers of imgui :)
~ ⌚ 19:12:33
$ sudo apt-get install xorg-dev libglu1-mesa-dev
[sudo] password for pihentagy:
Reading package lists... Done
Building dependency tree
Reading state information... Done
libglu1-mesa-dev is already the newest version (9.0.1-1build1).
The following packages were automatically installed and are no longer required:
linux-headers-5.4.0-52 linux-headers-5.4.0-52-generic linux-image-5.4.0-52-generic
linux-modules-5.4.0-52-generic linux-modules-extra-5.4.0-52-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libdmx-dev libdmx1 libfontenc-dev libfs-dev libfs6 libpciaccess-dev libxaw7-dev libxfont-dev
libxmu-dev libxmu-headers libxmuu-dev libxpm-dev libxres-dev libxss-dev libxt-dev libxtst-dev
libxv-dev libxvmc-dev libxxf86dga-dev libxxf86vm-dev mesa-common-dev x11proto-record-dev
x11proto-scrnsaver-dev x11proto-xf86dga-dev x11proto-xf86vidmode-dev xserver-xorg-dev
Suggested packages:
libxaw-doc libxt-doc
The following NEW packages will be installed:
libdmx-dev libdmx1 libfontenc-dev libfs-dev libfs6 libpciaccess-dev libxaw7-dev libxfont-dev
libxmu-dev libxmu-headers libxmuu-dev libxpm-dev libxres-dev libxss-dev libxt-dev libxtst-dev
libxv-dev libxvmc-dev libxxf86dga-dev libxxf86vm-dev mesa-common-dev x11proto-record-dev
x11proto-scrnsaver-dev x11proto-xf86dga-dev x11proto-xf86vidmode-dev xorg-dev xserver-xorg-dev
0 upgraded, 27 newly installed, 0 to remove and 1 not upgraded.
Need to get 2.048 kB of archives.
After this operation, 9.823 kB of additional disk space will be used.
Do you want to continue? [Y/n]
I recently ran across this issue, too. The nimgl/imgui repository includes cimgui as a submodule. You should be able to compile the shared library by running make in src/imgui/private/cimgui. Then copy/link the generated cimgui.so to the the same directory as the nim based executable, or install it in /usr/local/lib via ldconfig.
Alternatively you can build the library from the main cimgui repository. Just be sure to checkout the version of cimgui that the nimgl project expects. Presently nimgl is using v1.78 of cimgui.
Works for me on Ubuntu 20.04.
Ok, tried that:
/tmp ⌚ 10:17:35
$ git clone --recursive https://github.com/cimgui/cimgui.git
$ cd cimgui
$ make
$ cp cimgui.so ~
$ rm -rf ~/.cache/nim
and then when I try to run my program again:
$ nim r i.nim
Hint: used config file '/home/pihentagy/.choosenim/toolchains/nim-1.4.0/config/nim.cfg' [Conf]
Hint: used config file '/home/pihentagy/.choosenim/toolchains/nim-1.4.0/config/config.nims' [Conf]
............CC: stdlib_system.nim
CC: .nimble/pkgs/imgui-1.78.0/imgui.nim
CC: i.nim
Hint: [Link]
Hint: 36943 lines; 1.446s; 60.121MiB peakmem; Debug build; proj: /home/pihentagy/i.nim; out: /home/pihentagy/.cache/nim/i_d/i [SuccessX]
Hint: /home/pihentagy/.cache/nim/i_d/i [Exec]
Traceback (most recent call last)
/home/pihentagy/i.nim(3) i
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Error: execution of an external program failed: '/home/pihentagy/.cache/nim/i_d/i '
The command line nim r i.nim in your example above should not compile/run. I assume you mean nim c -r i.nim.
Can you share a snippet of i.nim so we can understand what's happening on line 3?
Also, you should be able to compile and run the ImGui test app from the nimgl/imgui repo. So, copy test.nim and cimgui.so to a directory, compile test.nim and run.
The command line nim r i.nim in your example
It is fine for recent Nim compiler. But it is not very smart to use it in case of problems. If there is only a minimal chance for trouble, I use a plain nim c --gc:arc myfile.nim first to see all the compiler output including warnings.
(nim r is compiling and running and hiding/deleting the executable.)
compile to $nimcache/projname, run with [arguments] using backend specified by --backend (default: c)