I am using GLFW libraries in my *.c program.
#include <GL/glfw.h>
#include <stdlib.h>
int main(void)
{
int running = GL_TRUE;
int k=0;
.....
...
..
The command I use to compile is:
gcc test1.c -o test1 -lglfw
My question is that, since this line is present:
#include <GL/glfw.h>
why do I have to pass -lglfw to gcc?
GL/glfw.h is a header file, it declares all the types, constants, functions, you know the drill, it’s to make the compiler know what code to generate and to make it not complain about unknown identifiers. libglfw is a library that contains the actual binary code (or stubs that will be bound later by the dynamic linker, or something like that), you have to link with it to make the linker not complain about unresolved symbols.
It’s possible for the header to contain the actual source code of the library (so the compiler will generate the binary code over and over again for each translation unit where the library is used), it’s called a header-only library then, but in the C world such libraries aren’t something that you can find often and this particular library is not header-only.