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

Error compiling code

Post by zigfreid »

I'm compiling code from sources on my linux system. But getting this error:
===================================
Building demo: demos/MegaSokoban/default
===================================
make -C demos/MegaSokoban/default UZEBIN_DIR=/home/vitaly/uzebox-master/bin/
avr-gcc -mmcu=atmega644 -Wl,-Map=MegaSokoban.map -Wl,-gc-sections uzeboxVideoEngineCore.o uzeboxCore.o uzeboxSoundEngine.o uzeboxSoundEngineCore.o uzeboxVideoEngine.o MegaSokoban.o -o MegaSokoban.elf
/usr/bin/avr-ld: MegaSokoban.o: in function `sokoban':
/home/vitaly/uzebox-master/demos/MegaSokoban/default/../MegaSokoban.c:677: undefined reference to `sokoban_move'
/usr/bin/avr-ld: /home/vitaly/uzebox-master/demos/MegaSokoban/default/../MegaSokoban.c:682: undefined reference to `sokoban_is_level_cleared'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:79: MegaSokoban.elf] Error 1
make: *** [Makefile:138: demos/MegaSokoban/default] Error 2
"avr-gcc -v" command output:
Using built-in specs.
Reading specs from /usr/lib/gcc/avr/10.1.0/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/10.1.0/lto-wrapper
Target: avr
Configured with: /build/avr-gcc/src/gcc-10.1.0/configure --disable-install-libiberty --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-linker-build-id --disable-nls --disable-werror --disable-__cxa_atexit --enable-checking=release --enable-clocale=gnu --enable-gnu-unique-object --enable-gold --enable-languages=c,c++ --enable-ld=default --enable-lto --enable-plugin --enable-shared --infodir=/usr/share/info --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --prefix=/usr --target=avr --with-as=/usr/bin/avr-as --with-gnu-as --with-gnu-ld --with-ld=/usr/bin/avr-ld --with-plugin-ld=ld.gold --with-system-zlib --with-isl --enable-gnu-indirect-function
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 10.1.0 (GCC)
Maybe somebody already solved this ? Could you please help ? Thanks.
User avatar
Jubatian
Posts: 1564
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Error compiling code

Post by Jubatian »

Could you test this with your distro's packaged avr-gcc? This is a pretty new version of gcc, guessing you might have installed it yourself.

I checked the code which gives you the error, I see nothing odd in it, the referenced functions exist in it, sokoban_move() certainly without any dubious construct (sokoban_is_level_cleared misses "void" in its parameter list, which is not entirely right), and seems like we are looking at the same checkout (current Uzebox Master).

How did you install this version of GCC? (for reference, might try to reproduce the setup in a virtual machine, though hoping the problem is found without that, aren't really keen on investing so much time on it if it is possible to be avoided)
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Error compiling code

Post by Artcfox »

Does making that function "static inline void" change anything, or removing the "inline" from it?
zigfreid
Posts: 16
Joined: Sun Aug 16, 2020 5:54 am

Re: Error compiling code

Post by zigfreid »

Jubatian wrote: Sun Aug 16, 2020 1:00 pm Could you test this with your distro's packaged avr-gcc? This is a pretty new version of gcc, guessing you might have installed it yourself.

I checked the code which gives you the error, I see nothing odd in it, the referenced functions exist in it, sokoban_move() certainly without any dubious construct (sokoban_is_level_cleared misses "void" in its parameter list, which is not entirely right), and seems like we are looking at the same checkout (current Uzebox Master).

How did you install this version of GCC? (for reference, might try to reproduce the setup in a virtual machine, though hoping the problem is found without that, aren't really keen on investing so much time on it if it is possible to be avoided)
uname -r retuns "5.4.52-1-MANJARO". I installed compiler version: avr-gcc is 10.1.0-1 (08/05/2020) from official community repository.

But if you want i can try install another compiler, called avr-gcc-atmel 4.9.2-1 from AUR repository ? Please let me know. Thanks.
zigfreid
Posts: 16
Joined: Sun Aug 16, 2020 5:54 am

Re: Error compiling code

Post by zigfreid »

Artcfox wrote: Sun Aug 16, 2020 1:23 pm Does making that function "static inline void" change anything, or removing the "inline" from it?
If i changed function to
static inline uint8_t sokoban_is_level_cleared() {
Then error related to function sokoban_is_level_cleared() is gone.

Similar fix is working also for sokoban_move function. So your Could you explain please the rootcause of my problem? Many thanks.
User avatar
Jubatian
Posts: 1564
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Error compiling code

Post by Jubatian »

zigfreid wrote: Sun Aug 16, 2020 7:14 pmSimilar fix is working also for sokoban_move function. So your Could you explain please the rootcause of my problem? Many thanks.
Did a bit of research as I don't use inline myself ("static" does the job, the compiler will sensibly inline it wherever possible).

What seems to be the case is that in Sokoban, the way it uses "inline", the compiler assumes that it is a separate definition to use when it deducts that the function can be inlined (this should normally be in the header of the module which contains the function's definition). If it deducts that it shouldn't inline, then it expects that the function exists as a normal, callable function (which normally would be in the source of the module whose header contained the inline definition).

So this case what is apparently happening that the compiler decides that it shouldn't inline those, and just compiles the game's source without the function's definition, assuming it comes from another source (another object file). Which is not the case, so the linker complains.

Solution: Probably all "inline"s have to be replaced to "static"s in the games and other sources (likely in most places it is used this way, incorrectly for the compiler).

EDIT: Committed fix. Seems like only MegaSokoban had this sort of problematic inlining.
zigfreid
Posts: 16
Joined: Sun Aug 16, 2020 5:54 am

Re: Error compiling code

Post by zigfreid »

Jubatian wrote: Sun Aug 16, 2020 10:40 pm
zigfreid wrote: Sun Aug 16, 2020 7:14 pmSimilar fix is working also for sokoban_move function. So your Could you explain please the rootcause of my problem? Many thanks.
Did a bit of research as I don't use inline myself ("static" does the job, the compiler will sensibly inline it wherever possible).

What seems to be the case is that in Sokoban, the way it uses "inline", the compiler assumes that it is a separate definition to use when it deducts that the function can be inlined (this should normally be in the header of the module which contains the function's definition). If it deducts that it shouldn't inline, then it expects that the function exists as a normal, callable function (which normally would be in the source of the module whose header contained the inline definition).

So this case what is apparently happening that the compiler decides that it shouldn't inline those, and just compiles the game's source without the function's definition, assuming it comes from another source (another object file). Which is not the case, so the linker complains.

Solution: Probably all "inline"s have to be replaced to "static"s in the games and other sources (likely in most places it is used this way, incorrectly for the compiler).

EDIT: Committed fix. Seems like only MegaSokoban had this sort of problematic inlining.
I can confirm that MegaSokoban compilation problem was solved, but i'm getting another error:
===================================
Building demo: demos/SpriteDemo/default
===================================
make -C demos/SpriteDemo/default UZEBIN_DIR=/home/vitaly/uzebox-master/bin/
avr-gcc -mmcu=atmega644 -Wl,-Map=SpriteDemo.map -Wl,-gc-sections uzeboxVideoEngineCore.o uzeboxCore.o uzeboxSoundEngine.o uzeboxSoundEngineCore.o uzeboxVideoEngine.o SpriteDemo.o -o SpriteDemo.elf
/usr/bin/avr-ld: uzeboxVideoEngine.o:/home/vitaly/uzebox-master/demos/SpriteDemo/default/../../../kernel/videoMode2/videoMode2.h:69: multiple definition of `sprites'; uzeboxVideoEngineCore.o:(.bss+0x4e0): first defined here
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:82: SpriteDemo.elf] Error 1
make: *** [Makefile:138: demos/SpriteDemo/default] Error 2
Maybe you have any idea ? Thanks again.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Error compiling code

Post by Artcfox »

Any better if you change to:

Code: Select all

extern struct SpriteStruct sprites[];
to:

Code: Select all

extern struct SpriteStruct* sprites;
in videoMode2.h?
zigfreid
Posts: 16
Joined: Sun Aug 16, 2020 5:54 am

Re: Error compiling code

Post by zigfreid »

Artcfox wrote: Mon Aug 17, 2020 2:18 pm Any better if you change to:

Code: Select all

extern struct SpriteStruct sprites[];
to:

Code: Select all

extern struct SpriteStruct* sprites;
in videoMode2.h?
After change above, i'm getting this error message:
===================================
Building demo: demos/SpriteDemo/default
===================================
make -C demos/SpriteDemo/default UZEBIN_DIR=/home/vitaly/uzebox-master/bin/
avr-gcc -I"../../../kernel" -mmcu=atmega644 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=28636360UL -Os -fsigned-char -ffunction-sections -fno-toplevel-reorder -MD -MP -MT uzeboxCore.o -MF dep/uzeboxCore.o.d -DVIDEO_MODE=2 -DINTRO_LOGO=2 -DMIXER_CHAN4_TYPE=1 -DSCREEN_SECTIONS_COUNT=9 -DINCLUDE_DEFAULT_WAVES=0 -DVRAM_TILES_V=39 -c ../../../kernel/uzeboxCore.c
avr-gcc -I"../../../kernel" -mmcu=atmega644 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=28636360UL -Os -fsigned-char -ffunction-sections -fno-toplevel-reorder -MD -MP -MT uzeboxSoundEngine.o -MF dep/uzeboxSoundEngine.o.d -DVIDEO_MODE=2 -DINTRO_LOGO=2 -DMIXER_CHAN4_TYPE=1 -DSCREEN_SECTIONS_COUNT=9 -DINCLUDE_DEFAULT_WAVES=0 -DVRAM_TILES_V=39 -c ../../../kernel/uzeboxSoundEngine.c
avr-gcc -I"../../../kernel" -mmcu=atmega644 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=28636360UL -Os -fsigned-char -ffunction-sections -fno-toplevel-reorder -MD -MP -MT uzeboxVideoEngine.o -MF dep/uzeboxVideoEngine.o.d -DVIDEO_MODE=2 -DINTRO_LOGO=2 -DMIXER_CHAN4_TYPE=1 -DSCREEN_SECTIONS_COUNT=9 -DINCLUDE_DEFAULT_WAVES=0 -DVRAM_TILES_V=39 -c ../../../kernel/uzeboxVideoEngine.c
In file included from ../../../kernel/uzeboxVideoEngine.c:30:
../../../kernel/videoMode2/videoMode2.c:41:22: error: conflicting types for 'sprites'
41 | struct SpriteStruct sprites[MAX_SPRITES];
| ^~~~~~~
In file included from ../../../kernel/uzebox.h:30,
from ../../../kernel/uzeboxVideoEngine.c:25:
../../../kernel/videoMode2/videoMode2.h:69:30: note: previous declaration of 'sprites' was here
69 | extern struct SpriteStruct* sprites;
| ^~~~~~~
make[1]: *** [Makefile:74: uzeboxVideoEngine.o] Error 1
make: *** [Makefile:138: demos/SpriteDemo/default] Error 2
User avatar
Jubatian
Posts: 1564
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Error compiling code

Post by Jubatian »

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).
Post Reply