源程序如下
#include <stdio.h>
#include <libvirt/libvirt.h>int getDomainInfo(int id) {virConnectPtr conn = NULL; /* the hypervisor connection */
virDomainPtr dom = NULL; /* the domain being checked */
virDomainInfo info; /* the information being fetched *//* NULL means connect to local QEMU/KVM hypervisor */
conn = virConnectOpenReadOnly(NULL);
if (conn == NULL)
{
fprintf(stderr, "Failed to connect to hypervisor\n");
return 1;}/* Find the domain by its ID */
dom = virDomainLookupByID(conn, id);if (dom == NULL) {fprintf(stderr, "Failed to find Domain %d\n", id);virConnectClose(conn);return 1;}/* Get virDomainInfo structure of the domain */
if (virDomainGetInfo(dom, &info) < 0) {fprintf(stderr, "Failed to get information for Domain %d\n", id);virDomainFree(dom);virConnectClose(conn);return 1;}/* Print some info of the domain */printf("Domain ID: %d\n", id);printf(" vCPUs: %d\n", info.nrVirtCpu);printf(" maxMem: %d KB\n", info.maxMem);printf(" memory: %d KB\n", info.memory);if (dom != NULL)virDomainFree(dom);if (conn != NULL)virConnectClose(conn);return 0;}int main(int argc, char **argv){int dom_id = 3;printf("—–Get domain info by ID via libvirt C API —–\n");getDomainInfo(dom_id);return 0;}
进入eshell里面编译之后,出现如下错误/tmp/ccy8wXgz.o: In function `getDomainInfo':
qwe.c:(.text+0x21): undefined reference to `virConnectOpenReadOnly'
qwe.c:(.text+0x6b): undefined reference to `virDomainLookupByID'
qwe.c:(.text+0xa1): undefined reference to `virConnectClose'
qwe.c:(.text+0xbe): undefined reference to `virDomainGetInfo'
qwe.c:(.text+0xed): undefined reference to `virDomainFree'
qwe.c:(.text+0xf9): undefined reference to `virConnectClose'
qwe.c:(.text+0x17a): undefined reference to `virDomainFree'
qwe.c:(.text+0x18d): undefined reference to `virConnectClose'
collect2: ld returned 1 exit status
/root/Desktop #
我的头文件已经调用,而且确定包含了这些参数的。这是怎么回事而?