Why i cant link Library and Header file

i have build on linux-debian.
but failed when i run command-line. Can some teach me how to link Library and Header file rigth way?

Hi @vitcon,

welcome to the GLFW forum. The easiest to make a GLFW program would be with this GLFW Cmake Starter:

The errors you are seeing are due to you not linking to the GLFW library, you need to add -lglfw. However after adding this you will likely get further errors due to needing to link to other libraries as well. You can use pkg-config to help configure the required compile-time and link-time flags and dependencies needed to use a library:
https://www.glfw.org/docs/latest/build_guide.html#build_link_pkgconfig

In future note that it’s easier for us if rather than attaching images you copy and paste the text from your console.

Good luck!

1 Like

Thanks you very much. This very useful for me. :smiling_face_with_three_hearts:

Linking errors like those are not necessarily because you omitted -lglfw, although this is what I would check first. Some linkers demand a specific way to link libraries, and the “correct” way may depend on the distribution you are using. For example, the “logical” way to link is -lGL -lglfw (first OpenGL, then GLFW) - and indeed it works just fine in most cases. However, I got linking errors like the ones you had on some Debian-based distributions, where -lglfw -lGL worked instead.

You can always add -Wl,--start-group before libraries and -Wl,--end-group at end, then rest of them can go in the middle in any order, like this:

-Wl,--start-group -lGL -lglfw -Wl,--end-group