Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Al_init is not defined

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Al_init is not defined
Naugrim00
Member #16,829
March 2018

Hello everyone,

I wanted to get into allegro for a project. So I installed allegro and put in the following code:

#SelectExpand
1#include "allegro5/allegro5.h" 2#include <iostream> 3#include "stdafx.h" 4 5int main(int argc, char** argv) 6{ 7 al_init(); 8 9 ALLEGRO_DISPLAY disp = al_create_display(100, 100); 10 11 return 0; 12}

But the problem is that I'm getting the following errors:

'al_init': identifier not found (r 7)
'al_create_display': identifier not found (r 9)
Incomplete type is not allowed (r 9)

Does anyone know how to fix this?
Kind regards

Mark Oates
Member #1,146
March 2001
avatar

If you followed the typical pattern of installation, then your include line for allegro should use angled brackets <...>.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Eric Johnson
Member #14,841
January 2013
avatar

No, don't use angle brackets use quotes

What's wrong with using angle brackets?

Neil Roy
Member #2,229
April 2002
avatar

You have a couple problems:

#include "allegro5/allegro5.h"

should be:

#include <allegro5/allegro5.h>

The same is true for #include "stdafx.h", that should be #include <stdafx.h>. You should only use quotes for local files you are loading from the same folder your other game source code files are in.

Also, your line;

ALLEGRO_DISPLAY disp = al_create_display(100, 100);

should be...

`ALLEGRO_DISPLAY *disp = al_create_display(100, 100);`

as al_create_display() returns a pointer.

So in summary, this is what your code should look like...

#include <allegro5/allegro5.h>
#include <iostream>
#include <stdafx.h>
   
int main(int argc, char** argv)
{
 al_init();
   
 ALLEGRO_DISPLAY *disp = al_create_display(100, 100);
  
 return 0;
}

---
“I love you too.” - last words of Wanda Roy

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Neil Roy
Member #2,229
April 2002
avatar

You're right about the extra 5, wrong about the angle brackets. The angle brackets indicate to load from the path in your setup. In my own setup in Code::Blocks I have added in a separate directory for library includes. So I use angle brackets for them.

Quotes are used for local files which are not in your include path in your preferences etc.

This is my includes for Allegro for my DP2 game; works just fine.

#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_physfs.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
#include <allegro5/allegro_opengl.h>
#include <physfs.h>

So he just needs to remove the extra 5 and make certain the location of the library is in his include path.

From MSDN...

Quoted form
-----------
The preprocessor searches for include files in this order:
1) In the same directory as the file that contains the #include statement.
2) In the directories of the currently opened include files, in the reverse order in which they were opened. The search begins in the directory of the parent include file and continues upward through the directories of any grandparent include files.
3) Along the path that's specified by each /I compiler option.
4) Along the paths that are specified by the INCLUDE environment variable.

Angle-bracket form
------------------
The preprocessor searches for include files in this order:
1) Along the path that's specified by each /I compiler option.
2) When compiling occurs on the command line, along the paths that are specified by the INCLUDE environment variable.

---
“I love you too.” - last words of Wanda Roy

Chris Katko
Member #1,881
January 2002
avatar

By your own post, it doesn't matter if he uses "" for system / allegro includes.

But I've always been taught <> for sys libraries. "" For local.

It just appears local, then searches system libs if it can't find it.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Neil Roy
Member #2,229
April 2002
avatar

You guys LOVE to argue and debate. LMFAO Hey, do what ever fucking works. Wow.

---
“I love you too.” - last words of Wanda Roy

Chris Katko
Member #1,881
January 2002
avatar

NO. ONLY DO IT MY WAY. EVERY ONE ELSE IS WRONG.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Mark Oates
Member #1,146
March 2001
avatar

Brackets <...> are what you should be using for your allegro includes.

Your projects shouldn't be in your libs path and allegro (whatever version you're using) shouldn't be in your project's path. You're free to do it wrong if you want, of course.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Neil Roy
Member #2,229
April 2002
avatar

Well sorry Edgar, but putting "PERIOD" in there doesn't make it final!!!

My Allegro install is NOT IN MY COMPILER'S SYSTEM FOLDER! It is a totally separate folder! As should everyone else's if you want to avoid problems.

In my own setup my compiler is in "C:\MINGW32", my libraries I add to my system like Allegro, SDL2 etc... are all in "C:\MINGW_DEV_LIBS". I use Code::Blocks as my IDE and on it,. I go to SETTINGS->COMPILER then select the "SEARCH DIRECTORIES" tab and add "C:\MinGW_Dev_Lib\include" to my "COMPILER" tab and "C:\MinGW_Dev_Lib\lib" to the "LINKER" tab which also contains the relavant "C:\MinGW32" folders.

I then add Allegro 5 with: #include <allegro5/allegro.h>

THAT is how you properly do it. You can also add in separate folders for your lib in a similar way for each project. There is a similar way to set this up with Visual Studio.

I can't believe you don't know this. I think you just like to argue endlessly.

---
“I love you too.” - last words of Wanda Roy

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Okay Neil, answer this. How do you include cmath? Do you use quotes or brackets? I would hope your answer would be brackets, because it's a system library. How is Allegro a system library? So why should I use angle brackets?

This is retarded but it works :

#include "cmath"
#include "cstdio"

int main(int argc , char** argv) {
   
   printf("sqrt(3) is %f\n" , sqrt(3.0f));
   
   return 0;
}

Likewise this is retarded, but it works as well :

#include <allegro5/allegro.h>

But the appropriate way to include a library in your code is to use quotes, unless it is a system library.

Dizzy Egg
Member #10,824
March 2009
avatar

I use square brackets, like:

#include [allegro5/allegro]

which doesn't compile at all, but its my right to do what I want regardless of the correct way, so suck it.

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

GullRaDriel
Member #3,861
September 2003
avatar

Brackets are overrated. I just stares at my compilers until it reads in my mind the libs I want.

8-)

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Peter Hull
Member #1,136
March 2001

You could argue about this, or you could read the standard.

Or you can do what Dizzy does, which at least is consistent across all known platforms. :P

LennyLen
Member #5,313
December 2004
avatar

You could argue about this, or you could read the standard.

The standard says that there is no standard for what to do with either <> or "". It's implementation defined.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Here's what gcc says...

Quote:

#include <file>

This variant is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the -I option (see Invocation).

#include "file"

This variant is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for <file>. You can prepend directories to the list of quote directories with the -iquote option.

You can use whatever you want and it will work, but allegro is not a system header nor is it a system library, so it should not be treated as such.

Neil Roy
Member #2,229
April 2002
avatar

The reason why `#include ""` works, according to the standard is because when it fails (fails to find any local files), than it switches to the <> method. So the reason why quotes work for you is because according to the standard, it will use the angle brackets method when the quotes FAIL, which according to most of the standard implementation, it WILL fail every time as it will not find the file locally and so will switch to searching using the angle brackets method, which searches system folders where the compiler exists and any other you included in setup (which is what I do).

But do it the way you wish, whatever, but don't sit there on your high horse saying "NO, JUST NO" every time someone is trying to HELP!

---
“I love you too.” - last words of Wanda Roy

Mark Oates
Member #1,146
March 2001
avatar

Dizzy Egg said:

I use square brackets, like:

#include [allegro5/allegro]

which doesn't compile at all, but its my right to do what I want regardless of the correct way, so suck it.

This is the correct answer 8-)

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Now it looks like Obj-C ;P

The point is, in the old days it was considered fine and fair practice to install everything into your compiler's bin,lib,and include directories. Today we know that's nonsense because that's how version mis-matches get created. Everything should be installed separately from your compiler. If it didn't come with your compiler, then chances are that it doesn't belong there. This also allows you to hot-swap versions of the libraries you use depending on a simple -I directive. The fact that both <> and "" search these folders doesn't matter. To be strict and fair, <> shouldn't search those folders. When you specify "" you are saying this file is NOT a system file, so categorically it shouldn't be searching in system directories! ;) ;P

Chris Katko
Member #1,881
January 2002
avatar

I always use double white space to mean single quotes, and triple white space to mean double quotes, and then I have a pre-processor stage convert them at compile time.

That way, I only have to use one key, space. It's way faster.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Eric Johnson
Member #14,841
January 2013
avatar

I always use double white space to mean single quotes, and triple white space to mean double quotes, and then I have a pre-processor stage convert them at compile time.

That way, I only have to use one key, space. It's way faster.

You might like the Whitespace programming language then. ;D

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

 1   2 


Go to: