Hello,
I'm trying to use @geotre's Wren wrapper for Nim, but I can't get dynamic linking to work. Here's my folder structure with the relevant files:
.
└── src
├── lib
│ └── wren
│ ├── info.txt
│ ├── LICENSE
│ ├── readme.md
│ ├── src
│ │ ├── wren
│ │ │ └── libwren.nim
│ │ └── wren.nim
│ └── wren.nimble
├── libwren.so
└── rapid.nim
The wrapper's libwren.nim file depends on the libwren.(dll|dylib|so) dynamic library, and I'm putting it into my src folder, as you can see above. The wrapper unfortunately isn't available on Nimble, so I had to include it in my lib folder. libwren.so has been compiled from the official repo: https://github.com/wren-lang/wren, using the command make shared, on a 64-bit machine.
Now, the problem is, my application runs into an error:
libwren.so: cannot open shared object file: No such file or directory
could not load: libwren.so
This is the program's output when compiled with the -d:nimDebugDlOpen switch (Nim also says libpcre.so.3 is missing, but I'm not going to use PCRE in my final application so I stripped it from the output).Have you tried this?
LD_LIBRARY_PATH="$(pwd)" ./binary
I did the same with nimbass.
https://github.com/genotrance/nimbass/blob/master/nimbass.nimble
Not much choice beyond tweaking LD_LIBRARY_PATH at runtime. It's part of the reason most of the nimgen wrappers compile in the code.
2. In my source code I added this:
when sizeof(int) == 4:
when defined(windows):
const wrenDynlib = "libwren-32.dll"
elif defined(macosx):
const wrenDynlib = "libwren-32.dylib"
else:
const wrenDynlib = "libwren-32.so"
elif sizeof(int) == 8:
when defined(windows):
const wrenDynlib = "libwren-64.dll"
elif defined(macosx):
const wrenDynlib = "libwren-64.dylib"
else:
const wrenDynlib = "libwren-64.so"
{.link: currentSourcePath.splitPath.head / wrenDynlib .}
There's probably a cleaner way btw, but I did this for testing.
ld doesn't return any errors, but my application itself does:
/home/[user]/Coding/Nim/rapid/src/rapid: error while loading shared libraries: libwren.so: cannot open shared object file: No such file or directory
Error: execution of an external program failed: '/home/[user]/Coding/Nim/rapid/src/rapid '
Hey @lqdev I've switched the wren package to use nimgen and compile in the code, so there's no longer any requirement for libwren.so or the dynlib pragmas.
It's also going on nimble - https://github.com/nim-lang/packages/pull/977
Let me know if that works better for you