There is this library, that can be build dynamically, and statically, and I would like to make this library available to the nim world. The library I am talking about is AntTweakBar. Since the original library is not maintained anymore, I had to patch it on my own to support SDL2 events, so I am not talking anymore about the original library.
My goal is, that someone can just say: nimble install AntTweakBar, and no further dependencies need to be installed, and I think this can be done with static linking, at least that is, what I did in my go wrapper. But whatever I try, things turn out to not work the way I think they should.
Since nimble installs generally by source to provide platform independent packages, I think that I should also include the source of AntTweakBar in my package. But then how do I get the Makefile in the packaged AntTweakBar directory executed?
As far as I know, nimble does not install it's own nimble files, but the installation of packages is always just the source, not the binary. So in my point of view the whole nimscript power in nimble is completely useless, because when the package is actually build (after istallation), there is no build script anymore to influence anything.
Then I tried to use the link macro, in combination with staticExec. I wanted to call staticExec("make -C cAntTweakBar/src") before my link macro call. But the path cAntTweakBar/src, but this breaks as soon as I call the nim compiler from another directory that the nim file. Then I wanted to transform the relative paths manually to absolute paths by adding the current working directory, but system.instanciationInfo apparently does not give me this information at compile time.
So I am stuck at the moment, can you please give me some advice.
This is the version of AntTweakBar that I would like to wrap: https://github.com/krux02/AntTweakBar
EDIT: I just tried to add all source file of AntTweakBar with the compile pragma, in AntTweakBar.nim.
{.compile: "cAntTweakBar/src/LoadOGL.cpp".}
{.compile: "cAntTweakBar/src/LoadOGLCore.cpp".}
{.compile: "cAntTweakBar/src/TwBar.cpp".}
{.compile: "cAntTweakBar/src/TwColors.cpp".}
But all it does is trying to link, doesn't build those files at all:
nim c AntTweakBar.nim
Hint: system [Processing]
Hint: AntTweakBar [Processing]
Hint: [Link]
gcc: Fehler: /home/arne/proj/nim/nimAntTweakBar/src/nimcache/TwEventX11.o: Datei oder Verzeichnis nicht gefunden
gcc: Fehler: /home/arne/proj/nim/nimAntTweakBar/src/nimcache/TwPrecomp.o: Datei oder Verzeichnis nicht gefunden
gcc: Fehler: /home/arne/proj/nim/nimAntTweakBar/src/nimcache/TwOpenGLCore.o: Datei oder Verzeichnis nicht gefunden
gcc: Fehler: /home/arne/proj/nim/nimAntTweakBar/src/nimcache/TwOpenGL.o: Datei oder Verzeichnis nicht gefunden
[...]
EDIT: The wrapper is done, you can get it here: https://github.com/krux02/nimAntTweakBar
Were you able to get it working? Sorry that nobody replied to you in so long.
I think the {.compile.} pragma is the indeed the way to go. Nimble can install the C files together with the package. I'm not sure why the pragma doesn't work though.
Dear @andrea,
I've tried the nimscript format in Nimble to download and build a C library (http://github.com/sdwfrost/rmath). The relevant bit from my .nimble looks like this:
# Tasks
before install:
echo "Building libRmath-nim"
exec "git clone https://github.com/sdwfrost/libRmath-nim"
withDir "libRmath-nim":
exec "make"
when defined(windows):
const
rmathlib = "Rmath-nim.dll"
elif defined(macosx):
const
rmathlib = "libRmath-nim.dylib"
else:
const
rmathlib = "libRmath-nim.so"
cpFile(thisDir() & "/libRmath-nim/src/" & rmathlib, thisDir() & "/private/" & rmathlib)
rmDir("libRmath-nim")
The only problem is that Nim can't find the shared library unless I add to LD_LIBRARY_PATH. Does anyone know how to refer to a shared library in an installed package? (I also had problems with joinPath, as ospaths wouldn't load, hence the use of concatenation in the .nimble)
Best
Simon
@sdwfrost Does the library non exist anymore? I'm not finding it on github.
By the way: thank you for the before install: thing, I did not know one could do that in nimble!
Dear @andrea,
Sorry, I changed the name of the library - it's now at http://github.com/sdwfrost/distributions.
I settled for having a separate nims file for installing the dependencies, as this overcomes the issue that one can't import into nimble files (https://github.com/nim-lang/nimble/issues/186), then called it from the nimble file. You still have to add to LD_LIBRARY_PATH, however.
Best Simon