English Amiga Board


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

 
 
Thread Tools
Old 24 August 2018, 10:11   #921
Marlon_
Amiga Programmer

Marlon_'s Avatar
 
Join Date: Mar 2016
Location: Sundsvall, Sweden
Age: 29
Posts: 483
I still do most of my C/C++ coding in the terminal to this date. I'm considering getting Visual Studio Code set up for this as it's available for Windows, Mac and Linux.
Marlon_ is offline  
Old 24 August 2018, 11:12   #922
Marlon_
Amiga Programmer

Marlon_'s Avatar
 
Join Date: Mar 2016
Location: Sundsvall, Sweden
Age: 29
Posts: 483
Quote:
Originally Posted by NovaCoder View Post
Nope, I'll try that now.



Thanks



Update: Seems happier now, still building...







OK that worked, now trying to use eclipse CDT, anyone have any tips?



Thanks


You are welcome to join us in our amigadev slack! https://join.slack.com/t/amigaports/...DA1OWQwNGY4MWQ
Marlon_ is offline  
Old 29 August 2018, 07:52   #923
NovaCoder
Registered User
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 3,474
Been playing around with this recently (using eclipse CDT) and come across my first problem.


I'm just trying to create a txt file and although it compiles and links OK it doesn't seem to work?

This is the code:

Code:
printf("creating log file\n");
    	debugLogFile = fopen("DEBUG.TXT", "w");
        if (debugLogFile) {
        	printf("created log file\n");
        } else {
        perror( "Error opening file" );
        printf( "Error code opening file: %d\n", errno );
        printf( "Error opening file: %s\n", strerror( errno ) );
  }
It always returns NULL and does not create 'DEBUG.TXT'

Output:

Code:
Error opening file
Error opening file: Success
Error code opening file: 0

Anyone know what I've stuffed up

I'm not linking with any extra libs or anything just using compiler options: -m68040 -noixemul -O3 -Wall -c -fmessage-length=0

Last edited by NovaCoder; 29 August 2018 at 08:28.
NovaCoder is offline  
Old 29 August 2018, 13:51   #924
Marlon_
Amiga Programmer

Marlon_'s Avatar
 
Join Date: Mar 2016
Location: Sundsvall, Sweden
Age: 29
Posts: 483
Quote:
Originally Posted by NovaCoder View Post
Been playing around with this recently (using eclipse CDT) and come across my first problem.


I'm just trying to create a txt file and although it compiles and links OK it doesn't seem to work?

This is the code:

Code:
printf("creating log file\n");
    debugLogFile = fopen("DEBUG.TXT", "w");
        if (debugLogFile) {
        printf("created log file\n");
        } else {
        perror( "Error opening file" );
        printf( "Error code opening file: %d\n", errno );
        printf( "Error opening file: %s\n", strerror( errno ) );
  }
It always returns NULL and does not create 'DEBUG.TXT'

Output:

Code:
Error opening file
Error opening file: Success
Error code opening file: 0

Anyone know what I've stuffed up

I'm not linking with any extra libs or anything just using compiler options: -m68040 -noixemul -O3 -Wall -c -fmessage-length=0

I believe it’s the file access flag that is the culprit. Can’t remember which option was valid
Marlon_ is offline  
Old 29 August 2018, 16:57   #925
lantus360
Registered User
 
Join Date: Feb 2013
Location: Olathe, Kansas
Posts: 193
Quote:
Originally Posted by lantus360 View Post
this code

Code:
#include <stdio.h>

int main()
{
	FILE *f = fopen("test.c","rt");
	
	if (f)
	{
		printf("File opened!\n");
		fclose(f);
	}
	else
	{
		printf("File not opened\n");
	}
opens my file OK with

m68k-amigaos-gcc -o test test.c 


but does not with

m68k-amigaos-gcc -o test test.c -noixemul


why?

edit: fails with -mcrt=nix13 but works with -mcrt=clib2
Novacoder - this might be related to your problem. Try linking with clib2
lantus360 is offline  
Old 29 August 2018, 17:11   #926
Marlon_
Amiga Programmer

Marlon_'s Avatar
 
Join Date: Mar 2016
Location: Sundsvall, Sweden
Age: 29
Posts: 483
Ah, fopen might be broken in libnix.
Marlon_ is offline  
Old 30 August 2018, 00:20   #927
NovaCoder
Registered User
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 3,474
Thanks guys, will try linking with clib2


Update:

OK that threw up a linking error with strlcpy....do I need to change some other compiler settings?

Code:
Invoking: Cross GCC Linker
m68k-amigaos-gcc -s -mcrt=clib2 -o "HelloWorld_m68k"  ./src/HelloWorld_m68k.o  /home/novacoder/Development/tools/eclipse/df/SDL/Debug/libSDL.a 
/home/novacoder/Development/Amiga/tools/lib/gcc/m68k-amigaos/6.4.1b/../../../../m68k-amigaos/bin/ld: /home/novacoder/Development/Amiga/tools/m68k-amigaos/clib2/lib/libm.a(math_init_exit.o):math_init_exit.o:(.text+0x15a): undefined reference to `strlcpy'
Update:

I managed to get it working without clib2 by using native Amiga DOS commands

Last edited by NovaCoder; 30 August 2018 at 03:54.
NovaCoder is offline  
Old 26 September 2018, 19:44   #928
bebbo
Registered User

 
Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 307
Quote:
Code:
FILE *f = fopen("test.c","rt");
There is no "rt" mode according to http://www.cplusplus.com/reference/cstdio/fopen/ or http://man7.org/linux/man-pages/man3/fopen.3.html ...
bebbo is offline  
Old 01 October 2018, 02:34   #929
NovaCoder
Registered User
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 3,474
Anyone know how to link in the library for the functions defined in unistd.h?

For example rmdir, stat, fstat

Are they missing from libnix?

This is building with noixemul and C++ BTW



Another unrelated problem I've noticed is that the following code doesn't work as expected:

PHP Code:
int main(int argcchar *argv[])
{
    
struct DiskObject *diskObject;
    
char *toolType;
    
struct WBStartupwbStartup;

    if (
argc != 0) {
        
// Started from the shell.
        
return 1;
    }

    
// Started from WorkBench
    
wbStartup = (struct WBStartup*)argv;



So when you start this from the shell it works as expected but it doesn't automatically populate the WBStartup structure when you start it from WorkBench (in fact it doesn't seem to even execute?)




Thanks

Last edited by NovaCoder; 01 October 2018 at 03:54.
NovaCoder is offline  
Old 01 October 2018, 09:44   #930
bebbo
Registered User

 
Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 307
Quote:
Originally Posted by NovaCoder View Post
Anyone know how to link in the library for the functions defined in unistd.h?

For example rmdir, stat, fstat

Are they missing from libnix?


This is building with noixemul and C++ BTW
I've no idea what version you are refering to. The libnix libraries do provide these functions.

Quote:
Originally Posted by NovaCoder View Post
Another unrelated problem I've noticed is that the following code doesn't work as expected:

PHP Code:
int main(int argcchar *argv[]){
    
struct DiskObject *diskObject;
    
char *toolType;
    
struct WBStartupwbStartup;
    if (
argc != 0) {
        
// Started from the shell.
        
return 1;
    }
    
// Started from WorkBench
    
wbStartup = (struct WBStartup*)argv;

So when you start this from the shell it works as expected but it doesn't automatically populate the WBStartup structure when you start it from WorkBench (in fact it doesn't seem to even execute?)


Thanks
Uhm, casting argv to wbStartup is not correct. Try this instead:
Code:
#include <unistd.h>
#include <sys/stat.h>

// defining a variable or function with this name prohibits linking of code
// parsing the command line into argv.
int __nocommandline;

// the startup message from workbench or 0 if started via cli
extern struct WBStartup *_WBenchMsg;

int main(int argc, char ** argv) {

// just a test of some functions.
  struct stat sbuf;
  mkdir("blubb", 0); // mode does not care on Amiga
  stat("blubb", &sbuf);
  rmdir("blubb");

  if (!_WBenchMsg) return 1;

  // started via workbench.

  return 0;
}
And compile it using
Code:
m68k-amigaos-gcc bla.c -Os -o bla -noixemul
bebbo is offline  
Old 01 October 2018, 13:00   #931
NovaCoder
Registered User
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 3,474
Quote:
Originally Posted by bebbo View Post
I've no idea what version you are refering to. The libnix libraries do provide these functions.



Uhm, casting argv to wbStartup is not correct. Try this instead:
Code:
#include <unistd.h>
#include <sys/stat.h>

// defining a variable or function with this name prohibits linking of code
// parsing the command line into argv.
int __nocommandline;

// the startup message from workbench or 0 if started via cli
extern struct WBStartup *_WBenchMsg;

int main(int argc, char ** argv) {

// just a test of some functions.
  struct stat sbuf;
  mkdir("blubb", 0); // mode does not care on Amiga
  stat("blubb", &sbuf);
  rmdir("blubb");

  if (!_WBenchMsg) return 1;

  // started via workbench.

  return 0;
}
And compile it using
Code:
m68k-amigaos-gcc bla.c -Os -o bla -noixemul
OK thanks, I'll give that a go

Update: Yep that works, thanks

Last edited by NovaCoder; 02 October 2018 at 01:31.
NovaCoder is offline  
Old 01 October 2018, 20:05   #932
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 21,901
I noticed that pfs3aio since v3.1 test #2 has extra data hunk, with size of 1 long, content 0x000011d0 and single reloc entry. None of object files should have non-constant data and nm only lists text ("T") symbols.

Updating to latest amiga-gcc didn't change anything (make clean/clean-prefix, git pull, make update, make all stuff done)

How to find out where it comes from? Some library?

(I was about to release final v3.1 pfs3aio but this needs to be fixed first, it should be 100% pure, single hunk and rommable)
Toni Wilen is offline  
Old 02 October 2018, 09:59   #933
bebbo
Registered User

 
Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 307
Quote:
Originally Posted by Toni Wilen View Post
I noticed that pfs3aio since v3.1 test #2 has extra data hunk, with size of 1 long, content 0x000011d0 and single reloc entry. None of object files should have non-constant data and nm only lists text ("T") symbols.

Updating to latest amiga-gcc didn't change anything (make clean/clean-prefix, git pull, make update, make all stuff done)

How to find out where it comes from? Some library?

(I was about to release final v3.1 pfs3aio but this needs to be fixed first, it should be 100% pure, single hunk and rommable)
Ok - took more time than expected^^

init.c:
Code:
  static const UBYTE *intext = "_interrupt";
that's a variable living in data.

you could move it into the text segment by making it const:
Code:
  static const UBYTE * const intext = "_interrupt";
Quote:
How to find out where it comes from? Some library?
hunkdump each .o file then look into the source file where the data segement occurs and search for global / static variables
bebbo is offline  
Old 02 October 2018, 17:32   #934
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 21,901
Quote:
Originally Posted by bebbo View Post
Code:
  static const UBYTE * const intext = "_interrupt";
Thanks. Time for final version

It must have been some compiler update that changed it because this part of code has not changed for ages.
Toni Wilen is offline  
Old 03 October 2018, 22:45   #935
bebbo
Registered User

 
Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 307
For those interested in my recent versions, I am providing now
Both do contain some stuff not yet on github...
Quote:
Your branch is ahead of 'origin/master' by * commits.
  • install anywhere - it's compiles with prefix /opt/amiga but you may chose a different path to copy/install to
  • binutils 2.30.52
  • m68k-amigaos-gprof
  • some fixes
  • use vc (vbcc front end) with provided vc.config
  • ...

I also wrote a script to easily benchmark different compilers. Here is the chart for dhrystone21.c:



You may provide more benchmarks and compilers (prebuild for linux) and I'll update the chart and maybe also the compiler explorer

Last edited by bebbo; 05 October 2018 at 16:23.
bebbo is offline  
Old 03 October 2018, 22:49   #936
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 47
Posts: 441
Ummm, gprof??? As in "profiler works"?
alkis is offline  
Old 03 October 2018, 22:52   #937
bebbo
Registered User

 
Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 307
Quote:
Originally Posted by alkis View Post
Ummm, gprof??? As in "profiler works"?
give it a try

Code:
 m68k-amigaos-gprof.exe test_gprof
Flat profile:

Each sample counts as 0.02 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls   s/call   s/call  name
 99.11      2.22     2.22        1     2.22     2.22  new_func1
  0.89      2.24     0.02        1     0.02     2.24  main
  0.00      2.24     0.00        2     0.00     1.11  func1

Last edited by bebbo; 03 October 2018 at 23:06.
bebbo is offline  
Old 03 October 2018, 22:55   #938
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 47
Posts: 441
Quote:
Originally Posted by bebbo View Post
give it a try
will do, as soon as they hit github!

Issues to be reported at https://github.com/bebbo/gcc or you have a new location?
alkis is offline  
Old 04 October 2018, 09:38   #939
pipper
Registered User

 
Join Date: Jul 2017
Location: San Jose
Posts: 94
Does anyone know how to build a .library file with the gcc toolchain? I tried to follow the example at https://github.com/bebbo/amigaos-cro...mple-library.c but had no success. It built _something_ but I don’t think it’s a valid library file
pipper is online now  
Old 04 October 2018, 10:34   #940
Samurai_Crow
Total Chaos forever!

Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Ft. Collins, CO USA
Age: 44
Posts: 1,099
Send a message via Yahoo to Samurai_Crow
I think you're supposed to build with custom startup code.

Try typing "make simple.library_r" and look at the -resident command line option.

Last edited by Samurai_Crow; 04 October 2018 at 10:43.
Samurai_Crow is offline  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
New GCC based dev toolchain for AmigaOS 3.x cla Coders. Releases 8 24 December 2017 10:18
Issue with photon/xxxx WinUAE Toolchain arpz Coders. Asm / Hardware 2 26 September 2015 22:33
New 68k gcc toolchain arti Coders. C/C++ 17 31 July 2015 03:59
Hannibal's WinUAE Demo Toolchain 5 Bobic Amiga scene 1 23 July 2015 21:04
From gcc to vbcc. Cowcat Coders. General 9 06 June 2014 14:45

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 04:53.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.08414 seconds with 14 queries