Page 1 of 1

Strange compiler errors [solved]

Posted: Sat Aug 02, 2014 8:22 am
by twosixonetwo
While changing my code I encountered the following situation:
Let's say I have this code:

Code: Select all

void handleJoyEvent(u16 joy, u16 changed, u16 state);

u8 readVDP60hz()
{
	return (*((u16*)(0xC00004)))&0x1;
};

int main()
{
    // [...]

    JOY_setEventHandler(handleJoyEvent);
    // [...]
}
//no declaration of handleJoyEvent follows
Instead of complaining that I don't declare what handleJoyEvent does, I get these Errors:

Code: Select all

C:/sgdk/lib/libmd.a(main.o): In function `readVDP60hz':
main.c:(.text+0x178): multiple definition of `readVDP60hz'
out/src/main.o:main.c:(.text+0xf8): first defined here
C:/sgdk/lib/libmd.a(main.o): In function `main':
main.c:(.text+0x184): multiple definition of `main'
out/src/main.o:main.c:(.text+0x104): first defined here
C:/sgdk/bin/ld: Warning: size of symbol `main' changed from 232 in out/src/main.
o to 330 in C:/sgdk/lib/libmd.a(main.o)
make: *** [out/rom.out] Error 1
I don't have multiple declarations of those functions, neither in main.c nor in multiple files. If I remove the JOY_setEventHandler-call the code compiles fine (without warnings).

Does someone know why that is? Might this be due to my makefile or is this unavoidable?

Posted: Sat Aug 02, 2014 9:25 am
by Stef
I think there is something really wrong in your makefile, i guess you don't use the one included in SGDK ?

Posted: Sat Aug 02, 2014 12:50 pm
by twosixonetwo
Well, the newest makefile doesn't work for me since I've got the sega.s and the rom_head.c in my src folder:

Code: Select all

C:\sgdk\projects\SVPDemo>%GDK_WIN%\bin\make -f makefile.gen
make: *** No rule to make target `C:/sgdk/src/boot/sega.s', needed by `src/boot/sega.s'.  Stop.
If I change

Code: Select all

$(SRC)/boot/sega.s: $(LIBSRC)/boot/sega.s
	$(MKDIR) -p $(SRC)/boot
	$(CP) $< $@

$(SRC)/boot/rom_head.c: $(LIBSRC)/boot/rom_head.c
	$(MKDIR) -p $(SRC)/boot
	$(CP) $< $@
to

Code: Select all

$(SRC)/boot/sega.s: $(SRC)/boot/sega.s
	$(MKDIR) -p $(SRC)/boot
	$(CP) $< $@

$(SRC)/boot/rom_head.c: $(SRC)/boot/rom_head.c
	$(MKDIR) -p $(SRC)/boot
	$(CP) $< $@
the compilation works AND I am getting the compiler error I've described above :?

Posted: Sat Aug 02, 2014 5:50 pm
by Chilly Willy
You have an extra ";" following the close brace for readVDP60hz().

Posted: Sat Aug 02, 2014 7:25 pm
by twosixonetwo
Yes, that's unnecessary, doesn't create any problems though. (IIRC) it's merely an empty statement.
I removed it and the strange compiler message remains...

Posted: Sat Aug 02, 2014 10:03 pm
by Stef
Did you removed the sega.s file from the base SGDK folder ?
If yes you should not do it, the new makefile will just copy the sega.s from the original SGDK folder then you can freely modify it if you want...
From your error it looks like you removed the original sega.s file.

Posted: Mon Aug 04, 2014 11:35 am
by twosixonetwo
Ahh... well now I realize what your change meant. I have never written a makefile from scratch and wasn't really aware of how the change was supposed to work.

So, I now use the newest makefile (https://code.google.com/p/sgdk/source/b ... n194&r=194) and the strange compiler errors are still there.

If I have a little more time I might narrow it down to a test case and see if it has to do with the implementation of JOY_setEventHandler, compiler version or mistakes in my code ;)

Posted: Wed Aug 06, 2014 10:21 am
by twosixonetwo
Case closed. Updated sgdk from 0.95 to 0.96d and the strange errors went away. Sorry for the confusion caused. :oops:

Posted: Wed Aug 06, 2014 12:03 pm
by Stef
Glad to hear you fixed it :)