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)/$< |
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().
|
C++ is supported since Version 0.8.0.
A workaround to avoid the new keyword might do the job too. |
If exception handling is the culprit, try adding std::noexcept to the new allocations and check for null allocations in your code.
|
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? |
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. |
Quote:
Code:
void *malloc(size_t size) { |
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)); } |
If p is a void pointer, what is sizeof(p)?
|
4 - which is definitely wrong here
|
Just use AllocVec and FreeVec instead as they track the allocation size
|
Quote:
|
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. |
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.
|
Quote:
Code:
#include "support/gcc8_c_support.h" |
I do have issues with virtual methods. It fails again at linking stage. Trying bebbos solution with eclipse. Do prefer the vscode experience though.
|
Adding the flag "-shared-libgcc" did the trick. Now virtual methods work.
|
Quote:
Please let us know how you get on. While I hate C++, I'm getting tired of what I have to go through without it. |
Quote:
Do people here not use CreatePool(), AllocPooled() and DeletePool? Sent from my iPhone using Tapatalk |
Quote:
|
All times are GMT +2. The time now is 16:25. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.