this post was submitted on 07 Sep 2023
3 points (100.0% liked)

C Programming Language

931 readers
22 users here now

Welcome to the C community!

C is quirky, flawed, and an enormous success.
... When I read commentary about suggestions for where C should go, I often think back and give thanks that it wasn't developed under the advice of a worldwide crowd.
... The only way to learn a new programming language is by writing programs in it.

ยฉ Dennis Ritchie

๐ŸŒ https://en.cppreference.com/w/c

founded 1 year ago
MODERATORS
 

Hello,

I've installed the library called Raylib (https://www.raylib.com/). I followed the instructions to install the dynamic library. However, when compiling using gcc, including the raylib.h header dynamically in the source code produces an undefined reference error for every function I use from that library. That means that the library functions weren't attached to the executable at runtime, so gcc didn't find the right .so file.

To actually produce an executable, I have to use a shell script, that for some reason needs raylib's source code path. But that goes against the point of installing a dynamic library, since the latter is used so that source code can be compiled without library functions, instead putting them somewhere else to be shared with other executables.

Can someone explain to me how gcc finds the .so files and if anyone has used raylib dou you understand what the shell script does?

top 3 comments
sorted by: hot top controversial new old
[โ€“] [email protected] 1 points 11 months ago* (last edited 11 months ago) (1 children)

You'd need at least -L/path/to/raylib/dir where the raylib.so is and -lraylib in the compiler line. Order matters, search around.

[โ€“] [email protected] 2 points 11 months ago

If there's a .pc file shipped, pkg-config can simplify your life by figuring out the flags for you.

[โ€“] [email protected] 1 points 7 months ago

I have installed gcc and Raylib from msys2.

And compile my code with it using:

gcc test.c -lraylib -lopengl32 -lgdi32 -lwinmm