English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 10 September 2021, 16:57   #1
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
Opening Custom screen crashes

I was trying this example code fro the Data Becker Supergrafik book. On the disk there is also the binary which wokrs, but it was compiled with Lattice C. When I try to compile it on bebbos gcc, then the binary crashes.


I assume that I missing some compile or linker option. I have used this gcc for my other project as well, but this is usally not using the OS in most cases and it works.


Seems that only ".c" is allowed as attachment but not ".cpp"



Commandline is this:

Code:
amiga-g++   -I/opt/amiga/utils/include -I/opt/amiga/m68k-amigaos/ndk13-include -I/opt/amiga/m68k-amigaos/ndk-include  -D AMIGA_OS --save-temps -fverbose-asm -Wall -pedantic -mcrt=nix13 -fno-exceptions -fno-rtti -std=c++11 -O2 -mregparm -fno-rtti -O3 -DNDEBUG   -o main.o -c main.cpp
amiga-g++  -D AMIGA_OS --save-temps -fverbose-asm -Wall -pedantic -mcrt=nix13 -fno-exceptions -fno-rtti -std=c++11 -O2 -mregparm -fno-rtti -O3 -DNDEBUG  -Wl,--enable-auto-import main.cpp.o  -o ../bin/CustomScreen.exe -Wl,--out-implib,../bin/libCustomScreen.dll.a -Wl,--major-image-version,0,--minor-image-version,0  -L/opt/amiga/utils/lib -lAmigaUtils -lAmigaGCCUtils
Attached Files
File Type: c main.c (5.6 KB, 96 views)

Last edited by sparhawk; 10 September 2021 at 17:21.
sparhawk is offline  
Old 10 September 2021, 18:57   #2
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,098
Remove (or comment out) the line that includes <utils/dos/dos.h>, and try to compile with just
Code:
amiga-g++ main.cpp -o main.exe -mcrt=nix13
. That works for me with "m68k-amigaos-g++ (GCC) 6.5.0b 210726154642".

If that also works for you, then try adding back in some of your other compiler/linker flags
paraj is offline  
Old 10 September 2021, 20:50   #3
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
Thanks for trying it, so at least I know now that the source is working, as I assumed. Have to hunt it down where it goes wrong now...
sparhawk is offline  
Old 10 September 2021, 21:26   #4
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,160
do you have a 68000? because it doesn't work on 68000 (startup code has word read at odd addresses)
jotd is offline  
Old 10 September 2021, 21:59   #5
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,098
Quote:
Originally Posted by jotd View Post
do you have a 68000? because it doesn't work on 68000 (startup code has word read at odd addresses)

Are you compiling with all of OPs compiler/linker options? Doing only what I wrote in my reply I get the attached binary, which works fine w/ UAE A500 quickstart.


Adding " -fverbose-asm -Wall -pedantic -mcrt=nix13 -fno-exceptions -fno-rtti -std=c++11 -fno-rtti -O3 -DNDEBUG -s --save-temps" also seems fine, "-mregparm" however does not.
Attached Files
File Type: 68k main.68k (19.0 KB, 58 views)
paraj is offline  
Old 10 September 2021, 23:23   #6
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by sparhawk View Post
Seems that only ".c" is allowed as attachment but not ".cpp"
This is a C source. I don't see any C++ in it.

Quote:
Commandline is this:
Code:
  amiga-g++   -I/opt/amiga/utils/include -I/opt/amiga/m68k-amigaos/ndk13-include -I/opt/amiga/m68k-amigaos/ndk-include  -D AMIGA_OS --save-temps -fverbose-asm -Wall -pedantic -mcrt=nix13 -fno-exceptions -fno-rtti -std=c++11 -O2 -mregparm -fno-rtti -O3 -DNDEBUG   -o main.o -c main.cpp
Why "g++"? It is plain C. Use a C compiler. No special options should be necessary. Just link with -lamiga for the stub functions (source doesn't use inlines via <proto/...>).
Really the only problem is the <utils/dos/dos.h>, which paraj already mentioned. It doesn't exist, but isn't required either.
phx is offline  
Old 11 September 2021, 15:46   #7
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
Quote:
Originally Posted by paraj View Post
Adding " -fverbose-asm -Wall -pedantic -mcrt=nix13 -fno-exceptions -fno-rtti -std=c++11 -fno-rtti -O3 -DNDEBUG -s --save-temps" also seems fine, "-mregparm" however does not.

Yeah, it looks like regparm is the problem, though I fail to see why. When calling OS routines, they use regparams anyway.
sparhawk is offline  
Old 11 September 2021, 15:48   #8
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
Quote:
Originally Posted by phx View Post
This is a C source. I don't see any C++ in it.

Yeah, because it didn't work with my original project and so I tested some older C code to see if there is a problem with my code or something else.


Anyway, it shouldn't matter if I use g++ or gcc because both should work with this simple code, right?
sparhawk is offline  
Old 11 September 2021, 18:01   #9
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Quote:
Originally Posted by sparhawk View Post
Anyway, it shouldn't matter if I use g++ or gcc because both should work with this simple code, right?
It could make a difference. C is not a full subset of C++, there are some differences, so just use gcc instead.

Edit: Took a quick look at the code, and it's definitely not simple enough to be guaranteed to not make a difference.
Thorham is offline  
Old 11 September 2021, 20:07   #10
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
Quote:
Originally Posted by Thorham View Post
It could make a difference. C is not a full subset of C++, there are some differences, so just use gcc instead.

That's strange, because most of my code is ASM and some stuff I do with g++, without OS, and I never had any issues. But that 'regparm' can explain it, as I had problems with that before when forgot to keep that in mind.
sparhawk is offline  
Old 11 September 2021, 23:16   #11
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by sparhawk View Post
I was trying this example code fro the Data Becker Supergrafik book. On the disk there is also the binary which wokrs, but it was compiled with Lattice C. When I try to compile it on bebbos gcc, then the binary crashes.


I assume that I missing some compile or linker option. I have used this gcc for my other project as well, but this is usally not using the OS in most cases and it works.


Seems that only ".c" is allowed as attachment but not ".cpp"



Commandline is this:

Code:
amiga-g++   -I/opt/amiga/utils/include -I/opt/amiga/m68k-amigaos/ndk13-include -I/opt/amiga/m68k-amigaos/ndk-include  -D AMIGA_OS --save-temps -fverbose-asm -Wall -pedantic -mcrt=nix13 -fno-exceptions -fno-rtti -std=c++11 -O2 -mregparm -fno-rtti -O3 -DNDEBUG   -o main.o -c main.cpp
amiga-g++  -D AMIGA_OS --save-temps -fverbose-asm -Wall -pedantic -mcrt=nix13 -fno-exceptions -fno-rtti -std=c++11 -O2 -mregparm -fno-rtti -O3 -DNDEBUG  -Wl,--enable-auto-import main.cpp.o  -o ../bin/CustomScreen.exe -Wl,--out-implib,../bin/libCustomScreen.dll.a -Wl,--major-image-version,0,--minor-image-version,0  -L/opt/amiga/utils/lib -lAmigaUtils -lAmigaGCCUtils



duh - that's a complicated command line...


I'd fix includes

Code:
//#include <utils/dos/dos.h>
also remove duplicate includes... and use exit(0); instead of Exit(0); -- include <stdlib.h> for no warnings.
and then
Code:
m68k-amigaos-gcc -Os main.c -mcrt=nix13 -o sparhawk
and the program is working.


Ah - you want to use -mregparm too: many clib header do not supply the needed __stdargs, also main needs that!
So use the proto includes instead:
Code:
//#include <clib/dos_protos.h>
//#include <exec/types.h>
//#include <exec/memory.h>
//#include <intuition/intuition.h>
//#include <intuition/screens.h>

//#include <clib/exec_protos.h>
//#include <clib/graphics_protos.h>
//#include <clib/intuition_protos.h> 

#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>

#include <stdio.h>
#include <stdlib.h>

//#include <utils/dos/dos.h>
and use
Code:
m68k-amigaos-gcc -Os main.c -mcrt=nix13 -o sparhawk -mregparm
and it's running fine again - plus it's a tad smaller, not profiting from -mregparm since your program only provides functions without params^^


and be nice to yourself and use volatile (and don't forget __stdargs at main)

Code:
volatile char *LeftMouse = (char *)0xbfe001;

void Color(void);
void Color_Cycle(void);

__stdargs int main(int argc, char *argv[])

there you go

Last edited by bebbo; 26 October 2023 at 13:18.
bebbo is offline  
Old 12 September 2021, 14:25   #12
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
Quote:
Originally Posted by bebbo View Post
duh - that's a complicated command line...

Yeah. Part of it is generated by cmake...


Quote:
there you go

Thanks!
sparhawk is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Does anyone know why CygnusEd 5.6 crashes source support.Apps 4 04 November 2017 03:38
3.5.0 crashes on me NLS support.WinUAE 7 22 June 2017 15:50
Asm-One crashes in 3.1.0 b00mer support.WinUAE 4 10 November 2015 09:11
Two WinUAE crashes thor support.WinUAE 5 06 November 2007 20:15
3D code and/or internet code for Blitz Basic 2.1 EdzUp Retrogaming General Discussion 0 10 February 2002 11:40

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:00.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.30501 seconds with 16 queries