schveiguy / raylib-d

Resurrected copy of onroundit's raylib-d
zlib License
56 stars 14 forks source link

Trying to build the example fails #1

Closed RealDoigt closed 3 years ago

RealDoigt commented 3 years ago
doigt@doigt-pc:~/Documents/d projs/raylibexp$ dub build
Performing "debug" build using /usr/bin/gdc for x86_64.
ddmp 0.0.1-0.dev.3: target for configuration "library" is up to date.
stdx-allocator 2.77.5: target for configuration "library" is up to date.
libdparse 0.14.0: target for configuration "library" is up to date.
fluent-asserts 0.13.3: target for configuration "library" is up to date.
raylibexp ~master: building configuration "application"...
/usr/bin/ld: /tmp/ccIFlABw.o: in function `_Dmain':
/home/doigt/Documents/d projs/raylibexp/source/app.d:10: undefined reference to `SetTargetFPS'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:11: undefined reference to `InitWindow'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:15: undefined reference to `WindowShouldClose'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:17: undefined reference to `BeginDrawing'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:21: undefined reference to `ClearBackground'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:22: undefined reference to `DrawText'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:19: undefined reference to `EndDrawing'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:13: undefined reference to `CloseWindow'
collect2: error: ld returned 1 exit status
/usr/bin/gdc failed with exit code 1.
schveiguy commented 3 years ago

This is an issue with the linker. You need to include the C library with your build.

Unfortunately, when the original github account was deleted, so was a lot of the infrastructure around it, including wiki information.

What OS are you working with?

RealDoigt commented 3 years ago

Ubuntu 21.04 Linux 5.11.0-17-generic x86_64 (Kubuntu)

I did try to include the files but I'm not sure how or where to put them of if there's a compiler command to include them specifically like in C.

schveiguy commented 3 years ago

I recommend downloading the prebuilt binary libraries from the raylib github repository, e.g.: https://github.com/raysan5/raylib/releases/tag/3.7.0

That is quite a bit newer than the last version that I tested raylib-d against. But assuming nothing has changed in terms of API, it should work.

In order to link on Linux, you need to provide lflags of -LpathToLib in your dub file. See lflags information here: https://dub.pm/package-format-json.html#build-settings.

Another option is to put the library file in /usr/lib, as I believe the linker will search there for libraries.

schveiguy commented 3 years ago

So as an example, if your library file is in the folder ~/raylib-3.7.0-linux/lib, you would add to your dub file like:

"lflags" : ["-L/home/username/raylib-3.7.0-linux/lib"]
schveiguy commented 3 years ago

Closing unless you have some more issue, feel free to ping me!

RealDoigt commented 3 years ago

sorry I was busy today, how do you add a relative path? I also tried

"lflags" : ["-L./lib"]

but it didn't work

schveiguy commented 3 years ago

Hm..., so inside the lib directory in your project folder, is libraylib.a or libraylib.so? I would think that would be how you specify a relative path.

You can use -v on dub to see what it's actually passing to the compiler.

RealDoigt commented 3 years ago

There doesn't to seem to be any log in relation to what I added to the dub.json file.

doigt@doigt-pc:~/Documents/d projs/raylibexp$ dub build -v
Using dub registry url 'https://code.dlang.org/'
Refreshing local packages (refresh existing: true)...
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/doigt/.dub/packages/local-packages.json
Looking for local package map at /home/doigt/Documents/d projs/raylibexp/.dub/packages/local-packages.json
Note: Failed to determine version of package raylibexp at .. Assuming ~master.
Refreshing local packages (refresh existing: false)...
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/doigt/.dub/packages/local-packages.json
Looking for local package map at /home/doigt/Documents/d projs/raylibexp/.dub/packages/local-packages.json
  Found dependency raylib-d 3.0.4
    Found dependency fluent-asserts 0.13.3
      Found dependency ddmp 0.0.1-0.dev.3
      Version selection for dependency unit-threaded (unit-threaded) of fluent-asserts is missing.
      Missing dependency unit-threaded >=0.0.0 (optional) of fluent-asserts
      Found dependency libdparse 0.14.0
        Found dependency stdx-allocator 2.77.5
Refreshing local packages (refresh existing: false)...
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/doigt/.dub/packages/local-packages.json
Looking for local package map at /home/doigt/Documents/d projs/raylibexp/.dub/packages/local-packages.json
  Found dependency raylib-d 3.0.4
    Found dependency fluent-asserts 0.13.3
      Found dependency ddmp 0.0.1-0.dev.3
      Version selection for dependency unit-threaded (unit-threaded) of fluent-asserts is missing.
      Missing dependency unit-threaded >=0.0.0 (optional) of fluent-asserts
      Found dependency libdparse 0.14.0
        Found dependency stdx-allocator 2.77.5
Generating using build
Configuring dependent raylibexp, deps:"fluent-asserts"
  Configuring dependent fluent-asserts, deps:"ddmp", "libdparse"
    Configuring dependent ddmp, deps:
    Configuring dependent libdparse, deps:"stdx-allocator"
      Configuring dependent stdx-allocator, deps:
Performing "debug" build using /usr/bin/gdc for x86_64.
ddmp 0.0.1-0.dev.3: target for configuration "library" is up to date.
Using existing build in /home/doigt/.dub/packages/ddmp-0.0.1-0.dev.3/ddmp/.dub/build/library-debug-linux.posix-x86_64-gdc_2076-2EDB8E8E90E61A9745BF110410530710/.
Copying target from /home/doigt/.dub/packages/ddmp-0.0.1-0.dev.3/ddmp/.dub/build/library-debug-linux.posix-x86_64-gdc_2076-2EDB8E8E90E61A9745BF110410530710/libddmp.a to /home/doigt/.dub/packages/ddmp-0.0.1-0.dev.3/ddmp
stdx-allocator 2.77.5: target for configuration "library" is up to date.
Using existing build in /home/doigt/.dub/packages/stdx-allocator-2.77.5/stdx-allocator/.dub/build/library-debug-linux.posix-x86_64-gdc_2076-319042CD813C3FB46C926212EA888193/.
Copying target from /home/doigt/.dub/packages/stdx-allocator-2.77.5/stdx-allocator/.dub/build/library-debug-linux.posix-x86_64-gdc_2076-319042CD813C3FB46C926212EA888193/libstdx-allocator.a to /home/doigt/.dub/packages/stdx-allocator-2.77.5/stdx-allocator
libdparse 0.14.0: target for configuration "library" is up to date.
Using existing build in /home/doigt/.dub/packages/libdparse-0.14.0/libdparse/.dub/build/library-debug-linux.posix-x86_64-gdc_2076-328651CA0C466028FF5AEB947F0210CA/.
Copying target from /home/doigt/.dub/packages/libdparse-0.14.0/libdparse/.dub/build/library-debug-linux.posix-x86_64-gdc_2076-328651CA0C466028FF5AEB947F0210CA/libdparse.a to /home/doigt/.dub/packages/libdparse-0.14.0/libdparse
fluent-asserts 0.13.3: target for configuration "library" is up to date.
Using existing build in /home/doigt/.dub/packages/fluent-asserts-0.13.3/fluent-asserts/.dub/build/library-debug-linux.posix-x86_64-gdc_2076-53B180D66C3255040577AFF0D005E48D/.
Copying target from /home/doigt/.dub/packages/fluent-asserts-0.13.3/fluent-asserts/.dub/build/library-debug-linux.posix-x86_64-gdc_2076-53B180D66C3255040577AFF0D005E48D/libfluent-asserts.a to /home/doigt/.dub/packages/fluent-asserts-0.13.3/fluent-asserts
Target '/home/doigt/Documents/d projs/raylibexp/.dub/build/application-debug-linux.posix-x86_64-gdc_2076-7461B03CAD70BC4A4BF9C68C1C9BA109/raylibexp' doesn't exist, need rebuild.
raylibexp ~master: building configuration "application"...
/usr/bin/gdc -o .dub/build/application-debug-linux.posix-x86_64-gdc_2076-7461B03CAD70BC4A4BF9C68C1C9BA109/raylibexp -fdebug -g -Werror -Wall -fversion=Have_raylibexp -fversion=Have_raylib_d -fversion=Have_fluent_asserts -fversion=Have_ddmp -fversion=Have_libdparse -fversion=Have_stdx_allocator -Isource/ -I../../../.dub/packages/raylib-d-3.0.4/raylib-d/source/ -I../../../.dub/packages/fluent-asserts-0.13.3/fluent-asserts/source/ -I../../../.dub/packages/ddmp-0.0.1-0.dev.3/ddmp/source/ -I../../../.dub/packages/libdparse-0.14.0/libdparse/src/ -I../../../.dub/packages/stdx-allocator-2.77.5/stdx-allocator/source/ source/app.d ../../../.dub/packages/raylib-d-3.0.4/raylib-d/source/easings.d ../../../.dub/packages/raylib-d-3.0.4/raylib-d/source/raygui.d ../../../.dub/packages/raylib-d-3.0.4/raylib-d/source/raylib.d ../../../.dub/packages/raylib-d-3.0.4/raylib-d/source/raymath.d ../../../.dub/packages/raylib-d-3.0.4/raylib-d/source/raymathext.d ../../../.dub/packages/raylib-d-3.0.4/raylib-d/source/rlgl.d ../../../.dub/packages/fluent-asserts-0.13.3/fluent-asserts/.dub/build/library-debug-linux.posix-x86_64-gdc_2076-53B180D66C3255040577AFF0D005E48D/libfluent-asserts.a ../../../.dub/packages/ddmp-0.0.1-0.dev.3/ddmp/.dub/build/library-debug-linux.posix-x86_64-gdc_2076-2EDB8E8E90E61A9745BF110410530710/libddmp.a ../../../.dub/packages/libdparse-0.14.0/libdparse/.dub/build/library-debug-linux.posix-x86_64-gdc_2076-328651CA0C466028FF5AEB947F0210CA/libdparse.a ../../../.dub/packages/stdx-allocator-2.77.5/stdx-allocator/.dub/build/library-debug-linux.posix-x86_64-gdc_2076-319042CD813C3FB46C926212EA888193/libstdx-allocator.a -Xlinker -L./lib
/usr/bin/ld: /tmp/ccnDEBGQ.o: in function `_Dmain':
/home/doigt/Documents/d projs/raylibexp/source/app.d:10: undefined reference to `SetTargetFPS'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:11: undefined reference to `InitWindow'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:15: undefined reference to `WindowShouldClose'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:17: undefined reference to `BeginDrawing'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:21: undefined reference to `ClearBackground'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:22: undefined reference to `DrawText'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:19: undefined reference to `EndDrawing'
/usr/bin/ld: /home/doigt/Documents/d projs/raylibexp/source/app.d:13: undefined reference to `CloseWindow'
collect2: error: ld returned 1 exit status
FAIL .dub/build/application-debug-linux.posix-x86_64-gdc_2076-7461B03CAD70BC4A4BF9C68C1C9BA109/ raylibexp executable
/usr/bin/gdc failed with exit code 1.
schveiguy commented 3 years ago

It's in there, at the end: -L./lib. But I don't see -lraylib anywhere. Did you add "raylib" to your "libs" flags?

Can you post your dub.json?

RealDoigt commented 3 years ago

no, I didn't understand that I had to add it.

dub.txt

schveiguy commented 3 years ago

OK, try:

{
    "authors": [
        "Doigt"
    ],
    "copyright": "Copyright © 2021, Doigt",
    "dependencies": {
        "raylib-d": "~>3.0.4"
    },
    "description": "Candidate tech expirements for jam",
    "license": "GNU-3.0",
    "name": "raylibexp",
    "libs": ["raylib"],
    "lflags" : ["-L./lib"]
}

Note the "libs" part I added. Then inside the lib directory, make sure libraylib.so or libraylib.a (whichever you have as a binary) is present.

RealDoigt commented 3 years ago

The building works but the generated file won't run; it says it can't find the raylib library file:

doigt@doigt-pc:~/Documents/d projs/raylibexp$ ./raylibexp
./raylibexp: error while loading shared libraries: libraylib.so.370: cannot open shared object file: No such file or directory

I've tried putting the required file in the same directory level, but it won't find it still.

├── dub.json
├── dub.selections.json
├── include
│   └── raylib.h
├── lib
│   ├── libraylib.a
│   ├── libraylib.so -> libraylib.so.370
│   ├── libraylib.so.3.7.0
│   └── libraylib.so.370 -> libraylib.so.3.7.0
├── libraylib.so.3.7.0
├── raylibexp
└── source
    └── app.d

edit: I've now tried unloading the whole contents of lib in the same folder to no avail

schveiguy commented 3 years ago

You need to set the environment variable LD_LIBRARY_PATH for the Linux dynamic linker to find that library.

I recommend the full path, as relative paths might change if you run the program from another directory.

e.g.:

export LD_LIBRARY_PATH=/path_to_project/lib

Then try running. Alternatively, I see libraylib.a in there, you can remove the .so files and it should pick the static library to link against, which means you won't need the dynamic library any more.

RealDoigt commented 3 years ago

Ah, well the reason I wanted a relative path is because I was planning to make a game with raylib and ship all the required files in one easy to find place like you would for a dotnet/mono, nodejs or rust app... which is all I know how to do. What you're telling me is frankly hard to grasp and I don't really understand what you're explaining to me.

schveiguy commented 3 years ago

My recommendation is to just remove the .so files in that case. Then the library gets embedded into your application.

So the only file that should remain in lib should be libraylib.a. On Linux, .a means "archive", and .so means "shared object". The .a file is the static lib.

Then rebuild (you may have to do dub clean), and you won't need to deal with the shared libraries. Linux isn't built the same as Windows (where you can just stick the dll in the local directory), you need to allow it to load shared libraries from non-standard directories by setting your environment variables.

RealDoigt commented 3 years ago

I see, that's useful to know! Thank you, it worked well.