4

I want to split a program developed in c using z88dk in several .c files and I do not know how.

I have these files:

  1. test.c: The main file with the "main" method.
  2. test2.c: An auxiliar file with the "AuxFunction" method.
  3. test3.h: The header definition for test2.c

I Build with this command: D:\Spectrum\z88dk\bin\zcc.exe +zx -lndos -create-app test.c test2.c -o test

The error reported from zcc is this: Error at module 'test2': symbol '_AuxFunction' already defined in module 'test2'

There are the sources:

test.c

/* test.c file */

#include <stdio.h>
#include "test2.h"

void main(){
    printf("Include test 1.1!\n");
    printf(AuxFunction("Hello"));
}

test2.c

/* Test2.c file */

char* AuxFunction(char* txt){
    return txt;
}

test2.h

/* test2.h file */

char* AuxFunction(char*);

Any link, help or suggestion will be welcome!

Thanks for your time!

4
  • Are these definitely the entire contents of the files you're trying to compile? I'm wondering if some include guards in test2.h might help here.
    – Muzer
    Mar 24, 2017 at 17:32
  • These are the files I try to compile. I'm not started to work. I'm working on a Hello World to know how to do it.
    – Duefectu
    Mar 24, 2017 at 17:46
  • Since AuxFunction is defined in a separate file, you need to declare it as extern (external function) in the header file.
    – Mick
    Mar 24, 2017 at 18:08
  • 1
    Also, since this appears to be generic C code, it may be better to ask such questions in StackOverflow.
    – Mick
    Mar 24, 2017 at 18:11

1 Answer 1

5

As Mick suggested, declare AuxFunction as extern in the header file. This works for me using d88zk version 1.8, zcc version 2.57 (which is the version in the debian repos). Declaring functions 'extern' is generally useless in any compiler from the last 20 years. I guess d88zk, despite appearing to be an active project, needs to be treated as a legacy C compiler.

test2.h

/* test2.h file */

extern char* AuxFunction(char*);
4
  • Actually, I had forgotten that extern is not needed in modern C compilers, but then I'm a legacy C coder.
    – Mick
    Mar 24, 2017 at 21:03
  • With extern I get Error at module 'test2': symbol '_AuxFunction' already defined in module 'test2'. If I use zcc.exe +zx -lndos -create-app test.c -o test (without test2.c) I get: Error at file 'C:\Users\xxx.asm' line 27: symbol '_AuxFunction' not defined
    – Duefectu
    Mar 24, 2017 at 21:22
  • OK, I installed z88dk 1.99B on a Windows computer. I copy-pasted your test.c and test2.c above and my test2.h from this answer. Compile completes successfully and I have a test.tap output file. Double check to make sure that your source files match with what is posted here. Mar 24, 2017 at 22:24
  • I have one problem with z88dk v1.99b, with v1.99a Works fine, but with v1.99b didn't work. For sure I have a config trouble with v1.99b. Thanks for your help!
    – Duefectu
    Mar 24, 2017 at 23:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .