Hey there I'm having trouble linking a static lib in my app (C program), I don't understand why this won't work as I am following the instructions from the "Programming Linux Games", Page 29 "Working with Libraries"
For simplicity's sake I'm trying to link the following source as a static lib to a main.c:
Code:
/* myCharLib.c */
#include "myCharLib.h"
const char get_char(){
return MY_CHAR;
}
Code:
#ifndef MYCHARLIB_H_
#define MYCHARLIB_H_
const char MY_CHAR = 'J';
const char get_char();
#endif
Code:
/* myIntLib.c */
#include "myIntLib.h"
const int get_integer()
{
return MY_INT;
}
Code:
#ifndef MYINTLIB_H_
#define MYINTLIB_H_
const int MY_INT = 84;
const int get_integer();
#endif
And here is the make file I'm using:
Code:
CC=gcc
CFLAGS=-W -Wall -pedantic
libcMyLib.a: myCharLib.c myIntLib.c
$(CC) $(CFLAGS) -c myCharLib.c myIntLib.c
ar rcs libcMyLib.a myCharLib.o myIntLib.o
ranlib libcMyLib.a
.PHONY: clean
clean:
rm *.o
rm *.a
And my main.c file:
Code:
#include <stdio.h>
const int get_int();
const char get_char();
int main()
{
get_int();
get_char();
return 0;
}
So my working directory has these files after running make:
Code:
libcMyLib.a main.c makefile myCharLib.c myCharLib.h myCharLib.o myIntLib.c myIntLib.h myIntLib.o
Now I try compiling main.c and linking with libMyLib.a and this is what I get:
Code:
gcc -static main.c -L. -lcMyLib -o main
/tmp/cc0wiQCm.o: In function `main':
main.c:(.text+0x7): undefined reference to `get_int'
main.c:(.text+0xc): undefined reference to `get_char'
collect2: ld returned 1 exit status
Where exactly am I going wrong here?
*Edit, yes I am aware of the sticky, but I've also tried following that advice and end up with the same linking problem
Bookmarks