06.12.2017 20:51, Thomas пишет:
Hi guys!
I need some help or advice about Cimgui (a C-API for Imgui) because I
have no idea how to get it working.
First, I'm new to D (only a few weeks) and still learning. I have a
small C++/C# background, but wanted to try something new. So D got into
my focus.
I am working on Manjaro Linux btw.
Since 2 weeks I am working on a small project of mine to test the SDL2
functions with derelict. Until now everything worked just fine and I got
my first window in SDL.
For this I have installed all SDL library and development files with the
package manager of Manjaro Linux. Even GLFW.
To fill the SDL window with some widgets I have decided to try Imgui via
Cimgui.
My first approach was to use the derelict-imgui version 0.9.4 over DUB.
import derelict.imgui.imgui; has been accepted yet, but
DerelictImgui.load(); not
While compiling I got the following error message:
derelict.util.exception.SharedLibLoadException@../../.dub/packages/derelict-util-3.0.0-beta.2/derelict-util/source/derelict/util/sharedlib.d(158):
Failed to load one or more shared libraries:
cimgui.so - cimgui.so: cannot open shared object file: No such file
or directory
so Cimgui was missing..
Ok, so in a second attempt I downloaded Cimgui as a ZIP and also the
Imgui files from the homepage into the appropriate directory and
unzipped them. First, the compiling via make doesn't wanted to compile:
cimgui.cpp: In Funktion »void ImGuiTextBuffer_append(ImGuiTextBuffer*,
const char*, ...)«:
cimgui.cpp:1716:13: Fehler: »struct ImGuiTextBuffer« hat kein Element
namens »appendv«; meinten Sie »appendf«?
buffer->appendv(fmt, args);
Translated from german -> "there is no element appendv in ImGuiTextBuffer"
So I changed the code myself on that position by replacing "appendv"
with "appendf"
That worked fine. But next problem was this:
/usr/bin/ld: ../imgui/imgui.o: relocation R_X86_64_PC32 against symbol
`_ZN6ImVec2C1Eff' can not be used when making a shared object; recompile
with -fPIC
/usr/bin/ld: final link failed: Bad value
After some research I found out it meant that the imgui files had not
been compiled with -fPIC to be used as a shared library. So I deleted
all .o files in the imgui directory and recompiled
imgui.cpp
imgui_draw.cpp and
imgui_demo.cpp
each with "g++ -c -fPIC -pie"
So I copied the new compiled .o files to the cimgui project and
recompiled it again.
This time it worked without problems :-)
The new shared library file cimgui.so moved to my project directory and
exported LD_LIBRARY_PATH so it could be found by the compiler.
This time the compiler cried this error:
derelict.util.exception.SymbolLoadException@../../.dub/packages/derelict-util-3.0.0-beta.2/derelict-util/source/derelict/util/sharedlib.d(181):
Failed to load symbol igPushIdPtr from shared library cimgui.so
----------------
??:? void*
derelict.util.sharedlib.SharedLib.loadSymbol(immutable(char)[], bool)
[0xcfec77a6]
??:? void*
derelict.util.loader.SharedLibLoader.loadSymbol(immutable(char)[], bool)
[0xcfec5cce]
??:? void derelict.util.loader.SharedLibLoader.bindFunc(void**,
immutable(char)[], bool) [0xcfec5978]
??:? void derelict.imgui.imgui.DerelictImguiLoader.loadSymbols()
[0xcfebe7a5]
??:? void derelict.util.loader.SharedLibLoader.load(immutable(char)[][])
[0xcfec5b4e]
??:? void derelict.util.loader.SharedLibLoader.load(immutable(char)[])
[0xcfec5ac8]
??:? void derelict.util.loader.SharedLibLoader.load() [0xcfec59ab]
??:? _Dmain [0xcfeae0af]
Program exited with code 1
After some research again I found a workaround on the Derelict Util
homepage:
import derelict.util.exception : ShouldThrow;
ShouldThrow myMissingSymbCB( string symbolName )
{
if ( symbolName == "igSetNextWindowPosCenter" ||
symbolName == "igAlignFirstTextHeightToWidgets" ||
symbolName == "igPushIdStr" ||
symbolName == "igPushIdStrRange" )
{
return ShouldThrow.No;
}
else
{
return ShouldThrow.Yes;
}
}
int main()
{
DerelictImgui.missingSymbolCallback = &myMissingSymbCB;
DerelictImgui.load();
}
But with each attempt to compile my project with "dub" by adding the
next symbol name into the list above a new symbol fails to load. Again
and again.
Since 1 week I tried several ways to get the libray to work.
Unfortunately without success.
Because I couldn't find any relevant information on the internet about
this problem I hope to get a solution here. Maybe someone (an Cimgui
expert here?) can give me a step by step instruction how to compile the
library properly ?
Thank you!
Could you describe what dub package you tried to build first of all? It
helps to reproduce your case.