Including Libraries question

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
czarnikjak
New member
Posts: 9
Joined: Tue Jan 03, 2023 10:31 am

Including Libraries question

Post by czarnikjak »

I am pretty new to C and Z88dk, so apologies if this is a silly question and I am doing something wrong.

I am trying to use the following libraries in my code:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <arch/zx.h>
#include <rs232.h>

int main() {
}
These are the compiler options:
zcc +zx -vn -startup=0 -clib=sdcc_iy test.c -o test -create-app

stdlib.h, zx.h and stdio.h import just fine, but the rs232.h doesn't with this error:

test.c:4:19: fatal error: rs232.h: No such file or directory

This baffles me, as when I look inside my ./z88dk/include folder, rs232.h is there, alongside stdio.h and stdlib.h:
You do not have the required permissions to view the files attached to this post.
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Including Libraries question

Post by jorgegv »

When using newlib, headers are under include/_DEVELOPMENT, and no rs232.h lives there, so I guess serial was not migrated to newlib.

I have the following similar code:

Code: Select all

// zcc +zx -vn serial.c -o serial -lndos -lrs232plus -create-app
// zcc +zx -vn -compiler=sdcc serial.c -o serial -lndos -lrs232plus -create-app
// zcc +zx -vn -compiler=sdcc -clib=sdcc_iy serial.c -o serial -lndos -lrs232plus -create-app

#include <rs232.h>
#include <stdio.h>

void init( void ) {
    rs232_params( RS_BAUD_38400 | RS_STOP_1 | RS_BITS_8, RS_PAR_NONE );
    rs232_init();
}

void rs232_puts( char *txt ) {
    while ( *txt ) rs232_put( *txt++ );
    rs232_put( '\n' );
}

void main( void ) {
    puts( "Hola" );
    rs232_puts( "Hola por el canal serie" );
    puts( "Adios" );
}
The first two compilation lines work fine (classic lib), the third one does not (newlib).
czarnikjak
New member
Posts: 9
Joined: Tue Jan 03, 2023 10:31 am

Re: Including Libraries question

Post by czarnikjak »

jorgegv wrote: Tue Jan 03, 2023 3:12 pm The first two compilation lines work fine (classic lib), the third one does not (newlib).
Thanks Jorge, I made progress

With this compile line it does find the rs232.h but still fails compilation with different error this time:

zcc +zx -vn test.c -o test -lndos -lrs232plus -create-app

Error: Section overlaps section CODE by 2283 bytes
zx: Aborting... one or more binaries overlap
Building application code failed


Thats for the source code you pasted above. No idea why this comes up.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Including Libraries question

Post by dom »

Remove any existing binary files before compiling - I think there’s a rogue a_CODE.bin or similar floating around the place.
czarnikjak
New member
Posts: 9
Joined: Tue Jan 03, 2023 10:31 am

Re: Including Libraries question

Post by czarnikjak »

dom wrote: Tue Jan 03, 2023 5:25 pm Remove any existing binary files before compiling - I think there’s a rogue a_CODE.bin or similar floating around the place.
Thank you Dom, that did the trick.

One thing I noticed when not using the new library, that in the compiler line I need to add things like -lndos for it to compile. It compiles just fine without -lndos when using -clib option.

Can somebody explain to a noob like me why this is the case? And how can one work out which -lxxxx is needed for respective included header file?

Thanks!
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Including Libraries question

Post by dom »

The underlying cause is that's there's two "separate" library implementations within z88dk. The so called "classic" and "new" libraries.

Originally, the classic library and new library were completely different code bases, however over time they have mostly converged with the result that the only differences are as follows:

- Classic supports many more targets and has different way of implementing the crt0 startup file
- Classic uses the same library for both sccz80 and sdcc compiles
- <stdio.h> is a different implementation that supports file io
- Classic supports multiple floating point libraries for pure sccz80 compilations
- Classic provides cross platform graphics, sound, text libraries, rs232
- Classic tends to be tuned at link time, newlib at library build time
- Newlib has some +zx specific libraries that haven't been backported (yet)

The "new" library was written by Alvin before he moved onto ZX Next things with the intention of providing a more standards compliant C library and providing performance tuning options. However, it was only implemented for a small number of targets and omitted file io. It does have a number of interesting ideas that were much easier to cherry-pick into classic rather than port all 100+ targets to newlib.

There's a thread somewhere on here, indicating that it's probably best to choose classic for new projects.

In general you should only need to specify an extra library if there's a choice of implementations available, broadly this tends to be maths libraries, file io and rs232 libraries. -lndos stands for "no dos" and just contains empty stubs for fileio.
czarnikjak
New member
Posts: 9
Joined: Tue Jan 03, 2023 10:31 am

Re: Including Libraries question

Post by czarnikjak »

dom wrote: Wed Jan 04, 2023 11:55 am
In general you should only need to specify an extra library if there's a choice of implementations available, broadly this tends to be maths libraries, file io and rs232 libraries. -lndos stands for "no dos" and just contains empty stubs for fileio.
Ah, that makes more sense now! Thanks for explaining this, I see now why I had to use -lndos and -lrs232plus :)

I have started my exploration by following this excellent guide https://github.com/z88dk/z88dk/blob/mas ... edGuide.md , which is focusing on newlib, hence I wasn't aware of the details of the classic library.

One more thing I cant work out with classic library is -startup=0 and -startup=30.
Classic lib apps seem to default to 64 column mode, which is less readable on TV and uses more memory.
Is there an easy way to replicate what newlib -startup does in the classic library?

Thanks again and sorry for these basic questions!
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Including Libraries question

Post by dom »

czarnikjak wrote: Wed Jan 04, 2023 1:13 pmOne more thing I cant work out with classic library is -startup=0 and -startup=30.
Classic lib apps seem to default to 64 column mode, which is less readable on TV and uses more memory.
Is there an easy way to replicate what newlib -startup does in the classic library?
There's not a one-to-one mapping, however there's an option to switch over to the ROM screen driver: https://github.com/z88dk/z88dk/wiki/Pla ... rom-driver
czarnikjak
New member
Posts: 9
Joined: Tue Jan 03, 2023 10:31 am

Re: Including Libraries question

Post by czarnikjak »

dom wrote: Wed Jan 04, 2023 1:25 pm
czarnikjak wrote: Wed Jan 04, 2023 1:13 pmOne more thing I cant work out with classic library is -startup=0 and -startup=30.
Classic lib apps seem to default to 64 column mode, which is less readable on TV and uses more memory.
Is there an easy way to replicate what newlib -startup does in the classic library?
There's not a one-to-one mapping, however there's an option to switch over to the ROM screen driver: https://github.com/z88dk/z88dk/wiki/Pla ... rom-driver
Thanks, this
-pragma-redirect:fputc_cons=fputc_cons_rom_rst
does the trick and minimizes memory usage by the looks of it.
Post Reply