Impossible to compile two files

Bug reports (if you don't/won't have a Github account)
Post Reply
joaopa
Member
Posts: 46
Joined: Sat Mar 15, 2014 5:42 pm

Impossible to compile two files

Post by joaopa »

I have two files!

try1.c
#include <stdio.h>

int affiche(void);

int main(void)
{
printf("toto\n");
affiche();
return 0;
}

try2.c
#include <stdio.h>

int affiche(void)
{
printf("tata\n");
return 0;
}

With gcc, this is correct:
gcc -o try try1. try2.c

With z88dk, I obtain
zcc +zx -o try try1.c try2.c
cp /home/david/z88dk/lib/config//../..//lib/spec_crt0.opt /tmp/tmpXXw3UHJE.opt
cp /tmp/tmpXXw3UHJE.opt /tmp/tmpXXw3UHJE.asm
zcpp -I. -DZ80 -DSPECTRUM -D__SPECTRUM__ -D__SPECTRUM -DSCCZ80 -DSMALL_C -I/home/david/z88dk/lib/config//../..//include try1.c /tmp/tmpXXO32KhH.i
sccz80 -asm=z80asm /tmp/tmpXXO32KhH.i
copt /home/david/z88dk/lib/config//../..//lib/z80rules.2 < /tmp/tmpXXO32KhH.asm > /tmp/tmpXXO32KhH.op1
copt /home/david/z88dk/lib/config//../..//lib/z80rules.1 < /tmp/tmpXXO32KhH.op1 > /tmp/tmpXXO32KhH.opt
z80asm -eopt -ns -Mo -I/home/david/z88dk/lib/config//../..//lib /tmp/tmpXXO32KhH.opt
Error at file '/tmp/tmpXXO32KhH.opt' line 23: symbol '_affiche' not defined
1 errors occurred during assembly
Errors in source file try1.c:
Error at file '/tmp/tmpXXO32KhH.opt' line 23: symbol '_affiche' not defined
^ ---- call _affiche
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

sccz80 is creating function prototypes with static linkage by default rather than extern.

Slipping an extern keyword in front of function prototypes will work around the bug:

try1.c

Code: Select all

#include <stdio.h>

extern int affiche(void);

int main(void)
{
    printf("toto\n");
    affiche();
    return 0;
}
joaopa
Member
Posts: 46
Joined: Sat Mar 15, 2014 5:42 pm

Post by joaopa »

Thanks. That did the trick. It would be a good idea to fix this bug though!!
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Linkage for function prototypes has to be changed to EXTERN by default in declglb() but I'm not familiar enough with the code to figure out how to do it.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Fixed in the feb 22 build.

An updated windows sccz80.exe file can be downloaded from here before feb 22:
https://drive.google.com/open?id=0B6XhJ ... i01QjRtdE0
Post Reply