I return to the embrace of allegro and the setup of it in VS2008 is so troublesome, can someone please help me?

I followed a video in youtube, and for future, I type the action into a text file, here it is:

1) Copy the contents of E:\Raymond\game programming\allegro-msvc9-4.2.3\bin to C:\Program Files\Microsoft Visual Studio 9.0\VC\bin .
2) Copy the contents of E:\Raymond\game programming\allegro-msvc9-4.2.3\include to C:\Program Files\Microsoft Visual Studio 9.0\VC\include .
3) Copy the contents of E:\Raymond\game programming\allegro-msvc9-4.2.3\lib to C:\Program Files\Microsoft Visual Studio 9.0\VC\lib .
4) Copy the contents of E:\Raymond\game programming\allegro-msvc9-4.2.3\bin to C:\WINDOWS\system32

Then we open VS2008. This what the author of the video do:

5) Open VS2008, create a new Win32 project ( not console ). Select empty project.
6) Add a main.cpp in source folder.
7) On the Tabs, Click "Project" then click [Project name] property.
8) Choose "Configuration Property" and expand it.
9) Choose "Linker" and expland it. Click "Input".
10) Click Additional Dependencies, Add "alld.lib". Click OK.
alld.lib
alleg.lib
alld_s.lib
alleg_s.lib
alleg_s_crt.lib
allp.lib
allp_s.lib

11) In main.cpp, write:

#include <allegro.h>
int main()
{
allegro_init();
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
install_keyboard();
textout_ex(screen, font, "Welcome to allegro!", 0,0, makecol(0, 0, 255), makecol(255,0,0));
readkey();
return 0;

}
END_OF_MAIN();

When I ran it, it got errors:

1>------ Build started: Project: win32_allegro1, Configuration: Debug Win32 ------
1>Linking...
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>C:\Documents and Settings\Raymond.Yeung\Desktop\GUI\win32_allegro1\Debug\win32_allegro1.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\Raymond.Yeung\Desktop\GUI\win32_allegro1\win32_allegro1\Debug\BuildLog.htm"
1>win32_allegro1 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Then I think it would be a console project if we use int main(),
so I repeat 5) to 11), and make it a win32 console project.

5) Open VS2008, create a new Win32 console project. Select empty project.

Then I ran it again, it still goes error

1>------ Build started: Project: console_allegro1, Configuration: Debug Win32 ------
1>Linking...
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Documents and Settings\Raymond.Yeung\Desktop\GUI\console_allegro1\Debug\console_allegro1.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\Raymond.Yeung\Desktop\GUI\console_allegro1\console_allegro1\Debug\BuildLog.htm"
1>console_allegro1 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I search up the internet about "_main referenced in function ___tmainCRTStartup",
and one of the post suggest adding "#define ALLEGRO_USE_CONSOLE" on the top of main.cpp, so I followed.

#define ALLEGRO_USE_CONSOLE
#include <allegro.h>
int main()
{
	allegro_init();
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	install_keyboard();
	textout_ex(screen, font, "Welcome to allegro!", 0,0, makecol(0, 0, 255), makecol(255,0,0));
	readkey();
	return 0;

}
END_OF_MAIN();

Then I ran it again and there are no more error, it gave me 2 windows,
one is the console windows, another is a windows with text saying "Welcome to allegro!".

Here is the question: How can we remove the console windows??

Dani AI

Generated

Short diagnosis and the clean fix
Your link errors and the extra console are classic Allegro/VS issues: Allegro uses a small “magic main” shim (END_OF_MAIN()) to turn your normal main() into the Windows WinMain() entry point, so the normal solution is to build a Windows GUI application (not a console app) and let Allegro provide the WinMain wrapper — do not use ALLEGRO_USE_CONSOLE for a GUI build. (liballeg.org)

Recommended steps (what I’d try first)

  • Remove the ALLEGRO_USE_CONSOLE define. Keep END_OF_MAIN() right after main().
  • In Visual Studio set the linker subsystem to Windows (Project → Properties → Linker → System → Subsystem = Windows).
  • Make sure you’ve linked the correct Allegro libraries for the active configuration (Debug vs Release) and that the library search path is set in the project (don’t rely on copying files into system folders). Also verify your C runtime choice matches the Allegro build (debug/release). The official MSVC/Allegro notes explain these points. (liballeg.org)

If you still get “unresolved WinMain”
That means the Allegro “magic main” object wasn’t pulled into the link (wrong library variant, wrong configuration, or ALLEGRO_NO_MAGIC_MAIN set). Check Additional Dependencies for the active configuration and library order. As a last-resort workaround you can force the CRT to use main as the entry point (e.g. /ENTRY:mainCRTStartup via a pragma or linker option) — it works but is a hack; better to fix the proper Allegro/link settings. ()

If you prefer to hide the console at runtime
You can call the Win32 API to hide it after creating your Allegro display:

#include <windows.h>

// after allegro init / after creating the display:
ShowWindow(GetConsoleWindow(), SW_HIDE);

That’s simple and commonly used, but including Windows headers can trigger the BITMAP name clash (wingdi.h vs Allegro’s BITMAP). If you run into that, add NOGDI to your preprocessor definitions (or define it before including Windows headers) so wingdi won’t declare the conflicting GDI types. Use this only if you can’t get the proper GUI/subsystem build working. (stackoverflow.com)

Notes tied to the thread
— you already saw the two behaviors (WinMain unresolved for a Windows project, _main unresolved for a console project); follow the “Recommended steps” block above and double-check which Allegro lib files you linked for Debug vs Release. ’s links point toward runtime-hiding approaches (useful as a fallback), but the long-term fix is to set the subsystem and link the matching Allegro build. (liballeg.org)

Recommended Answers

All 2 Replies

I've found a few bits on hiding the console window:
http://www.franz.com/support/documentation/7.0/doc/operators/cg/h/hide-console.htm

Please upvote this post if it helps :)

For the first link, I don't know how to use that~

and for the others, it seems to collide with allegro's BITMAP definition~

e:\raymond\game programming\allegro-msvc9-4.2.3\include\allegro\system.h(31) : error C2371: 'BITMAP' : redefinition; different basic types
1> c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(567) : see declaration of 'BITMAP'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.