undefined reference to main

SGDK only sub forum

Moderator: Stef

Post Reply
tobeder
Interested
Posts: 10
Joined: Tue Sep 09, 2014 4:40 pm

undefined reference to main

Post by tobeder » Tue Sep 09, 2014 4:45 pm

Hi!

I was trying to setup and run the HelloWorld demo on Windows 7 but I'm getting this message:

Code: Select all

11:28:49 **** Build of configuration Debug for project HelloWorld ****
"C:\\genesis\\sdk\\bin\\make" -f "C:/genesis/sdk\\makefile.gen" 
C:/genesis/sdk/bin/gcc -BC:/genesis/sdk/bin -n -T C:/genesis/sdk/md.ld -nostdlib out/sega.o @out/cmd_ C:/genesis/sdk/lib/libmd.a C:/genesis/sdk/lib/libgcc.a -o out/rom.out
C:/genesis/sdk/lib/libmd.a(sys.o): In function `_start_entry':
sys.c:(.text+0x8ea): undefined reference to `main'
C:/genesis/sdk/lib/libmd.a(sys.o): In function `_reset_entry':
sys.c:(.text+0x8f8): undefined reference to `main'
make: *** [out/rom.out] Error 1
I include the SGDK bin folder to my Path and follow the Eclipse Tutorial

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue Sep 09, 2014 6:35 pm

Seems like make cannot find your project sources file.
I don't use Eclipse myself but you probably have something wrong on your project settings.

tobeder
Interested
Posts: 10
Joined: Tue Sep 09, 2014 4:40 pm

Post by tobeder » Wed Sep 10, 2014 5:37 pm

Before checking the project settings I can't compile from Eclipse so I tried the command line and I can do it. I'm stuck at the Multi tiles part of the tutorial (the moon) I can't compile the source code from the command line. Here's the error:

Code: Select all

C:\genesis\projects\tut3_TilesBitmap\3_TilesBitmap>%GDK_WIN%/bin/make -f %GDK_WI
N%/makefile.gen
C:/genesis/sdk/bin/mkdir -p out
C:/genesis/sdk/bin/mkdir -p out/src
C:/genesis/sdk/bin/mkdir -p out/res
C:/genesis/sdk/bin/gcc -m68000 -Wall -fno-builtin -Iinc -Isrc -Ires -IC:/genesis
/sdk/inc -IC:/genesis/sdk/res -BC:/genesis/sdk/bin -O1 -fomit-frame-pointer -c m
ain.c -o out/main.o
main.c:6:18: moon.h: No such file or directory
main.c: In function `main':
main.c:14: error: `moon' undeclared (first use in this function)
main.c:14: error: (Each undeclared identifier is reported only once
main.c:14: error: for each function it appears in.)
make: *** [out/main.o] Error 1

tobeder
Interested
Posts: 10
Joined: Tue Sep 09, 2014 4:40 pm

Post by tobeder » Wed Sep 10, 2014 10:37 pm

I find that I need to create the .res file in order to generate the moon.h

I can compile the example but I'm getting a weird result.

Code: Select all

Here's my code:

#include <genesis.h>
#include "moon.h"

int main()
{

           // get the image width (in pixel) ==> should be 8pix aligned
           u16 w = moon.w;
           // get the image height (in pixel)  ==> should be 8px aligned
           u16 h = moon.h;

           // get the palette data of moon
		   VDP_setPalette(PAL1, moon.palette->data);

           // load bitmap data of moon in VRAM
           // w/8 = width in tiles we want to load
           // h/8 = height in tile we want to load
           // w/8 = width in tiles of the bitamp
           // the 3rd arg is needed because you could load only a part of the bitmap if you want but SGDK needs the width as reference
           VDP_loadBMPTileData((u32*)moon.image, 1, w / 8, h / 8, w/8 );


           // draw the moon at (12,12)
		   VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, 1), 12, 12, w / 8, h / 8);

        while(1)
        {
           VDP_waitVSync();
        }
        return 0;
}
Imagemoon by tobeder, on Flickr

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu Sep 11, 2014 8:32 am

Unfortunately some sections in the wiki are outdated.
SGDK resources management changed and so you need to define all resources in a .res (rescomp tool) or .rc (genres tool).
rescomp offers you a sort of backward compatibility mode to generate automatically the .res file :

Code: Select all

rescomp -convert <input>
For instance you can run it from your project folder just this way :

Code: Select all

rescomp -convert .
and you should obtain a fresh 'converted.res' file.
The resources are converted to keep compatibility with older projects.

With the newer rescomp tool, you can just declare your moon image as IMAGE resource :

Code: Select all

IMAGE moon "moon.png" -1
then in your code you can just use this method to display it :

Code: Select all

VDP_drawImage(VDP_PLAN_A, &moon, 0, 0);
Easier is not it ? ;)

tobeder
Interested
Posts: 10
Joined: Tue Sep 09, 2014 4:40 pm

Post by tobeder » Thu Sep 11, 2014 4:26 pm

Easier is not it ? :wink:
Nice!

That's a lot easier :D
Now the moon example is working. Thank you!

Would be nice to have an updated version in the wiki.

ImagemoonOK by tobeder, on Flickr

Here is the code:

hola.c

Code: Select all

#include <genesis.h>
#include "moon.h"

int main()
{

   // draw the moon at (12,12)
   VDP_drawBitmap(VDP_PLAN_A, &moon, 12, 12);

	while(1)
	{
	   VDP_waitVSync();
	}
	return 0;
}
moon.res

Code: Select all

BITMAP moon "moon.bmp" -1
Last edited by tobeder on Thu Sep 11, 2014 10:17 pm, edited 1 time in total.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu Sep 11, 2014 6:41 pm

Actually declaring it as BITMAP make it having linear memory as in a bitmap buffer, this type of resource is more suited for the bitmap mode (BMP_xxx stuff in SGDK). When you deal with default VDP drawing (background plan) it's better to use IMAGE as it's organized as the megadrive video hardware expect it and so it's faster (don't need memory re organization) ;)

tobeder
Interested
Posts: 10
Joined: Tue Sep 09, 2014 4:40 pm

Post by tobeder » Thu Sep 11, 2014 10:13 pm

I see. Then the code is:

hola.c

Code: Select all

#include <genesis.h>
#include "moon.h"

int main()
{

   // draw the moon at (12,12)
   VDP_drawImage(VDP_PLAN_A, &moon, 12, 12);

	while(1)
	{
	   VDP_waitVSync();
	}
	return 0;
}
moon.res

Code: Select all

IMAGE moon "moon.bmp" -1
Thank you! :D

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu Sep 11, 2014 10:18 pm

Yeah, that is perfect now !

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: undefined reference to main

Post by POLYGAMe » Sat Jan 09, 2016 1:18 am

Gah! Been pulling my hair out over this... my old projects weren't working. Haha. Thank god for the forum again!

raindropua
Newbie
Posts: 2
Joined: Fri Sep 09, 2016 12:10 pm
Location: Ukraine
Contact:

Re: undefined reference to main

Post by raindropua » Mon Jan 22, 2018 1:22 pm

Hello, everyone. Maybe someone can help me. I stuck by compilation problem. I have this issue only with one PC with Win7, and on Win10 there is no problem with same project.

So there is log:

Code: Select all

C:\SGDK\bin\make -f C:\SGDK\makefile.gen
C:/SGDK/bin/mkdir -p src/boot
C:/SGDK/bin/mkdir -p out
C:/SGDK/bin/mkdir -p out/src
C:/SGDK/bin/mkdir -p out/res
C:/SGDK/bin/gcc -BC:/SGDK/bin -n -T C:/SGDK/md.ld -nostdlib out/sega.o @out/cmd_ C:/SGDK/lib/libmd.a C:/SGDK/lib/libgcc.a -o out/rom.out
C:\Users\Home\AppData\Local\Temp\ccDmOXsz.ltrans4.ltrans.o: In function `_reset_entry':
<artificial>:(.text+0x768): undefined reference to `main'
C:\Users\Home\AppData\Local\Temp\ccDmOXsz.ltrans4.ltrans.o: In function `_start_entry':
<artificial>:(.text+0x818): undefined reference to `main'
make: *** [out/rom.out] Error 1
This error appears with all actual versions of SGDK, at least from version 1.22. SGDK library itself compiles on both PC without any issues. There is no any IDE, console only. What did I miss? Please give me some advice.
Thank you in advance.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: undefined reference to main

Post by Chilly Willy » Mon Jan 22, 2018 2:42 pm

Shouldn't that ref be "_main"? Looks like the compiler isn't adding the underscore. There's an option for that, but I forget what it is offhand.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: undefined reference to main

Post by Stef » Mon Jan 22, 2018 3:17 pm

2 possibilities :
- you're trying to build the library with the makefile.gen (instead of makelib.gen)
- you're trying to build a project without any main() method in it
Is it one of these ?

raindropua
Newbie
Posts: 2
Joined: Fri Sep 09, 2016 12:10 pm
Location: Ukraine
Contact:

Re: undefined reference to main

Post by raindropua » Mon Jan 22, 2018 4:04 pm

Stef wrote:
Mon Jan 22, 2018 3:17 pm
2 possibilities :
- you're trying to build the library with the makefile.gen (instead of makelib.gen)
- you're trying to build a project without any main() method in it
Is it one of these ?
Unfortunately no. It would be too easy. I build the library with the makelib.gen and it builds successfully every time.

Issue only with project building (with makefile.gen). My project does contain the main() method in it. I use the same project and .bat file to run the building on both systems. On Win10 it builds successfully but on Win7 error occurs. :(

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: undefined reference to main

Post by Stef » Mon Jan 22, 2018 7:04 pm

Ok, so you may have another GCC toolchains or cygwing conflicting maybe...
You need to check your path environment variable and if you have other toolchains installed.

Post Reply