Search code examples
c++openglgccflags

C++ where are the flags for linking libraries documented?


With every new library I want to use I have noticed there is a specific flag, or set of flags, I have to add to the compile in order for it to actually link the library.

For example with GL GLEW and GLUT I use "-lglut -lGLU -lGL".

The problem is the only way to find these flags that I need is to search endlessly on google for them. Is there a 'standard' place to find these flags for any library? Are they appended to the tops of the headers or something? I hope it's just something obvious I'm missing.


Solution

  • I'll assume you are asking about GCC/G++ compiler.

    The flag is -l<libName>, where <libName> is the name of the library you want to link against. For example, -lGL links against the GL library.

    The reason some libraries require multiple flags in certain order is simply the way they depend on each other (the libraries your library depends on might also depend on some other ones, and so on). The library's documentation should solve the problem in most cases.