Issue
my files dependencies a.c
, a.h
, b.c
, b.h
, c.c
, c.h
, are like that:
// a.c
#include "a.h"
#include "b.h"
#include "c.h"
#include <lib>
// b.c
#include "b.h"
#include <lib>
// c.c
#include "c.h"
#include <lib>
I have no main()
function. I need to create out.o
and someone else will use this with main in his program (he'll have to write #include "a.h"
to use the functions I wrote there).
so I wrote
gcc -std=c99 -c c.c -o c.o -llib
gcc -std=c99 -c b.c -o b.o -llib
gcc -std=c99 -c a.c -o a.o -llib
but when I try to combine them using
gcc -o out.o a.o b.o c.o -llib
I get many errors like relocation 18 has invalid symbol index 13
and in the end undefined reference to 'main'
.
How can I create what I need? `
Solution
I think you want to create a library out of your .o files.
ar crf yourlib.a a.o b.o c.o
then, other people can compile their programs by doing, for example:
gcc -o main main.c yourlib.a
Answered By - zsram Answer Checked By - David Marino (WPSolving Volunteer)