Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 链接kstat库时出错_C_Compiler Errors_Solaris 10_Kstat - Fatal编程技术网

C 链接kstat库时出错

C 链接kstat库时出错,c,compiler-errors,solaris-10,kstat,C,Compiler Errors,Solaris 10,Kstat,您好,我一直在尝试链接solaris服务器上的kstat库,以用于类的项目。为了做到这一点,我把它放在将使用它的标题的开头 #ifdef HAVE_KSTAT #include <kstat.h> #endif sh.o是包含part3.o的父文件,part3.o是使用kstat的文件。但是我得到了错误 /usr/bin/ld: cannot find -lkstat collect2: error: ld returned 1 exit status 而且 part3.h:8:

您好,我一直在尝试链接solaris服务器上的kstat库,以用于类的项目。为了做到这一点,我把它放在将使用它的标题的开头

#ifdef HAVE_KSTAT
#include <kstat.h>
#endif
sh.o是包含part3.o的父文件,part3.o是使用kstat的文件。但是我得到了错误

/usr/bin/ld: cannot find -lkstat
collect2: error: ld returned 1 exit status
而且

part3.h:8:19: fatal error: kstat.h: No such file or directory

 #include <kstat.h>
                   ^
compilation terminated.
make: *** [sh.o] Error 1
part3.h:8:19:致命错误:kstat.h:没有这样的文件或目录
#包括
^
编译终止。
制造:**[sh.o]错误1

我做错了什么,如何正确链接kstat库。我尝试在make文件中创建part3.o自己的对象,并在其中链接kstat,但它给了我缺少分隔符的错误。

您必须找到此库的文件(例如
kstat.a
kstat.so
)及其标题。然后分别使用
-I
-L
将路径传递到头和库


例如:
$CC-I/usr/include/kstat-L/usr/lib/kstat files-lkstat

在服务器上找到这两个文件的路径后,我将尝试此操作。
gcc
链接器按照命令行上列出的顺序处理命令行参数。因此,库路径应该正好位于“short”库名称之前,并且这两个元素都应该位于命令行的末尾。定义不变的宏时,请使用
:=
而不是
=
,这样宏只计算一次。对于不生成同名文件的目标(如:clean),在目标之前有一个
.PHONY:clean
语句。使用宏替换系统实用程序(如gcc)是为了确保执行正确的实用程序。因此,宏需要具有实用程序的完整路径。(比如:CC:=/usr/lib/gcc)。注意
rm
也是一个系统实用程序,因此应接受相同的处理。应首先列出主依赖项文件,因此:
Funcs.o:Funcs.h Funcs.c
也应为:
Funcs.o:Funcs.c Funcs.h
,然后可将配方列为:
$(CC)-g-c-o$@$请勿在link语句中放置*.c文件(即,删除参数
main.c
,并添加一个新目标,用于将
main.c
编译到
main.o
part3.h:8:19: fatal error: kstat.h: No such file or directory

 #include <kstat.h>
                   ^
compilation terminated.
make: *** [sh.o] Error 1