Customizing make file with added library

I'm fairly new to C and have been trying to edit an example code in a library. The example comes with a Makefile. Everything has been working fine, but I want to add another library to this example (along with the previous ones used), to test some new things. The library I am trying to add comes with a .c file and a .h file. I have copied both of these files into the same directory as the original include folder. I am not sure what is going wrong.
Here is the following error I get in console.

cc -I../../include -L../../lib -L../../lib64 main.c -o Biometry
-lbsapi /usr/bin/ld: skipping incompatible ../../lib/libbsapi.so when searching for -lbsapi /tmp/ccswByGY.o: In function `main': main.c:(.text+0xd4f): undefined reference to `tpl_map' main.c:(.text+0xd73): undefined reference to `tpl_pack' main.c:(.text+0xd8e): undefined reference to `tpl_dump' main.c:(.text+0xd9a): undefined reference to `tpl_free' collect2: error: ld returned 1 exit status Makefile:8: recipe for target 'Biometry' failed make: *** [Biometry] Error 1

Here is the Makefile text

CPPFLAGS = -I../../include
CFLAGS =
LDFLAGS = -L../../lib -L../../lib64
LIBS = -lbsapi

Biometry: main.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) main.c -o Biometry $(LIBS)
The include folder contains:
bsapi.h
bserror.h
bssrv.h
bstypes.h
(including the two that I added):
tpl.h,
tpl.c
(I'm not sure if this goes here?)

In my code I've included the extra library; it now starts off like this:

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <bsapi.h>
#include <tpl.h>

All the help is appreciated!

To understand the error
http://www.cplusplus.com/forum/general/113904/#msg622055

1) put `tpl.c' in the same directory as `main.c'
Then change the makefile to
1
2
Biometry: main.c tpl.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)

With this it should build, the problem is that you are recompilling both files for any changes

a. Write the dependencies
1
2
3
4
5
6
7
8
9
Biometry: main.o tpl.o
	$(CC) $(LDFLAGS) $^ -o $@ $(LIBS)
	
#The dependencies may be obtained with g++ -MM
main.o: main.c tpl.h
tpl.o: tpl.c tpl.h
	
%.o: %.cpp
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

Automatizing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
CPPFLAGS = -I../../include
CFLAGS = 
LDFLAGS = -L../../lib -L../../lib64
LIBS = -lbsapi

project=Biometry

#capture all the sources in the current directory
sources:=$(wildcard *.cpp)
#name substitution .cpp -> .o
objects:=$(sources:.cpp=.o)
dependencies:=$(sources:.cpp=.d)
#to generate the dependencies files *.d
CPPFLAGS+=-MP -MMD

$(project): $(objects)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)

-include $(dependencies)
Topic archived. No new replies allowed.