April 25, 2024, 01:07:27 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


$MAIN issue

Started by J B Wood (Zumwalt), January 03, 2008, 10:42:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

J B Wood (Zumwalt)


$MAIN
$INCLUDE "B3DSDK_EBasic.inc"

sub main
dim test as int
test=bbBeginBlitz3D()
if test=1
DEBUGPRINT "Good"
ELSE
DEBUGPRINT "bad"
ENDIF
bbEndBlitz3D()
ENDSUB


Still gives me the old unresolved external _ib_main in my project.
Makes me feel stupid at times.

Ionic Wind Support Team

First, there is no 'main' sub in an EBasic project, that is what $main is for.  It marks the beginning execution point of your program, and there can be only one.

Second, make sure you have selected the correct project type and try this:


$main
$INCLUDE "B3DSDK_EBasic.inc"

dim test as int
test=bbBeginBlitz3D()
if test=1
DEBUGPRINT "Good"
        ELSE
DEBUGPRINT "bad"
ENDIF
bbEndBlitz3D()
END
Ionic Wind Support Team

J B Wood (Zumwalt)

Neither of these suggestions were the problem.
The project type is windows vs console.
The $MAIN "should" mark the begining of the execution point, notice it is at the top of the eba file.
What I did after about an hour of beating on it Paul, was move the $main into my inc file.
Then it compiles and works.

If you have a $INCLUDE, the $main in the eba is ignored and $INCLUDE supercedes it.
Thats a compile order issue.
You will want that in your book for EBasic, when creating a project, if you have $INCLUDE files, the first one put your $MAIN in it otherwise you will get an error.

The program works with or without my sub main, that is misleading for this problem since I use subs to house code blocks in ebasic and I label my first one sub main. My inc file has declare and cdecl's in it so they naturally come before my rest of the appliction.

I realise your answer was an off the hip shot, so thanks for trying to help.

To discover the bug, create a new project in EBasic, add 2 files, an eba file and an inc file.
In the inc file create a cdecl import, have autodefine off then in your eba, include that inc file after you declare $MAIN at the top, compile and try to run.

For me, this is a consistant ib_main error.

LarryMc

I always have $MAIN before my $INCLUDE in all of my projects and have never had a problem.  So, to me, that would appear NOT to be the problem in and of itself.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Same here, can't duplicate the problem Jonathan.   Currently working on a contracted project that has 10 separate modules, each has $main at the top before multiple include statements.  The modules have been compiled on 4 or 5 different machines without issues.

Besides that I have dozens of personal projects that include windows.inc right after the $main declaration without a problem.  On top of that the technique has been in use since IBasic Pro, so that's 5 years without an issue.

since I don't have the B3DSDK I can't look into it further.   More than likely there is a conflict/error in the include file that is causing it.  Or your compiler installation is munged which could be solved be a reinstallation.

Quote
The program works with or without my sub main,

Which is also not possible.  Nothing is calling your 'main' sub, unless there is code that is in that include file and not just declare statements.

All $main does is generate a global label for the linker to find.  Very simple code which makes it very difficult to circumvent.  If you look at any Emergence generated assembly file you will see this when you have used $main:


global _ib_main
_ib_main:


Right after all of the externs and defines, before any of the actual assembly code.   The 'main' subroutine that the linker calls exists in one of three modules, winmain.o for example.  Which contains the startup code.  That startup code calls _iib_main with an assembly jump statement. 

So the execution point of your program is right after that label. 

Paul.

Ionic Wind Support Team

J B Wood (Zumwalt)

No biggie at this point, later in the code I called my little main, but since I have fixed it I have redone the labeling of that sub to a generic test name.
Who knows, if no one else has the problem and it works fine then great, I just chuck it up to a machine issue and move on.
I have redone the $MAIN out of my INC for distribution and placed things where they should work for everyone else, I'll move all of this to another machine later and just blame this laptop, it is HP after all.