Closed zetashift closed 3 years ago
Thanks very much for the docs, this will definitely go to readme!
I fixed the issue with /
so that it should be \
on Windows, this should solve testing.
With raygui it is a bit harder, the exact commands in nimble file are:
let sourceFile = "raygui"/"src"/"raygui.h"
exec "cc -x c -fPIC -c -o raygui.o -DRAYGUI_IMPLEMENTATION -DRAYGUI_SUPPORT_ICONS " & sourceFile
exec "cc -shared -o libraygui.so -lraylib raygui.o"
On windows at least -o libraygui.so
should be -o raygui.dll
(as per conventions) and God knows what else. I searched for "how to compile a dynamic library for Windows" and got:
The commands should be similar though. And raygui.h requires raylib.h to be in path, you can just download it from raylib if it's not loaded by default https://github.com/raysan5/raylib/blob/master/src/raylib.h
Could you test raygui usage with -d:nimDebugDlOpen
, it should give more info on what's actually wrong with this dll. I personally took it from here: https://github.com/Guevara-chan/Raylib-Forever/releases
nim r -d:nimDebugDlOpen examples\original\basic.nim
@zetashift could you update the bindings from latest master and try again. It should just work. Only raylib.dll
should be present in the same directory
Running the shapes/bouncing_ball
and the shapes/draw_ring
example gives me on the latest master currently this error:
C:/Users/Rishi/.choosenim/toolchains/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lraylib
collect2.exe: error: ld returned 1 exit status
Error: execution of an external program failed: 'gcc.exe -o P:\dev\gamedev\nimraylib_now\examples\shapes\bouncing_ball.exe C:\Users\Rishi\nimcache\bouncing_ball_d\stdlib_io.nim.c.o C:\Users\Rishi\nimcache\bouncing_ball_d\stdlib_system.nim.c.o C:\Users\Rishi\nimcache\bouncing_ball_d\stdlib_dynlib.nim.c.o C:\Users\Rishi\nimcache\bouncing_ball_d\stdlib_winlean.nim.c.o C:\Users\Rishi\nimcache\bouncing_ball_d\stdlib_times.nim.c.o C:\Users\Rishi\nimcache\bouncing_ball_d\stdlib_os.nim.c.o C:\Users\Rishi\nimcache\bouncing_ball_d\@m..@s..@ssrc@snimraylib_now@sraylib.nim.c.o C:\Users\Rishi\nimcache\bouncing_ball_d\@mbouncing_ball.nim.c.o -lraylib '
I think I have to pass in the raylib headers somewhere then?
Yes, here is the line:
{.passL:"-lraylib".}
Possible problem is that mingw (gcc.exe) doesn't see the raylib.dll file. Possible solution: -L flag
nim r --passL:"-L<path/to/directory>" -d:nimDebugDlOpen examples\original\basic.nim
Another solution is to change {.passL:"-lraylib".}
to something else, but I'm not sure what exactly
Searches on the topic, nothing seems to have the exact answer but for reference:
Mingw website is currently down for some reason, would be good to browse their wiki once it's up e.g. this one http://www.mingw.org/wiki/LibraryPathHOWTO
According to these answers:
Seems that libraylibdll.a is also needed for linking
Raylib ships with 3 binaries:
raylib-3.5.0_win64_mingw-w64/lib/libraylib.a
raylib-3.5.0_win64_mingw-w64/lib/libraylibdll.a
raylib-3.5.0_win64_mingw-w64/lib/raylib.dll
and I assume that you need both libraylibdll.a and raylib.dll present in the same directory as exe
Alternatively we might want to pass it like this "--passL:libraylibdll.a" as @enthus1ast did it here https://github.com/enthus1ast/raylib/blob/master/src/draylib.nim#L4
I removed this passL pragma from master so you have easier time tinkering with it. For me it now works like this:
nim r --passL:-lraylib examples/original/crown.nim
My current understanding is that one of these options should work for Windows if you have libray.dll and libraydll.a files in the same directory as exe:
nim r --passL:"-lraylib" examples\original\crown.nim
nim r --passL:"-L/path/to/exe/folder -lraylib" examples\original\crown.nim
nim r --passL:"libraylibdll.a" examples\original\crown.nim
nim r --passL:"-L/path/to/exe/folder libraylibdll.a" examples\original\crown.nim
Please let me know if one of these commands work or you find anything else. I think I will be able to automate path finding after we find the correct command and flags
nim r --passL:"libraylibdll.a" examples\original\crown.nim
works! As long as libraylibdll.a
is in the same folder. nim r --passL:"-L/path/to/exe/folder libraylibdll.a" examples\original\crown.nim
works too!
nim r --passL:"-lraylib" examples\original\crown.nim
nim r --passL:"-L/path/to/exe/folder -lraylib" examples\original\crown.nim
nim r --passL:"libraylibdll.a" examples\original\crown.nim
nim r --passL:"-L/path/to/exe/folder libraylibdll.a" examples\original\crown.nim
ld.exe: cannot find -lraylib collect2.exe: error: ld returned 1 exit status
The raygui example I tried worked too.
nimble testExamples
still gives me the error:
PS P:\dev\gamedev\nimraylib_now> nimble testExamples
Executing task testExamples in P:\dev\gamedev\nimraylib_now\nimraylib_now.nimble
no tests were found for pattern: 'tests\examples\**\*.nim'
Running a single test example using testament r
I get this monstrosity:
https://play.nim-lang.org/#ix=2LLJ
Thank you very much for the feedback, I'm glad we finally found the right flag!
Current master fixes problem with passL flags like this in raylib.nim:
when defined(windows):
when defined(vcc):
# Should it be `link` instead of passL?
{.passL:"raylibdll.lib".}
else:
{.passL:"libraylibdll.a".}
else:
{.passL:"-lraylib".}
And "no tests were found for pattern" problem by replacing "*" glob to just single "" asterisk since double asterisk is not present in power shell, so the testament command is fixed to be like this:
task testExamples, "checks that all examples are correctly compiled":
let pattern = "'tests"/"examples"/"*"/"*.nim'"
exec "testament pattern " & pattern
In short, everything should work in regards to running and compiling any code if dll files are in the same directory as exe.
I don't know how to solve the problem with testament output though.
Let me know if the latest master works for you and I will release a new version and update readme accordingly.
Samples I have tried, like crown/draw_ring/bouncing_ball work great on latest master by simply running:
nim c -r foo.nim
ofcourse having the .dll and .a file in the same folder as resulting .exe.
Thank you!!
Great, thanks! A new version will be released soon
I can finally try this on my Linux laptop :P. I'll close this, the examples might be a whole other issue.
Mission completed indeed. Thank you for your time!
First off, thank you for your wonderful work! I've been tinkering on Windows with this, and anything that requires
raylib.dll
works, atleast the samples I tried. I'll be playing with this more!raylib-3.5.0_win64_mingw-w64.zip
if you are on a 64bits system orraylib-3.5.0_win32_mingw-w64.zip
if you are on a 32bits system./lib
folder in there you'll findraylib.dll
, put this dll in the same folder as your resulting.exe
file.So say we want to run this https://github.com/greenfork/nimraylib_now/blob/master/examples/shapes/bouncing_ball.nim example.
cd
yourself into the folder, runnim c -r .\bouncing_ball.nim
and make sure the dll is in the same folder, and you'll find yourself seeing this:Current issues
Testing doesn't work
Running
nimble testExamples
gives the following errorMaybe this is has to do with how paths are handled differently on Windows and Linux?
Raygui
I downloaded raygui.dll from your release page, put it next to raylib.dll but the example still fails with:
could not load: raygui.dll
RunningbuildRaygui
gives me the following error:This might have to do with me not having raygui.o anywhere. I'll try to troubleshoot this tonight or tomorrow.