Error compiling code

What is a Uzebox? How can I get one? Check here!
zigfreid
Posts: 16
Joined: Sun Aug 16, 2020 5:54 am

Re: Error compiling code

Post by zigfreid »

Jubatian wrote: Mon Aug 17, 2020 4:20 pm Could you try a compile removing the following line from Video Mode 2's source?

https://github.com/Uzebox/uzebox/blob/m ... ode2.c#L41

I don't even know how it is supposed to work with that line there as the structure is provided by the assembly source, so there indeed should be a conflict (and it is odd that I don't receive any, it compiles, and appears to run fine). The structure is visible to the C source as the header provides the declaration.

Once compiled that way could you try SpriteDemo and Zombienator? (These two are those which use Video Mode 2) If they work, I will commit the fix, I am just unsure as to why it even works the way it is on other compiler versions (as I think it just shouldn't).
Thankyou sir. That helps. Now i receive similar error from "Whack-a-Mole":
avr-gcc -mmcu=atmega644 -Wl,-Map=Whack-a-Mole.map -Wl,-gc-sections uzeboxVideoEngineCore.o gui.o uzeboxCore.o uzeboxSoundEngine.o uzeboxSoundEngineCore.o uzeboxVideoEngine.o Whack-a-Mole.o -o Whack-a-Mole.elf
/usr/bin/avr-ld: Whack-a-Mole.o:/home/vitaly/uzebox-master/demos/Whack-a-Mole/default/../Whack-a-Mole.c:118: multiple definition of `mx'; uzeboxCore.o:/home/vitaly/uzebox-master/demos/Whack-a-Mole/default/../../../kernel/uzeboxCore.c:390: first defined here
/usr/bin/avr-ld: Whack-a-Mole.o:/home/vitaly/uzebox-master/demos/Whack-a-Mole/default/../Whack-a-Mole.c:118: multiple definition of `my'; uzeboxCore.o:/home/vitaly/uzebox-master/demos/Whack-a-Mole/default/../../../kernel/uzeboxCore.c:390: first defined here
/usr/bin/avr-ld: Whack-a-Mole.o:/home/vitaly/uzebox-master/demos/Whack-a-Mole/default/../Whack-a-Mole.c:121: multiple definition of `actionButton'; uzeboxCore.o:/home/vitaly/uzebox-master/demos/Whack-a-Mole/default/../../../kernel/uzeboxCore.c:389: first defined here
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:85: Whack-a-Mole.elf] Error 1
make: *** [Makefile:138: demos/Whack-a-Mole/default] Error 2
I guess that i have to remove something somewhere again.
zigfreid
Posts: 16
Joined: Sun Aug 16, 2020 5:54 am

Re: Error compiling code

Post by zigfreid »

I will try to run SpriteDemo and Zombienator later, and inform here.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Error compiling code

Post by Artcfox »

I'm guessing those whack-a-mole errors (it certainly feels like we are playing whack-a-mole!) are due to this:
(C11 6.9.2 p1-2):

If the declaration of an identifier for an object has file scope and an initializer, the declaration is an external definition for the identifier.

A declaration of an identifier for an object that has file scope without an initializer, and without a storage-class specifier or with the storage-class specifier static, constitutes a tentative definition. If a translation unit contains one or more tentative definitions for an identifier, and the translation unit contains no external definition for that identifier, then the behavior is exactly as if the translation unit contains a file scope declaration of that identifier, with the composite type as of the end of the translation unit, with an initializer equal to 0.
It appears that both the game and the kernel are defining global variables with the same name, which is undefined behavior. Without looking closely, I'm not sure if the intent of the game code was to declare those variables as extern and to have the game modify the variables defined in the kernel, or if it was just an unfortunate naming collision on the part of the game, but I am inclined to believe the prior.

I've been responsible for quite a few compiler upgrades on large codebases, and every single time it makes me say "How did the old compiler even accept this?!" :lol:
zigfreid
Posts: 16
Joined: Sun Aug 16, 2020 5:54 am

Re: Error compiling code

Post by zigfreid »

Hello!
I fixed "Whack-a-Mole" by myself, but now i'm getting linker error in the "Zombienator":
avr-gcc -mmcu=atmega644 -Wl,-Map=Zombienator.map -Wl,-gc-sections uzeboxVideoEngineCore.o uzeboxCore.o uzeboxSoundEngine.o uzeboxSoundEngineCore.o uzeboxVideoEngine.o Zombienator.o structures.o videoengine.o mechanics.o necromancy.o guns.o -o Zombienator.elf
/usr/bin/avr-ld: Zombienator.o:/home/vitaly/uzebox-master/demos/Zombienator/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x440): first defined here
/usr/bin/avr-ld: structures.o:/home/vitaly/uzebox-master/demos/Zombienator/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x440): first defined here
/usr/bin/avr-ld: videoengine.o:/home/vitaly/uzebox-master/demos/Zombienator/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x440): first defined here
/usr/bin/avr-ld: mechanics.o:/home/vitaly/uzebox-master/demos/Zombienator/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x440): first defined here
/usr/bin/avr-ld: necromancy.o:/home/vitaly/uzebox-master/demos/Zombienator/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x440): first defined here
/usr/bin/avr-ld: guns.o:/home/vitaly/uzebox-master/demos/Zombienator/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x440): first defined here
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:94: Zombienator.elf] Error 1
make: *** [Makefile:138: demos/Zombienator/default] Error 2
Could you please help again ? Thanks.
User avatar
Jubatian
Posts: 1563
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Error compiling code

Post by Jubatian »

Artcfox wrote: Tue Aug 18, 2020 3:13 amIt appears that both the game and the kernel are defining global variables with the same name, which is undefined behavior. Without looking closely, I'm not sure if the intent of the game code was to declare those variables as extern and to have the game modify the variables defined in the kernel, or if it was just an unfortunate naming collision on the part of the game, but I am inclined to believe the prior.

I've been responsible for quite a few compiler upgrades on large codebases, and every single time it makes me say "How did the old compiler even accept this?!" :lol:
Yuck! Holy moly... This mouse code is horrible. I am leaning towards that indeed the game is designed to take those kernel variables, that when an actual mouse is present, the kernel would update them, otherwise it emulates mouse over them using the SNES controllers. Those "mx" and "my" variables seemingly accidentally global in the kernel are just awful. There are functions to get them, so it would seem they are local, but no "static" on them. And the other stuff, with no occurrence in kernel headers, is actually used by the whack-a-mole game...

I would still say, toss a "static" on https://github.com/Uzebox/uzebox/blob/m ... ore.c#L390 , and if the game breaks with a mouse, it breaks, somebody encountering it with an actual mouse should fix that later. It is totally unreasonable to have such 2 letter variables as globals, could easily clash with anything.
User avatar
Jubatian
Posts: 1563
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Error compiling code

Post by Jubatian »

zigfreid wrote: Wed Aug 19, 2020 3:53 pmHello!
I fixed "Whack-a-Mole" by myself, but now i'm getting linker error in the "Zombienator":
This after applying the fix I mentioned earlier? Could you please check that and report how the games are affected? (Still waiting for it before committing)
zigfreid
Posts: 16
Joined: Sun Aug 16, 2020 5:54 am

Re: Error compiling code

Post by zigfreid »

Jubatian wrote: Wed Aug 19, 2020 4:01 pm
zigfreid wrote: Wed Aug 19, 2020 3:53 pmHello!
I fixed "Whack-a-Mole" by myself, but now i'm getting linker error in the "Zombienator":
This after applying the fix I mentioned earlier? Could you please check that and report how the games are affected? (Still waiting for it before committing)
I can confirm that line:
struct SpriteStruct sprites[MAX_SPRITES];
is removed from file videoMode2.c when i running compilator. And i'm still getting the error above for "Zombienator".
User avatar
Jubatian
Posts: 1563
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Error compiling code

Post by Jubatian »

zigfreid wrote: Thu Aug 20, 2020 2:25 am... is removed from file videoMode2.c when i running compilator. And i'm still getting the error above for "Zombienator".
What is on Line 69 of kernel/videoMode2/videoMode2.h in your repo at the moment? Feels odd that it reports failures referring to that line, which is an external (the line should read as "extern struct SpriteStruct sprites[];"). Could you do a "make clean" and try to build it again? Maybe something wasn't recompiled after a fix, and thus the linker still conflicts when trying to link together those objects.
zigfreid
Posts: 16
Joined: Sun Aug 16, 2020 5:54 am

Re: Error compiling code

Post by zigfreid »

Jubatian wrote: Thu Aug 20, 2020 7:30 pm Could you do a "make clean" and try to build it again? Maybe something wasn't recompiled after a fix, and thus the linker still conflicts when trying to link together those objects.
After "make clean" the same error appeared again:
avr-gcc -mmcu=atmega644 -Wl,-Map=Zombienator.map -Wl,-gc-sections uzeboxVideoEngineCore.o uzeboxCore.o uzeboxSoundEngine.o uzeboxSoundEngineCore.o uzeboxVideoEngine.o Zombienator.o structures.o videoengine.o mechanics.o necromancy.o guns.o -o Zombienator.elf
/usr/bin/avr-ld: Zombienator.o:/home/vitaly/uzebox-master/demos/Zombienator/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x440): first defined here
/usr/bin/avr-ld: structures.o:/home/vitaly/uzebox-master/demos/Zombienator/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x440): first defined here
/usr/bin/avr-ld: videoengine.o:/home/vitaly/uzebox-master/demos/Zombienator/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x440): first defined here
/usr/bin/avr-ld: mechanics.o:/home/vitaly/uzebox-master/demos/Zombienator/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x440): first defined here
/usr/bin/avr-ld: necromancy.o:/home/vitaly/uzebox-master/demos/Zombienator/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x440): first defined here
/usr/bin/avr-ld: guns.o:/home/vitaly/uzebox-master/demos/Zombienator/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x440): first defined here
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:94: Zombienator.elf] Error 1
make: *** [Makefile:138: demos/Zombienator/default] Error 2
I'm checked line 69 in the file kernel/videoMode2/videoMode2.h and found described string:
extern struct SpriteStruct sprites[];
So i'm very confused, what is wrong ? Should I try again from download, unpack, compile sources ?
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Error compiling code

Post by Artcfox »

I'm pretty sure you need to remove this line from the game code: https://github.com/Uzebox/uzebox/blob/m ... res.h#L159
Post Reply