Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Unresolved external _main

Credits go to BAF, ReyBrujo, and Ultio for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
Unresolved external _main
Ceagon Xylas
Member #5,495
February 2005
avatar

I'm using Borland 5.5 to compile this script:

1#include <stdlib.h>
2#include <allegro.h>
3#include <winalleg.h>
4 
5int main(int argc, char *argv[]) {
6 allegro_init();
7 install_keyboard();
8 set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0);
9 clear_to_color(screen, makecol(0,0,0));
10 text_mode(-1);
11 textprintf(screen,font,0,0,makecol(255,255,255),"Hello world");
12 
13 readkey();
14 
15 allegro_exit();
16 return 0;
17}
18END_OF_MAIN();

And I get an error...
Error: Unresolved external '_main' referenced from C:\BORLAND\BCC55\LIB\C0X32.OBJ

I thought I knew how to fix this, but after an hour, I'm still clueless :-[

Ultio
Member #1,336
April 2001

You don't need the semicolon after END_OF_MAIN(). Also, are you sure you have the IDE linking against Allegro? In addition to that, why are you including winalleg.h? As far as I can tell, with the code you have there, you don't need to include it. I may be wrong though. I've never used Borland to compiled anything in regards to Allegro.

---
"It's nice knowing that someday, the software I write will just be pirated by millions of people." :-/
http://loomsoft.net | Zep's Dreamland | Allegro Newbie Tutorials

Mark Oates
Member #1,146
March 2001
avatar

hmm.... you did include liballeg? That's the only thing I can think of. :-/

Arthur Kalliokoski
Second in Command
February 2005
avatar

I think you have to COMMENT OUT the "#include <winalleg.h>", which is more for if the allegro stuff is just a module in a larger windows prog?

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

BAF
Member #2,981
December 2002
avatar

why borland? Try mingw?

Arthur Kalliokoski
Second in Command
February 2005
avatar

BAF, have you ever used the Turbo Debugger? I like it way better than any other debugger including gdb. Once you get it working then back to mingw! (Some small tests I did had Borland anywhere as fast as mingw on the "good" end to 20 percent slower on the "bad" end, and LCC was 70 percent slower! Although asm beat them all by 20 percent) (mandelbrot set)

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

ReyBrujo
Moderator
January 2001
avatar

_main is used by DOS and console projects. When you create a Win32 project, it will try to use _WinMain. So, you built a console project. Try adding #define ALLEGRO_USE_CONSOLE before including Allegro, or create a Win32 project instead of a console one.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Ceagon Xylas
Member #5,495
February 2005
avatar

I've tried everything suggested here, (except for ReyBrujo's suggestion to make a win32 project,) and none of them work. Borland doesnt use projects (as far as i know), so how would I go about building this program as a Win32 project... I tried #define ALLEGRO_USE_CONSOLE but still got the same error >.<

[edit]
Ok, adding the -tW switch builds it as a win32 program. Now I'm getting almost the same error, but windowsafied -- Unresolved external 'WinMain' referenced from C:\BORLAND\BCC55\LIB\C0W32.OBJ.

If I include the winalleg.h, it gives me a list of errors --

Error: Unresolved external '_install_allegro' referenced from C:\BORLAND\BCC55\BIN\MAIN.OBJ
Error: Unresolved external '_install_keyboard' referenced from C:\BORLAND\BCC55\BIN\MAIN.OBJ
Error: Unresolved external '_set_gfx_mode' referenced from C:\BORLAND\BCC55\BIN\MAIN.OBJ
Error: Unresolved external '_text_mode' referenced from C:\BORLAND\BCC55\BIN\MAIN.OBJ
Error: Unresolved external '_makecol' referenced from C:\BORLAND\BCC55\BIN\MAIN.OBJ
Error: Unresolved external '_font' referenced from C:\BORLAND\BCC55\BIN\MAIN.OBJ
Error: Unresolved external '_screen' referenced from C:\BORLAND\BCC55\BIN\MAIN.OBJ
Error: Unresolved external '_textprintf' referenced from C:\BORLAND\BCC55\BIN\MAIN.OBJ
Error: Unresolved external '_readkey' referenced from C:\BORLAND\BCC55\BIN\MAIN.OBJ
Error: Unresolved external '_allegro_exit' referenced from C:\BORLAND\BCC55\BIN\MAIN.OBJ
Error: Unresolved external '__WinMain' referenced from C:\BORLAND\BCC55\BIN\MAIN.OBJ

ReyBrujo
Moderator
January 2001
avatar

Now all your errors are linking errors, so you forgot to link against Allegro library. Which command line you used? You forgot to put alleg.lib somewhere.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Ceagon Xylas
Member #5,495
February 2005
avatar

I've tried

bcc32 -IC:\borland\bcc55\include -LC:\borland\bcc55\lib -LC:\borland\bcc55\lib\alleg.lib -tW main.cpp
//same WinMain error

and

bcc32 -IC:\borland\bcc55\include -LC:\borland\bcc55\lib\alleg.lib -tW main.cpp
//unable to open C0W32.obj

BAF
Member #2,981
December 2002
avatar

figure out cow32..

Try #define ALLEGRO_NO_MAGIC_MAIN too.

Ceagon Xylas
Member #5,495
February 2005
avatar

w00t! I finally got it -- even though my program crashes.. Hehehe...
At least it compiles!

Ok, so what I finally had to do was only include stdlib.h and allegro.h.
For my command line use

bcc32 -IC:\borland\bcc55\include -LC:\borland\bcc55\lib -tW main.cpp

I thought I had tried this before -- apparently it liked me this time and let me compile... Now I have to figure out why its crashing ;D
Thanks so very much guys!

[edit]
So basically...from what I've tested, my compiler doesnt compile win32 applications correctly. [?] =/ Umm... I tried to compile a simple program like this:

#include <stdlib.h>
#include <stdio.h>

main() {
  printf("Hello world");
  system("PAUSE");
  return 0;
}

It crashes too... Its nothing that has to do width Allegro -- sence I compiled this dependant of Allegro. I compiled it without the -tW switch, and it works fine. ::)

BAF
Member #2,981
December 2002
avatar

What does -tW do?

Ceagon Xylas
Member #5,495
February 2005
avatar

compiles as a win32 application.

[edit]
That was a close one, tobi (msg below) xD

Tobi Vollebregt
Member #1,031
March 2001

BAF:

Ceagon Xylas said:

Ok, adding the -tW switch builds it as a win32 program.

EDIT: beaten

________________________________________
website || Zipfile reader @ Allegro Wiki || Download zipfile reader

Ceagon Xylas
Member #5,495
February 2005
avatar

After 12 hours...Still no luck xD

ReyBrujo
Moderator
January 2001
avatar

Check makefile.bcc, there is the command line used to compile with Borland BCC. Search for the ilink command.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

marcin
Member #5,814
May 2005

Make config files:

Bcc32.cfg

-DWINVER=0x0400
-D_WIN32_WINNT=0x0400
-I"c:\Borland\Bcc55\include"
-L"c:\Borland\Bcc55\lib"

Ilink32.cfg

-L"c:\Borland\Bcc55\lib"

Options:

-DWINVER=0x0400
-D_WIN32_WINNT=0x0400

are undocumented but they are necessary for winXP.

And "-tW" option is for WINAPI programs and for allegro, I think, you need command line window program (both types are WIN programs, command line isn't DOS program :)).

[url]
http://www.webnotes.org/bcc55eng.htm
[/url]

(Copy and paste this link as text into your browser, it doesn't work directly, I don't know why...)

COX32.obj is run time library, I had problem with it at start of manual compiling and linking. If you first create *.obj and next you want link *.obj files you have to add to linker command line switches run time libraries explicite. So the best way is to compile and link at once.

I have found it, the best link, you have everything about manual linking here:

[url]
http://www.winprog.org/tutorial/bcpp.html
[/url]

(Copy and paste this link as text into your browser, it doesn't work directly, I don't know why...)

I used bcc5.5 but I have checked that gcc (devc++ or with cygwin) under winXP gives much faster code.

Ceagon Xylas
Member #5,495
February 2005
avatar

Quote:

COX32.obj is run time library, I had problem with it at start of manual compiling and linking. If you first create *.obj and next you want link *.obj files you have to add to linker command line switches run time libraries explicite. So the best way is to compile and link at once.

How do I go about doing this?
:borland n00b:

...Sorry about takin so long to reply; was on vacation. ;D

Matt Smith
Member #783
November 2000

Quote:

and for allegro, I think, you need command line window program

No, you want a windowed application, even if your program runs full screen

marcin
Member #5,814
May 2005

Could you write, once again, command line you actually use.

Did you make Bcc32.cfg and Ilink32.cfg files?

Did you read /allegro-x.x.x/docs/build/bcc32.txt file (section Using Allegro) ?

Ceagon Xylas
Member #5,495
February 2005
avatar

Quote:

Could you write, once again, command line you actually use.

I change it up all the time...but its something like
bcc32 -Lc:\borland\bcc55\lib -Ic:\borland\bcc55\lib -tW main.cpp

Quote:

Did you make Bcc32.cfg and Ilink32.cfg files?

Did you read /allegro-x.x.x/docs/build/bcc32.txt file (section Using Allegro)?

Yes.

marcin
Member #5,814
May 2005

Quote:

bcc32 -Lc:\borland\bcc55\lib -Ic:\borland\bcc55\lib -tW main.cpp

( -Ic:\borland\bcc55\lib )

"-I" switch is path to include folder not to lib folder

------------------------------------

Quote:

bcc32 -Lc:\borland\bcc55\lib -Ic:\borland\bcc55\lib -tW main.cpp
-------------------
Did you make Bcc32.cfg and Ilink32.cfg files?

Yes.
-------------------

So you don't need in command line "-L" and "-I" switches because you have it in Bcc32.cfg file.

-------------------

Do you have allegro.lib file in:
c:\borland\bcc55\lib

Do you have allegro headers in:
c:\borland\bcc55\include

Do you have allegro.dll in system folder?

Quote:

bcc32 -Lc:\borland\bcc55\lib -Ic:\borland\bcc55\lib -tW main.cpp

main.cpp is:

allegro program or

"hello world" command line program or

"hello world" WINAPI program?

If it's allegro program you have to add to command line allegro.lib file that has information about functions in allegro.dll (*.lib is export library for *.dll dynamic library)

If it's only "hello ..." command line program "-tW" option is bad.

If it's "hello ..." GUI program "-tW" option is necessary but you need code for creating example windows window (calling WINAPI functions) (about one page of code), not simply "hello ..." code with main() function.

********************************************

EDIT:

HA HA HA HA HA HA HA HA HA.......;D

---------------------------------------------------------------

E:\E\src\allegro\examples>bcc32 exhello.c alleg.lib -tW

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland

exhello.c:

Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

Error: Unresolved external '_main' referenced from C:\BORLAND\BCC55\LIB\C0X32.OBJ

E:\E\src\allegro\examples>

---------------------------------------------------------------

E:\E\src\allegro\examples>bcc32 -tW exhello.c alleg.lib

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland

exhello.c:

Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

E:\E\src\allegro\examples>

----------------------------------------------------------------

Do you see the difference !!!

HA HA HA, 5 days, HA HA HA ......

********************************************

Ceagon Xylas
Member #5,495
February 2005
avatar

ROTFL! but theres still a problem...

Um... when i try to run my program -- it crashes... I have the dlls in the folder, and not using any other outside sources...

Tobias Dammers
Member #2,604
August 2002
avatar

Two words:
1. mingw
2. gdb

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

 1   2 


Go to: