Home > other >  Please understand the C programming, also know some great god answer libvirt virtualization interfac
Please understand the C programming, also know some great god answer libvirt virtualization interfac

Time:09-30

Source program following


#include
#include

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 the connect to the local QEMU/KVM hypervisor */
Conn=virConnectOpenReadOnly (NULL);
If (conn==NULL)
{
Fprintf (stderr, "Failed to connect to the 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, & amp; Info) & lt; 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 ", the info. NrVirtCpu);

Printf (" maxMem: % d KB \ n ", the info. MaxMem);

Printf (" the memory: % d KB \ n ", the info. The memory);

If (dom!=NULL)

VirDomainFree (dom);

If (conn!=NULL)

VirConnectClose (conn);

return 0;

}

Int main (int arg c, char * * argv)

{

Int dom_id=3;

Printf (" -- -- Get domain info by ID via libvirt API - - C \ n ");

GetDomainInfo (dom_id);

return 0;

}


In eshell compiled, appear the following error

/TMP/ccy8wXgz. O: function In ` getDomainInfo ':
Qwe. C: (. Text + 0 x21) : undefined reference to ` virConnectOpenReadOnly '
Qwe. C: (. Text + 0 x6b) : undefined reference to ` virDomainLookupByID '
Qwe. C: (. Text + 0 xa1) : undefined reference to ` virConnectClose '
Qwe. C: (. Text + 0 xbe) : undefined reference to ` virDomainGetInfo '
Qwe. C: (. Text + 0 xed) : undefined reference to ` virDomainFree '
Qwe. C: (. Text + 0 xf9) : undefined reference to ` virConnectClose '
Qwe. C: (. Text + 0 x17a) : undefined reference to ` virDomainFree '
Qwe. C: (. Text + 0 x18d) : undefined reference to ` virConnectClose '
Collect2: ld returned 1 exit status
/root/Desktop #


I have call, the header file and contains the parameters, this is how to return a responsibility?

CodePudding user response:

How do you compile? Any - lvirt about this parameter?
  • Related