Trying to get started && C++ compilation problems...

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
MegaDriver
Newbie
Posts: 1
Joined: Sun Feb 28, 2016 7:07 pm

Trying to get started && C++ compilation problems...

Post by MegaDriver » Sun Feb 28, 2016 7:56 pm

OS: debian x86_64

Hello, I'm starting to get a bit frustrated just trying to get going with a mega drive game in c++ (rather than c or asm and don't tell me it won't fit, I'll make it fit whether I have to forget the standard library or not and at least just have c++ objects be supported)

First tried gendev after waiting for it to build it did work to compile c examples, but I couldn't figure out how to mess with the makefiles to get it to actually build me the missing m68k-elf-g++. No matter what I tried, it would never produce the g++ executable only gcc hence it would complain that m68k-elf-g++ was missing. Messed around uncommenting the g++: directive, locating the 4.8.2-g++.tar.gz since the archive it was trying to download it from it wasn't any longer available, got confused whether it was even necessary since in these other instructions it wasn't and most gcc cross compiler downloads don't include it anyway (as I feel like it's built into gcc with the right configure line, which I couldn't get gendev to insert, or didn't know couldn't figure out the proper place at least).

Then I said screw it, deleted gendev and /opt/toolchains/gen, then I followed these instructions to make the toolchain more manually: viewtopic.php?f=7&t=889&hilit=MD_32X_Examples.7z

Now after following those steps, building it, I have the toolchain now at /opt/toolchains/sega instead with the permissions set for my user. I edited ~/.gendev and ~/.32xdev (from gendev / only thing I kept from it) so it points to the /sega path rather than /gen...

Now I do ". ~/.gendev" or the 32x one when I want to compile for megadrive / 32x respectively.

Upon trying to compile the TicTacToe example provided though, everything seems to be good (just warnings, which I read on here are normal) until it gets to:

Code: Select all

crt0.o: In function `skip_tmss':
(.text+0x260): undefined reference to `_sdata'
crt0.o: In function `skip_tmss':
(.text+0x254): undefined reference to `_stext'
collect2: error: ld returned 1 exit status
Full output:

Code: Select all

m68k-elf-as -m68000 --register-prefix-optional crt0.s -o crt0.o
m68k-elf-gcc  -m68000 -Wall -O2 -c -fomit-frame-pointer  -c crtstuff.c -o crtstuff.o
m68k-elf-g++  -m68000 -Wall -O2 -c -fno-exceptions -nostartfiles -ffreestanding -fno-rtti  -c main.cpp -o main.o
m68k-elf-as -m68000 --register-prefix-optional hw_md.s -o hw_md.o
m68k-elf-gcc  -m68000 -Wall -O2 -c -fomit-frame-pointer  -c font.c -o font.o
m68k-elf-g++ -T /opt/toolchains/sega/ldscripts/md.ld -Wl,-Map=output.map -nostdlib -ffreestanding -fno-rtti crt0.o crtstuff.o main.o hw_md.o font.o -L/opt/toolchains/sega/m68k-elf/lib -L/opt/toolchains/sega/m68k-elf/m68k-elf/lib -lstdc++ -lc -lgcc -lnosys -o TicTacToe.elf
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libc.a(lib_a-closer.o): In function `_close_r':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-newlib-m68k-elf-1.19.0/m68k-elf/newlib/libc/reent/../../../../../newlib-1.19.0/newlib/libc/reent/closer.c:53: warning: _close is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libc.a(lib_a-fstatr.o): In function `_fstat_r':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-newlib-m68k-elf-1.19.0/m68k-elf/newlib/libc/reent/../../../../../newlib-1.19.0/newlib/libc/reent/fstatr.c:62: warning: _fstat is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libc.a(lib_a-signalr.o): In function `_getpid_r':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-newlib-m68k-elf-1.19.0/m68k-elf/newlib/libc/reent/../../../../../newlib-1.19.0/newlib/libc/reent/signalr.c:96: warning: _getpid is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libc.a(lib_a-isattyr.o): In function `_isatty_r':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-newlib-m68k-elf-1.19.0/m68k-elf/newlib/libc/reent/../../../../../newlib-1.19.0/newlib/libc/reent/isattyr.c:58: warning: _isatty is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libc.a(lib_a-signalr.o): In function `_kill_r':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-newlib-m68k-elf-1.19.0/m68k-elf/newlib/libc/reent/../../../../../newlib-1.19.0/newlib/libc/reent/signalr.c:61: warning: _kill is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libstdc++.a(basic_file.o): In function `std::__basic_file<char>::seekoff(long long, std::_Ios_Seekdir)':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-gcc-m68k-elf-4.8.2/m68k-elf/libstdc++-v3/src/c++98/basic_file.cc:327: warning: _lseek is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libc.a(lib_a-openr.o): In function `_open_r':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-newlib-m68k-elf-1.19.0/m68k-elf/newlib/libc/reent/../../../../../newlib-1.19.0/newlib/libc/reent/openr.c:59: warning: _open is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libstdc++.a(basic_file.o): In function `std::__basic_file<char>::xsgetn(char*, long)':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-gcc-m68k-elf-4.8.2/m68k-elf/libstdc++-v3/src/c++98/basic_file.cc:289: warning: _read is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libstdc++.a(pure.o): In function `__cxa_pure_virtual':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-gcc-m68k-elf-4.8.2/m68k-elf/libstdc++-v3/libsupc++/../../../../gcc-4.8.2/libstdc++-v3/libsupc++/pure.cc:49: warning: _write is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/lib/gcc/m68k-elf/4.8.2/../../../../m68k-elf/bin/ld: section .gcc_except_table._ZNSt8ios_base4InitC2Ev loaded at [0000000000000000,000000000000005b] overlaps section .text loaded at [0000000000000000,00000000000787bf]
/opt/toolchains/sega/m68k-elf/lib/gcc/m68k-elf/4.8.2/../../../../m68k-elf/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000000000
crt0.o: In function `skip_tmss':
(.text+0x260): undefined reference to `_sdata'
crt0.o: In function `skip_tmss':
(.text+0x254): undefined reference to `_stext'
collect2: error: ld returned 1 exit status
Makefile:28: recipe for target 'TicTacToe.elf' failed
make: *** [TicTacToe.elf] Error 1
Tried searching the forums and web for my exact problem and can't find anyone with it (though similar).

After reading the instructions again to see if I did anything wrong, I more closely examined this line: "The linker scripts in the archive are older than the ones in step 5, so don't replace them!"

I hadn't replaced the ldscripts from the MD_32X_Examples.7z archive, but I went and did that just for the hell of it! (The C version of the megadrive tic tac toe example also didn't compile by the way) Now I can actually compile the C++ version of the tic tac toe example, but it doesn't work in the emulator I tried so far. The C version that also compiles now, does work on the other hand.

After messing around, I replaced all the older ldscripts with the newer ones except md.ld... md.ld seems to be where the issue lies. When I used the new md.ld and tried to edit it, so that _sdata and _stext are actually written in the file, like the older md.ld (by simply doing it like how it was in the older version of md.ld for the newer version):

At the end of the data section:

Code: Select all

__data_size = __data_end - __data_start;
  _sdata = __data_size;
 
at the end of the text section:

Code: Select all

__text_size = __text_end - __text_start;
  _stext = __text_size;
 
or with _sdata = SIZEOF (.data) and _stext = SIZEOF(.text)

It doesn't seem to matter, now it doesn't complain about _sdata and _stext in function "skip_tmss", but it still won't successfully compile AND actually work!

So what can I do from here? How can I get the new md.ld to work with the example tictactoe c++ project, or the old md.ld to actually produce a working binary?

Did Chilly Willy not fully think it through that the example project wouldn't be able to compile with his instructions, or have I just messed up somewhere?

Maybe instead of editing the md.ld I need to fix the crt0.s so it doesn't look for _sdata and _stext under skip_tmss! Where's the newer matching crt0.s for the newer md.ld?

Thanks for your help.

Output with latest attempt:

Code: Select all

Mega@debianpc:~/GameDev/megadrive/TicTacToe/C++/MD$ make
m68k-elf-as -m68000 --register-prefix-optional crt0.s -o crt0.o
m68k-elf-gcc  -m68000 -Wall -O2 -c -fomit-frame-pointer  -c crtstuff.c -o crtstuff.o
m68k-elf-g++  -m68000 -Wall -O2 -c -fno-exceptions -nostartfiles -ffreestanding -fno-rtti  -c main.cpp -o main.o
m68k-elf-as -m68000 --register-prefix-optional hw_md.s -o hw_md.o
m68k-elf-gcc  -m68000 -Wall -O2 -c -fomit-frame-pointer  -c font.c -o font.o
m68k-elf-g++ -T /opt/toolchains/sega/ldscripts/md.ld -Wl,-Map=output.map -nostdlib -ffreestanding -fno-rtti crt0.o crtstuff.o main.o hw_md.o font.o -L/opt/toolchains/sega/m68k-elf/lib -L/opt/toolchains/sega/m68k-elf/m68k-elf/lib -lstdc++ -lc -lgcc -lnosys -o TicTacToe.elf
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libc.a(lib_a-closer.o): In function `_close_r':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-newlib-m68k-elf-1.19.0/m68k-elf/newlib/libc/reent/../../../../../newlib-1.19.0/newlib/libc/reent/closer.c:53: warning: _close is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libc.a(lib_a-fstatr.o): In function `_fstat_r':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-newlib-m68k-elf-1.19.0/m68k-elf/newlib/libc/reent/../../../../../newlib-1.19.0/newlib/libc/reent/fstatr.c:62: warning: _fstat is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libc.a(lib_a-signalr.o): In function `_getpid_r':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-newlib-m68k-elf-1.19.0/m68k-elf/newlib/libc/reent/../../../../../newlib-1.19.0/newlib/libc/reent/signalr.c:96: warning: _getpid is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libc.a(lib_a-isattyr.o): In function `_isatty_r':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-newlib-m68k-elf-1.19.0/m68k-elf/newlib/libc/reent/../../../../../newlib-1.19.0/newlib/libc/reent/isattyr.c:58: warning: _isatty is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libc.a(lib_a-signalr.o): In function `_kill_r':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-newlib-m68k-elf-1.19.0/m68k-elf/newlib/libc/reent/../../../../../newlib-1.19.0/newlib/libc/reent/signalr.c:61: warning: _kill is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libstdc++.a(basic_file.o): In function `std::__basic_file<char>::seekoff(long long, std::_Ios_Seekdir)':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-gcc-m68k-elf-4.8.2/m68k-elf/libstdc++-v3/src/c++98/basic_file.cc:327: warning: _lseek is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libc.a(lib_a-openr.o): In function `_open_r':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-newlib-m68k-elf-1.19.0/m68k-elf/newlib/libc/reent/../../../../../newlib-1.19.0/newlib/libc/reent/openr.c:59: warning: _open is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libstdc++.a(basic_file.o): In function `std::__basic_file<char>::xsgetn(char*, long)':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-gcc-m68k-elf-4.8.2/m68k-elf/libstdc++-v3/src/c++98/basic_file.cc:289: warning: _read is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/m68k-elf/lib/libstdc++.a(pure.o): In function `__cxa_pure_virtual':
/home/Mega/GameDev/megadrive/sega/build-toolchain/build-gcc-m68k-elf-4.8.2/m68k-elf/libstdc++-v3/libsupc++/../../../../gcc-4.8.2/libstdc++-v3/libsupc++/pure.cc:49: warning: _write is not implemented and will always fail
/opt/toolchains/sega/m68k-elf/lib/gcc/m68k-elf/4.8.2/../../../../m68k-elf/bin/ld: section .gcc_except_table._ZNSt8ios_base4InitC2Ev loaded at [0000000000000000,000000000000005b] overlaps section .text loaded at [0000000000000000,00000000000787bf]
/opt/toolchains/sega/m68k-elf/lib/gcc/m68k-elf/4.8.2/../../../../m68k-elf/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000000000
collect2: error: ld returned 1 exit status
Makefile:28: recipe for target 'TicTacToe.elf' failed
make: *** [TicTacToe.elf] Error 1

Post Reply