28 January 2018, 14:45 | #1 |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
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; } "Error 21" and "Reference to undefined symbol ___v0printf". What am I doing wrong? |
28 January 2018, 14:50 | #2 |
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 #2) if you are using vbcc, here are some examples Last edited by emufan; 28 January 2018 at 15:03. |
28 January 2018, 15:47 | #3 | |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
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 $@ $< Quote:
|
|
28 January 2018, 16:01 | #4 |
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 Code:
m68k-amigaos-gcc.exe -noixemul hello.c -o hello.exe #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 $@ $< Last edited by emufan; 28 January 2018 at 16:10. |
28 January 2018, 16:04 | #5 |
Registered User
Join Date: May 2010
Location: Helsinki, Finland
Posts: 1,341
|
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. |
28 January 2018, 16:06 | #6 |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
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?
|
28 January 2018, 16:19 | #7 |
Registered User
Join Date: May 2010
Location: Helsinki, Finland
Posts: 1,341
|
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. |
28 January 2018, 22:15 | #8 |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
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.
|
29 January 2018, 01:04 | #9 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
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 |
29 January 2018, 10:04 | #10 |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
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.
|
30 January 2018, 13:43 | #11 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Running Workbench program from CLI (at startup.) | Pheonix | support.Other | 47 | 28 January 2022 05:24 |
Simple way to check that the game is running on a CD32? | earok | Coders. Blitz Basic | 11 | 18 September 2017 15:19 |
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 |
|
|