Question

I have a mysterious problem! In the main.c I have the following:

#include "jogo.h"
int main(){
    int i;
    sef_startup();
    vg_init(0x105);
    batalha_naval();
    sleep(5);
    vg_exit();
    return 0;
}

In the jogo.h I have:

#ifndef __JOGO_H
#define __JOGO_H
void batalha_naval(void);
#endif

And in the main.c I have:

#include "core.h"
void batalha_naval(void) {
    vg_draw_line(0, 0, 1023, 0, 12);
}

But when doing a make the compiler gives a undefined _batalha_naval(); in the main.c. If I define the function in the jogo.h an error doesn't appear, but if I do like this the error appears.

I am using CC compiler.

Was it helpful?

Solution

  1. Your jogo.h appears correct. You need it if you wish to use function "batalha_naval()" in multiple compilation units.

  2. You should '#include "jogo.h"' in main.c, and in jogo.c.

  3. You must include both main and jogo in your link command.

OTHER TIPS

How are you linking? You need to do either:

$ cc -c main.c
$ cc -c jogo.c
$ cc main.o jogo.o

or

$ cc main.c jogo.c
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top