03 January 2021, 11:21 | #1 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
stdlib amiga gcc
Maybe Some c/c++ gurus can help.
I'm trying to port some C++ code to Amiga. I'm using abyss visual studio code plugin for development. For some basic c++ functions like the new operator stdlib is required. On linking stage I get errors like this: .../ld.exe: cannot find crtbegin.o: No such file or directory .../ld.exe: cannot find -lgcc .../ld.exe: cannot find -lc This is my Makefile. It's the default Makefile from abyss. I just removed the flag -nostdlib. # to generate assembler sources: -Wa,-ahl=$@.s forward-to-backward = $(subst /,\,$1) subdirs := $(wildcard */) VPATH = $(subdirs) cpp_sources := $(wildcard *.cpp)$(wildcard $(addsuffix *.cpp,$(subdirs))) cpp_objects := $(addprefix obj/,$(patsubst %.cpp,%.o,$(notdir $(cpp_sources)))) c_sources := $(wildcard *.c)$(wildcard $(addsuffix *.c,$(subdirs))) c_objects := $(addprefix obj/,$(patsubst %.c,%.o,$(notdir $(c_sources)))) objects := $(cpp_objects)$(c_objects) # https://stackoverflow.com/questions/...kefile/4038459 # http://www.microhowto.info/howto/aut...endencies.html OUT = a.mingw CC = m68k-amiga-elf-gcc CCFLAGS = -g -MP -MMD -m68000 -Ofast -std=gnu++11 -Wall -Wno-unused-function -Wno-volatile-register-var -fomit-frame-pointer -fno-tree-loop-distribution -flto -fwhole-program -fno-exceptions ASFLAGS = -Wa,-g LDFLAGS = -Wl,--emit-relocs,-Ttext=0,-Map=$(OUT).map all: $(OUT).exe $(OUT).exe: $(OUT).elf $(info Elf2Hunk $(OUT).exe) @elf2hunk $(OUT).elf $(OUT).exe $(OUT).elf: $(objects) obj/gcc8_a_support.o $(info Linking a.mingw.elf) @$(CC)$(CCFLAGS)$(LDFLAGS)$(objects) obj/gcc8_a_support.o -o $@ @m68k-amiga-elf-objdump --disassemble -S $@ >$(OUT).s obj/gcc8_a_support.o: support/gcc8_a_support.s $(info Assembling $<) @$(CC)$(CCFLAGS)$(ASFLAGS) -xassembler-with-cpp -c -o $@$(CURDIR)/$< clean: $(info Cleaning...) @del /q obj $(OUT).* 2>nul || rmdir obj 2>nul || ver>nul -include$(objects:.o=.d) $(cpp_objects) : obj/%.o : %.cpp @if not exist "$(call forward-to-backward,$(dir$@))" mkdir $(call forward-to-backward,$(dir$@)) $(info Compiling $<) @$(CC)$(CCFLAGS) -c -o $@$(CURDIR)/$< $(c_objects) : obj/%.o : %.c @if not exist "$(call forward-to-backward,$(dir$@))" mkdir $(call forward-to-backward,$(dir$@)) $(info Compiling $<) @$(CC)$(CCFLAGS) -c -o $@$(CURDIR)/$< |
03 January 2021, 11:29 | #2 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,197
|
I don't think Bartman's GCC10 installation even supports the C++ stdlib option. It's for writing hardware-banging demo code. If you need to allocate memory, use AllocVec().
|
03 January 2021, 11:35 | #3 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
C++ is supported since Version 0.8.0.
A workaround to avoid the new keyword might do the job too. |
03 January 2021, 11:39 | #4 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,197
|
If exception handling is the culprit, try adding std::noexcept to the new allocations and check for null allocations in your code.
Last edited by Samurai_Crow; 03 January 2021 at 11:46. |
03 January 2021, 11:40 | #5 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
What Samurai_Crow said, there is no stdlib, so you'll not be able to port most things.
But what kind of code is this, and how far can you get if you leave the -nostdlib flag in? |
03 January 2021, 12:13 | #6 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
I can define classes and access them. As soon as I use the new operator I get linker errors (undefined symbol). Turns out the new operator uses malloc which in turn requires stdlib. Maybe I could simulate the behavior of new like this.
1) Use memory allocation function for Amiga OS 2) Call constructor manually Not sure how to know how much memory to allocate though. It‘s the Wintermute Adventure engine I‘m trying to port. My goal is not to be fully compatible with recent games, but to have a decent engine on the Amiga for new games. So it’s going to be a minimal port. |
03 January 2021, 12:24 | #7 | |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Quote:
Code:
void *malloc(size_t size) { return AllocVec(size, NULL); } |
|
03 January 2021, 19:23 | #8 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
Thank Ernst. This definitely pointed me in the right Direction. It's possible to implement new operators for new and delete. This did the trick.
void * operator new(size_t size) { KPrintF("Operator new Called"); void *p = AllocMem( size, MEMF_ANY); return p; } void operator delete(void * p) { KPrintF("Operator delete Called"); FreeMem( p, sizeof(p)); } |
04 January 2021, 01:09 | #9 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,197
|
If p is a void pointer, what is sizeof(p)?
|
04 January 2021, 03:39 | #10 |
Registered User
Join Date: Jul 2017
Location: San Jose
Posts: 676
|
4 - which is definitely wrong here
|
04 January 2021, 04:15 | #11 |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
Just use AllocVec and FreeVec instead as they track the allocation size
|
04 January 2021, 04:24 | #12 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,197
|
|
04 January 2021, 09:54 | #13 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
I've just had a go at compiling a simple test class, and it looks like there's more stuff missing, I get "undefined reference to `_Znwm'" and "undefined reference to `_ZdlPvm'", and I'm not even doing anything yet.
If you're working with a bunch of existing code and need full C++ support, maybe Bebbo's gcc build is a better option. |
04 January 2021, 10:17 | #14 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
Thanjs for pointing out the Problem with Sizeof. Will switch to AllocVec and FreeVec. Up till now my Classes work fine with this solution. Can I have a look at yours Ernst.
|
04 January 2021, 10:27 | #15 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Here's my main.cpp:
Code:
#include "support/gcc8_c_support.h" #include <exec/execbase.h> struct ExecBase * SysBase; class TestClass { public: TestClass(int a); ~TestClass(); void Test(); private: int a; }; TestClass::TestClass(int aa) { KPrintF("In TestClass::TestClass(int)"); a = aa; } TestClass::~TestClass() { KPrintF("In TestClass::~TestClass()"); } void TestClass::Test() { KPrintF("In TestClass::Test, a = %ld", a); } int main() { SysBase = *((struct ExecBase * *) 4UL); KPrintF("In main()"); TestClass test1 = TestClass(1); test1.Test(); TestClass * test2 = new TestClass(2); test2->Test(); delete test2; } |
08 January 2021, 15:29 | #16 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
I do have issues with virtual methods. It fails again at linking stage. Trying bebbos solution with eclipse. Do prefer the vscode experience though.
|
10 January 2021, 16:01 | #17 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
Adding the flag "-shared-libgcc" did the trick. Now virtual methods work.
|
10 January 2021, 16:09 | #18 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
|
12 March 2021, 18:35 | #19 |
Registered User
Join Date: Mar 2020
Location: Boulder Creek / USA
Posts: 43
|
|
12 March 2021, 19:03 | #20 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
amiga-gcc minimal output | Fook42 | Coders. C/C++ | 17 | 02 May 2019 09:49 |
Amiga GCC 6.2 developer guide appreciated | asymetrix | Coders. C/C++ | 19 | 11 October 2018 23:58 |
Req: gcc crosscompiler with amiga hunk support | emufan | Coders. C/C++ | 5 | 02 October 2017 01:51 |
Amiga GCC Where to find it? | _ThEcRoW | request.Apps | 10 | 02 March 2006 00:44 |
Amiga GCC Where can i find? | _ThEcRoW | request.Apps | 1 | 22 October 2005 18:17 |
|
|