Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of #includes to avoid linking errors

Tags:

c++

include

Sometimes in C++ the order of the includes matters. That is the case of openGL using :

1.- Right way:

#include <windows.h>                // Header File For Windows
#include <gl\glu.h>                 // Header File For The GLu32 Library

2.- Wrong way:

#include <gl\glu.h>                 // Header File For The GLu32 Library
#include <windows.h>                // Header File For Windows

Does this happen just for some specific headers or is it kind of a random problem difficult to prevent a priori?

If that is the case:

How can I know the right order of the includes?

like image 203
Jav_Rock Avatar asked Dec 28 '22 07:12

Jav_Rock


1 Answers

  1. Just some specific headers. Some might call it a design flaw.
  2. You can't. Look at the error messages you get and sort them out carefully. On windows, putting windows.h first is probably a good idea.
like image 175
Carl Norum Avatar answered Jan 08 '23 15:01

Carl Norum