gcc cannot find -lglfw3
Asked Answered
T

3

12

I'm on a linux system (arch linux specifically) and I'm trying to compile the introduction project from the official glfw page but I cannot seem to get gcc to compile it. If anyone doesn't know what I'm talking about it's this.

Also this is how I'm trying to compile it:

gcc -Iinclude test.c -o test -lglfw3 -lm -lGL -lGLU

and it gives me the following errors:

/usr/bin/ld: cannot find -lglfw3

collect2: error: ld returned 1 exit status
Tolliver answered 10/5, 2017 at 5:26 Comment(0)
T
17

I completely forgot about this question until I got a notification for it. For me the solution was to not use -lglfw3 but rather use -lglfw

Tolliver answered 13/3, 2018 at 20:29 Comment(2)
This fixed my problem too, after 2 hours of struggle. Thank you from the bottom of my heart. Anyone has any idea why this happens? -lglfw vs -lglfw3 ??Apomixis
@MihaiAlexandruManolescu that's just the way the library was packaged. The actual file name is libglfw.so so adding a 3 obviously messes up the search. If you're asking why it's packaged that way then that would be a little harder to tell, you'd have to ask the person packaging it. Probably because they want whatever program linked with glfw to always use the latest version of the library and that can be achieved by just naming it glfw rather than adding on the version numberTolliver
W
3

If you've installed pkg-config, and glfw3.pc is in the search path, try:

gcc -Iinclude test.c -o test `pkg-config --libs glfw3` -lm -lGL -lGLU

If you only have the static build, use: pkg-config --static --libs glfw3, which will add the dependencies that libglfw3.a requires.

Wagonage answered 19/5, 2017 at 12:7 Comment(0)
M
1

Find libglfw3.a or libglfw3.so on your system Mention that path to gcc using -L

gcc -Iinclude test.c -o test -L/dir/where/glfw3/resides -lglfw3 -lm -lGL -lGLU
Mamba answered 10/5, 2017 at 5:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.