0

I've been working on a module in C (under Linux) that requires another module (headers are in other directories). My problem is that when I compile the code with my Makefile, the gcc compiler tells me that some headers aren't found.

gcc -c render.c

So I include the directories to find the header but here, gcc tries to find the "main" function which does not exist: it is a module...

gcc /opt/vc/include -c render.c

So I would like to know how is it possible to compile a module (output in module.o) that requires other modules?

Here are my files:

render.c:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "render.h"

int width,height;
int loop,counter;

int initRender(void(*setup)(void),void(*draw)(void),void(*end)(void))
{
    init(&width, &height);
    loop = -1;
    counter = 0;

    setup();
    while(loop==-1)
    {
        Start(width, height);
        draw();
        End();
        counter++;
    }
    end();
    finish();
    exit(0);
    return 0;
}

render.h:

#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"

#ifndef RENDER_H_
#define RENDER_H_
extern int width,height;
extern int loop,counter;

int initRender(void(*setup)(void),void(*draw)(void),void(*end)(void));

#endif

Makefile:

INCLUDEFLAGS=-I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -IopenVG
LIBFLAGS=-L/opt/vc/lib -lGLESv2 -lEGL -lbcm_host -lpthread  -ljpeg -LopenVG
NEEDED= openVG/libshapes.o openVG/oglinit.o

all: render

render.o:   render.c
    gcc -Wall -g $(INCLUDEFLAGS) -c render.c
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
hugodecasta
  • 262
  • 4
  • 13

1 Answers1

3

You probably want

 gcc -Wall -g -I/opt/vc/include -c render.c

this will produce a render.o object file.

Please take time to read the documentation about invoking GCC. In particular, check what every option -Wall, -g, -I and -c means. IMHO the first two are very important.

Later, you probably want to link all your object files into an executable, with some external libraries. Perhaps you want something like

 gcc -g -Wall -L/opt/vc/lib render.o main.o -lvc -o myprogram

(you really want the -Wall and -g options; IMHO you need to be an expert to dare avoiding them; once you have debugged your program and want to benchmark it, add -O2 for optimizations)

But surely, you want other options.

Notice that order of arguments to gcc matters a lot

Of course, you should learn about GNU make and you need to use it. See this and that examples. You might use make --trace (with recent make) or remake to debug your Makefile (which is not good). You should also run once make -p to understand more the builtin rules of make.

Perhaps you want a library, then read the Program Library HowTo.

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Thanck you Basile for your answer, in fact I knew that using the -I/../ would help me to include my directorys but I need 4 of them like: gcc -I/opt/vc/include -IopenVG -c render.c But here gcc talks me about main not being there... – hugodecasta Jan 03 '16 at 17:56
  • Please don't include options that do not work towards the thing OP tries to achieve (`-Wall -g`). Too often I've seen people copy-pasting command lines from Stack Overflow without understanding what they mean. – fuz Jan 03 '16 at 18:00
  • 2
    I strongly disagree: beginners should *always* use `-Wall -g` and most experts also *almost always* use them (there are *rare* cases where you don't want them when you develop some code). I did however invite the OP to *read the documentation* to understand what they means. – Basile Starynkevitch Jan 03 '16 at 18:02