English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 28 January 2018, 14:45   #1
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 687
Running simple C program

Hello,

I am trying to learn some C/C++ on Amiga. However I go stuck at the very beginning. I have taken the following the time I learn C on a windows machine;

Code:
#include <stdio.h>

int main(){
    
    printf("Hello World");
    return 0;
}
However when I run the make command I get the following error:

"Error 21" and "Reference to undefined symbol ___v0printf".

What am I doing wrong?
Sim085 is offline  
Old 28 January 2018, 14:50   #2
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
I guess more info is needed. which compiler are you using?
maybe attach the makefile

#1) with just this small source code, you may build it without a makefile:
Code:
gcc hello.c -o hello.exe
that's easier than updating the Makefile with any new source file.

#2) if you are using vbcc, here are some examples

Last edited by emufan; 28 January 2018 at 15:03.
emufan is offline  
Old 28 January 2018, 15:47   #3
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 687
Yes, I did check those examples and they do work. I am using vbcc. However why the simple printf call doesn't work?

My make file looks as follows (exactly as the one in the link):

Code:
CC=vc
LDFLAGS=-nostdlib

HELLO_EXE=hello
HELLO_OBJS=hello.o

all: $(HELLO_EXE)

$(HELLO_EXE) : $(HELLO_OBJS) 
    $(CC) $(LDFLAGS) -nostdlib -o $(HELLO_EXE) $(HELLO_OBJS)

%.o : %.c
   $(CC) -c -o $@ $<
That said running vc or gcc or vbcc from Shell returns Unknown command.




Quote:
Originally Posted by emufan View Post
I guess more info is needed. which compiler are you using?
maybe attach the makefile

#1) with just this small source code, you may build it without a makefile:
Code:
gcc hello.c -o hello.exe
that's easier than updating the Makefile with any new source file.

#2) if you are using vbcc, here are some examples
Sim085 is offline  
Old 28 January 2018, 16:01   #4
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
you are not alone with that error:
Code:
vc -c -o hello.o hello.c
vc -nostdlib -nostdlib -o hello hello.o
hello.o: In "_main":
Error 21: hello.o (CODE+0x6): Reference to undefined symbol ___v0printf.
/opt/m68k-amigaos/bin/vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib "hello.o"  
 -s -Rshort -L/opt/m68k-amigaos/m68k-amigaos/vbcc/lib -L...vbcc/include -o hello failed
make: *** [Makefile:10: hello] Error 1
with gcc it does build this way:
Code:
m68k-amigaos-gcc.exe -noixemul hello.c -o hello.exe
need to check vbcc in what linker lib it provides the printf function.

#1) replace -nostdlib , with -stdlib:
Code:
CC=vc
LDFLAGS=-stdlib

HELLO_EXE=hello
HELLO_OBJS=hello.o

all: $(HELLO_EXE)

$(HELLO_EXE) : $(HELLO_OBJS) 
	$(CC) $(LDFLAGS) -stdlib -o $(HELLO_EXE) $(HELLO_OBJS)

%.o : %.c
	$(CC) -c -o $@ $<
so it does build

Last edited by emufan; 28 January 2018 at 16:10.
emufan is offline  
Old 28 January 2018, 16:04   #5
ajk
Registered User
ajk's Avatar
 
Join Date: May 2010
Location: Helsinki, Finland
Posts: 1,305
You have "-nostdlib" in the Makefile. But printf() is part of the standard library and now there is no implementation for it, which is why you get the error.

Either build with the standard library or use the Amiga API for printing text.
ajk is offline  
Old 28 January 2018, 16:06   #6
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 687
So obviously I am just into this, my only experience of C development is a little from Windows. What is the advantage of using one or the other?


Quote:
Originally Posted by ajk View Post
You have "-nostdlib" in the Makefile. But printf() is part of the standard library and now there is no implementation for it, which is why you get the error.

Either build with the standard library or use the Amiga API for printing text.
Sim085 is offline  
Old 28 January 2018, 16:19   #7
ajk
Registered User
ajk's Avatar
 
Join Date: May 2010
Location: Helsinki, Finland
Posts: 1,305
Well, it doesn't really matter for a Hello World type program. The Amiga API will be more efficient when coding a (complex) program specifically for the Amiga. But it will not be portable to other systems, if that is a concern. And of course you must seek Amiga specific advice rather than be able to follow any standard tutorials.

And of course you can use both the standard library and Amiga headers in the same program, as required. You'll find that there is a "windows.h" when coding for the Windows API and also POSIX headers for Linux/UNIX and so on.
ajk is offline  
Old 28 January 2018, 22:15   #8
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 687
Thanks that really got me moving. I still have to familiarise myself and follow more tutorials but like this I can already write and run some of the basic stuff I learnt at school.
Sim085 is offline  
Old 29 January 2018, 01:04   #9
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,649
Do not use Makefiles from somebody else when you don't know what all the options are doing in it.

Compiling a single source using the standard clib into an executable is as easy as typing:
Code:
vc +aos68k -o hello hello.c
(in case you are compiling for m68k)
phx is offline  
Old 29 January 2018, 10:04   #10
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 687
That is what I thought, from looking at the makefile script I can see it uses vc. However when I try it from Shell it gives me unknown command. I checked System:C and can only see make. No vc. I still can't figure how make executes vc.


Quote:
Originally Posted by phx View Post
Do not use Makefiles from somebody else when you don't know what all the options are doing in it.

Compiling a single source using the standard clib into an executable is as easy as typing:
Code:
vc +aos68k -o hello hello.c
(in case you are compiling for m68k)
Sim085 is offline  
Old 30 January 2018, 13:43   #11
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,649
Quote:
Originally Posted by Sim085 View Post
I checked System:C and can only see make. No vc. I still can't figure how make executes vc.
The vbcc binaries are in vbcc:bin, and when installed correctly the user-startup should add an assignment to C: like this:
Code:
assign >NIL: C: vbcc:bin ADD
phx 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
Simple way to check that the game is running on a CD32? earok Coders. Blitz Basic 11 18 September 2017 15:19
Running Workbench program from CLI (at startup.) Pheonix support.Other 45 15 November 2016 14:46
Simple tutorial required for running Amiga emulator on a Mac Pauly79 support.FS-UAE 1 10 February 2014 12:38
External windows program communicating with program running inside WinUAE xxxxx support.WinUAE 10 19 February 2013 09:27
Simple weather program. Thorham Coders. General 1 04 September 2010 00:53

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 11:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.09337 seconds with 13 queries