Hi so I have been trying to link the kstat library on a solaris server for a project for class. to do this i have put this at the beginning of the header that will use it
#ifdef HAVE_KSTAT
#include <kstat.h>
#endif
and my make file looks like
CC=gcc
#CC=gcc -Wall
mysh: sh.o Funcs.o mp3.o get_path.o part3.o main.c
$(CC) -g -pthread -lkstat main.c sh.o Funcs.o mp3.o get_path.o part3.o -o mysh
Funcs.o: Funcs.h Funcs.c
$(CC) -g -c Funcs.c
mp3.o: mp3.h mp3.c
$(CC) -g -c mp3.c
sh.o: sh.c sh.h
$(CC) -g -c -pthread -DHAVE_KSTAT sh.c
get_path.o: get_path.c get_path.h
$(CC) -g -c get_path.c
clean:
rm -rf sh.o get_path.o mysh Funcs.o part3.o
sh.o being the parent file that includes part3.o which is the file using kstat. However i get the error
/usr/bin/ld: cannot find -lkstat
collect2: error: ld returned 1 exit status
and also
part3.h:8:19: fatal error: kstat.h: No such file or directory
#include <kstat.h>
^
compilation terminated.
make: *** [sh.o] Error 1
what have i done wrong, how do i properly link the kstat library. I tried making part3.o its own object for creation within the make file and linking kstat in that one but it gave me the error missing separator.
You have to find the files of this library (e.g.
kstat.a
orkstat.so
) and its headers. Then pass the paths to headers and the lib with-I
and-L
respectively.For example:
$CC -I /usr/include/kstat -L /usr/lib/kstat files -lkstat