I have a small program I'm creating as part of learning Nim. On Linux it works fine. But on Windows it compiles but fails to run:
R:\wordladder>nim c -d:nimDebugDlOpen -r wordladder
Hint: used config file 'c:\bin\nim\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: wordladder [Processing]
Hint: critbits [Processing]
Hint: nre [Processing]
Hint: pcre [Processing]
Hint: util [Processing]
Hint: tables [Processing]
Hint: hashes [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: algorithm [Processing]
Hint: etcpriv [Processing]
Hint: options [Processing]
Hint: typetraits [Processing]
Hint: unicode [Processing]
wordladder.nim(28, 7) Hint: 'words' is declared but not used [XDeclaredButNotUsed]
wordladder.nim(8, 7) Hint: 'STEPS' is declared but not used [XDeclaredButNotUsed]
CC: stdlib_system
Hint: [Link]
Hint: operation successful (20015 lines compiled; 1.684 sec total; 66.004MiB; Debug Build)
[SuccessX]
Hint: R:\wordladder\wordladder.exe [Exec]
could not load: pcre64.dll
Error: execution of an external program failed: 'R:\wordladder\wordladder.exe '
R:\wordladder>echo %PATH%
c:\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\Windows
PowerShell\v1.0\;C:\Program Files\TortoiseHg\;"C:\Program Files (x86)\GnuWin32\bin";C:\Go\
bin;c:\bin\julia\bin;C:\Python34\;C:\Python34\Scripts;c:\bin\nim\bin;c:\mingw\mingw64\bin;
C:\Program Files\diffpdfc\
R:\wordladder>
The code I've got so far is here: so far it only outputs a list of words taken from a .dic file:
wordladder.nim.zip
As you can see nim's bin dir is in the PATH and I've checked and it does contain pcre64.dll.
I've now discovered the problem: Nim is installed on C: but I'm developing the app on R: (which is shared with Linux so I can test on both). But that still doesn't explain why the Nim executable can't find the DLL since the DLL is on the PATH?
I'm sorry, but i dont think its a Nim problem. Nim uses LoadLibrary to load pcre64.dll, so if it fails, maybe your PATH is wrong, or maybe pcre64.dll is not in C:\BIN\NIM\BIN?
As you can see from the dir and echo %path% commands below, the DLL is indeed present there and the PATH is indeed correct!
R:\>dir c:\bin\nim\bin\
Volume in drive C has no label.
Volume Serial Number is C8CE-CB52
Directory of c:\bin\nim\bin
12/03/2017 07:31 <DIR> .
12/03/2017 07:31 <DIR> ..
12/03/2017 07:31 1,273,507 c2nim.exe
12/03/2017 07:31 270,336 libcurl.dll
12/03/2017 07:31 1,359,872 libeay32.dll
12/03/2017 07:31 2,246,656 libeay64.dll
12/03/2017 07:31 260,096 libpng12.dll
12/03/2017 07:31 260,096 libpng3.dll
12/03/2017 07:31 102,912 makelink.exe
12/03/2017 07:31 2,774,870 nim.exe
12/03/2017 07:31 6,100,019 nimble.exe
12/03/2017 07:31 582,699 nimgrep.exe
12/03/2017 07:31 2,115,998 nimsuggest.exe
12/03/2017 07:31 295,424 pcre.dll
12/03/2017 07:31 140,288 pcre3.dll
12/03/2017 07:31 518,656 pcre32.dll
12/03/2017 07:31 526,336 pcre64.dll
12/03/2017 07:31 140,800 pdcurses.dll
12/03/2017 07:31 140,800 pdcurses32.dll
12/03/2017 07:31 187,458 pdcurses64.dll
12/03/2017 07:31 260,096 png.dll
12/03/2017 07:31 650,725 sqlite3_32.dll
12/03/2017 07:31 862,541 sqlite3_64.dll
12/03/2017 07:31 379,392 ssleay32.dll
12/03/2017 07:31 408,064 ssleay64.dll
12/03/2017 07:31 84,480 zlib1.dll
24 File(s) 21,942,121 bytes
2 Dir(s) 78,909,300,736 bytes free
R:\>echo %path%
c:\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\Windows
PowerShell\v1.0\;C:\Program Files\TortoiseHg\;"C:\Program Files (x86)\GnuWin32\bin";C:\Go\
bin;c:\bin\julia\bin;C:\Python34\;C:\Python34\Scripts;c:\bin\nim\bin;c:\mingw\mingw64\bin;
C:\Program Files\diffpdfc\
Could you please run executable itself, without nim c -r nimfile.nim?
Also compilation is not fails, compilation was completed successfully.
Yes I know it builds fine, but that's not much help at runtime:-)
R:\wordladder>nim c -d:nimDebugDlOpen wordladder
Hint: used config file 'c:\bin\nim\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: wordladder [Processing]
Hint: critbits [Processing]
Hint: nre [Processing]
Hint: pcre [Processing]
Hint: util [Processing]
Hint: tables [Processing]
Hint: hashes [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: algorithm [Processing]
Hint: etcpriv [Processing]
Hint: options [Processing]
Hint: typetraits [Processing]
Hint: unicode [Processing]
wordladder.nim(35, 7) Hint: 'count' is declared but not used [XDeclaredButNotUsed]
wordladder.nim(34, 7) Hint: 'words' is declared but not used [XDeclaredButNotUsed]
wordladder.nim(13, 7) Hint: 'STEPS' is declared but not used [XDeclaredButNotUsed]
CC: stdlib_system
Hint: [Link]
Hint: operation successful (20027 lines compiled; 1.240 sec total; 66.004MiB; Debug Build)
[SuccessX]
R:\wordladder>wordladder.exe
could not load: pcre64.dll
(The reason the Hints differ from before is that I've changed the code -- but the regex part is the same.)
Ok i have tried to make equal position of files and projects, and got
K:\test>wordladder.exe
Traceback (most recent call last)
wordladder.nim(30) wordladder
wordladder.nim(19) getWords
system.nim(2626) sysFatal
Error: unhandled exception: cannot open: V:\tmp\en_GB.dic [IOError]
So my pcre64.dll was loaded successfully.
It looks like you have a big zoo of c compilers, and big %PATH%. If you have installed Nim from official nim-0.16.0_x64.zip, then yours pcre64.dll is 64bit dll, but it requires msvcrt.dll. I think somewhere in your %PATH% there one more msvcrt.dll present and it is 32bit.
Try to find 64bit msvcrt.dll and drop it in same directory as your executable.
I think this path C:\Program Files (x86)\GnuWin32\bin is a problem, i think you can find there 32bit version of msvcrt.dll.
You are brilliant! That was exactly the problem. I uninstalled gnu-grep (which I don't need now that I share drives with Linux) and removed that from the PATH and nim builds and runs wordladder perfectly.
Thank you:-)