Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example raylib: error on Windows 10 #141

Open
renlite opened this issue Apr 20, 2024 · 3 comments
Open

Example raylib: error on Windows 10 #141

renlite opened this issue Apr 20, 2024 · 3 comments

Comments

@renlite
Copy link

renlite commented Apr 20, 2024

Tried raylib pkg to install but get following errors.

$> onyx package add raylib
$>        ←[32mAdded  ←[39m'raylib' version 0.0.7
$> ←[0m

$> onyx package sync
$>        ←[32mFetch  ←[39mhttp://github.com/onyx-lang/pkg-raylib  0.0.7
$> ←[0m     ←[32mInstall  ←[39mRunning installation of './lib\github.com\onyx-lang\pkg-raylib'
$> ←[0m←[31m       Error  ←[39mFailed to build native library in ./lib\github.com\onyx-lang\pkg-raylib.
$> ←[0m←[31m       Error  ←[39mAborting sync.
$> ←[0m

The project structure and .kdl files seem to be correct.

image

@renlite
Copy link
Author

renlite commented Apr 20, 2024

Does this mean I could fetch the raylib.dll and put it into a special dirctory?
What would be the steps to try it?
image

@brendanfh
Copy link
Collaborator

Natively compiled packages are currently not really supported on Windows, for the reason in the comment you found. That will be addressed at some point when a good solution is found.

To get this working for now, you will have to go into the build.onyx file in the raylib package and comment out the code that compiles and deletes the C file. Then, from within the pkg-raylib folder, run the following command:

$ onyx run --generate-foreign-info build.onyx

That should make a C file in the current directory. You then need to compile that C file using cl.exe or msvc, along with the ray lib.lib file in the windows folder, into a DLL. That DLL can then be move to a folder called bin at the root of your project, and has to be called onyx_raylib.dll. I think everything should work then?

I've never actually done this on Windows, but I believe that should do the trick. Let me know if anything needs clarification.

@renlite
Copy link
Author

renlite commented Apr 21, 2024

Some notes:
In build.onyx the path := module_path(#file); seems not to work. No file was created. After I changed the path manually for onyx_raylib.c in build.onyx the generate_c_bindings created the file.

Then I started Developer PowerShell for VS 2022. After some #include errors I changed the form of Lib-Path to local include: eg #include "raylib.h" and copied required files into raylib directory.

$ cd ->\lib\github.com\onyx-lang\pkg-raylib\raylib
$ cl.exe /LD .\onyx_raylib.c .\windows\raylib.lib
$
$ many errors for all referenced functions in raylib:
$ onyx_raylib.obj : error LNK2019: Reference to external symbol "_InitWindow" in function "___onyx_internal_onyx_raylib_InitWindow".
$ ...
$ onyx_raylib.dll : fatal error LNK1120: 499 no solved extern

An onyx_raylib.dll could not be created.

image

A lot of C libs offer a dynamic lib for many platforms that could be used to load dynamically and bind to the .dll (.so) from Onyx. In the module.onyx file of raylib pkg there are the C bindings already defined (#foreign block). Why is a separate generation of onyx_raylib.c necessary to include the C lib? Usually a language with C FFI loads a dynamic lib and uses bind coding in the other language to find and call the C functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants