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

C Programming Language

993 readers
1 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
[โ€“] 0x0@programming.dev 1 points 1 year ago* (last edited 1 year 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.

[โ€“] o11c@programming.dev 2 points 1 year ago

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

[โ€“] modev@programming.dev 1 points 10 months ago

I have installed gcc and Raylib from msys2.

And compile my code with it using:

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