I have been investigating this issue. After some struggle I have managed to reproduce it.
I am using MSYS2, so that I could install the package dlfcn:
$ pacman -S mingw-w64-x86_64-dlfcn
Now I am getting the same error:
λ nim c --threads:on --tlsEmulation:off ex00
Hint: used config file 'C:\Users\jose\Documents\nim-1.4.2\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\jose\Documents\nim-1.4.2\config\config.nims' [Conf]
................
c:\Users\jose\Downloads\VapourSynth.nim\VapourSynth.nim-master\src\wrapper\vsframe.nim(403, 7) Hint: 'ssW' is declared but not used [XDeclaredButNotUsed]
c:\Users\jose\Downloads\VapourSynth.nim\VapourSynth.nim-master\src\wrapper\vsframe.nim(404, 7) Hint: 'ssH' is declared but not used [XDeclaredButNotUsed]
c:\Users\jose\Downloads\VapourSynth.nim\VapourSynth.nim-master\src\wrapper\vsframe.nim(405, 7) Hint: 'bytesPerSample' is declared but not used [XDeclaredButNotUsed]
..
c:\Users\jose\Downloads\VapourSynth.nim\VapourSynth.nim-master\src\vsmacros\filter.nim(241, 7) Hint: 'srcNumPlanes' is declared but not used [XDeclaredButNotUsed]
c:\Users\jose\Downloads\VapourSynth.nim\VapourSynth.nim-master\src\wrapper\helper.nim(6, 7) Hint: 'nodes' is declared but not used [XDeclaredButNotUsed]
c:\Users\jose\Downloads\VapourSynth.nim\VapourSynth.nim-master\src\wrapper\vsmap.nim(282, 3) Hint: 'VSType' is declared but not used [XDeclaredButNotUsed]
Hint: [Link]
gcc.exe: error: unrecognized command-line option '-rdynamic'
Error: execution of an external program failed: 'gcc.exe -o c:\Users\jose\Downloads\VapourSynth.nim\VapourSynth.nim-master\test\ex00.exe C:\Users\jose\nimcache\ex00_d\stdlib_assertions.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_locks.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_sharedlist.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_widestrs.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_io.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_system.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_parseutils.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_unicode.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_strutils.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_strformat.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_options.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_streams.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_tables.nim.c.o C:\Users\jose\nimcache\ex00_d\@m..@[email protected] C:\Users\jose\nimcache\ex00_d\@mex00.nim.c.o -rdynamic -Wl,-wrap,dlopen '
with:
λ gcc -v
...
gcc version 10.2.0 (Rev6, Built by MSYS2 project)
The first question is:
-rdynamic
Pass the flag -export-dynamic to the ELF linker, on targets that support it. This
instructs the linker to add all symbols, not only used ones, to the dynamic symbol
table. This option is needed for some uses of dlopen or to allow obtaining backtraces
from within a program.
Secondly, I have tried:
λ gcc.exe -o c:\Users\jose\Downloads\VapourSynth.nim\VapourSynth.nim-master\test\ex00.exe C:\Users\jose\nimcache\ex00_d\stdlib_assertions.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_locks.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_sharedlist.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_widestrs.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_io.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_system.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_parseutils.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_unicode.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_strutils.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_strformat.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_options.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_streams.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_tables.nim.c.o C:\Users\jose\nimcache\ex00_d\@m..@[email protected] C:\Users\jose\nimcache\ex00_d\@mex00.nim.c.o -Wl,-wrap,dlopen
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\jose\nimcache\ex00_d\@m..@[email protected]:@m..@[email protected]:(.text+0x19): undefined reference to `dlopen'
collect2.exe: error: ld returned 1 exit status
λ gcc.exe -o c:\Users\jose\Downloads\VapourSynth.nim\VapourSynth.nim-master\test\ex00.exe C:\Users\jose\nimcache\ex00_d\stdlib_assertions.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_locks.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_sharedlist.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_widestrs.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_io.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_system.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_parseutils.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_unicode.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_strutils.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_strformat.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_options.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_streams.nim.c.o C:\Users\jose\nimcache\ex00_d\stdlib_tables.nim.c.o C:\Users\jose\nimcache\ex00_d\@m..@[email protected] C:\Users\jose\nimcache\ex00_d\@mex00.nim.c.o -Wl,-wrap
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\jose\nimcache\ex00_d\@m..@[email protected]:@m..@[email protected]:(.text+0x19): undefined reference to `__real_dlopen'
collect2.exe: error: ld returned 1 exit status
Any idea how should I compile this? Any particular option for windows?
Hello,
In src/wrapper/VSScript_Wrapper.nim there is this horrible POSIX-specific code:
{. passL:"-rdynamic -Wl,-wrap,dlopen".}
{.emit: """
#include <dlfcn.h>
#include <stdio.h>
void *__real_dlopen(const char *filename, int flags);
void *__wrap_dlopen(const char *filename, int flags)
{
//printf("shadow dlopen with RTLD_GLOBAL: %s\n", filename);
//fflush(stdout);
return __real_dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
}
""".}
It seems to serve no purpose at all even on not-windows (Nim already use dlopen/LoadLibrary for loading dlls after all).
I tried to cut it out with a
when not defined(windows):
Horrible code
and it compiles on my windows machine. (It fails at execution with ' plugin "com.vapoursynth.ffms2" not installed properly in your computer' but I did not try hard to install VapourSynth).
BTW if loading dlls explicitly in Nim code is needed it is probably better to use stdlib's dynlib module instead of using a msys2 package.