Well made my first library. Now it has changed, starting with the own z80asm:
https://github.com/z88dk/z88dk/wiki/Tool---z80asm
... as librarian
z88dk-z80asm -xlibrary.lib [options] file...
When called with the -x option, z80asm builds a library containing all the object files passed as argument. That library can then be used during linking by specifying it with the -l option.
In this example we take the typical folder layout:
So now you put all your individual files into your library folder, in my example all are C source files, then compile with:
Code: Select all
lib/mylib1$ zcc +platform [options] -c *.c -I/your/include/folder
This output to .o files.
Then from the your main lib folder and create the library file:
Code: Select all
lib$ z88dk-z80asm -xmylib1.lib mylib1/*.o
Not tested but I suppose if we have a mix we could simply pass as files: *.o *.asm
Now to compile our program with our library:
Code: Select all
$ zcc +platform [options] -L/your_library_folder -lmylib1 .....
But some things are not clear for me, like using the __LIB__ qualifier, according to old documentation:
The __LIB__ qualifier will cause the C compiler to translate these header functions into sequences of “LIB myfunc”, “LIB init”, etc so that the linker will know those references are for library functions. The C compiler will generate code like “call myfunc” and “call init” to call these functions.
With some examples:
Code: Select all
#ifndef _MYHEADER
#define _MYHEADER
extern void __LIB__ myfunc(int a, int b);
extern void __LIB__ init(void);
#endif
I have tested without the __LIB__ qualifier, and it works perfectly, only linking the required ones. Later I added the __LIB__ to header file, but without recompiling the library, and the ZCC cannot find the symbols, after recompiling the library (the whole process, compiling with zcc then creating it with z88dk-z80asm) it does.
In both cases works fine, so not sure the purpose of the __LIB__ qualifier. I noticed that z88dk libraries uses it, so not sure if it is required for working correctly or is just because heritage from previous.