mardi 9 mars 2021

How do you link two files in make, that both include a different library?

I want to test my code in test.c which includes main.h with all the function declarations from main.c. I want to compile my test.c file with criterion, which on its own works fine like this: cc -c test.c -o testing -I include -L lib -l criterion.3.1.0 and I compile my main.c in the same way and it works fine: cc main.c -o output -I include -L lib -l SDL2-2.0.0. But when I want to include a function from main.c in test.c it gives me a linking error. The project architecture is like this:

//main.c

#include "main.h"

int function1(){
    [...]
}

//test.c
#include "main.h"
#include <criterion/criterion.h>

Test(sample,test_function1){
    cr_assert(function1() == 1);
}

//main.h
#include <SDL2/SDL.h>

extern int function1();

How do I have to compile/link these files in order to have my test-file use get access to the functions from main.c?

Aucun commentaire:

Enregistrer un commentaire