[libvirt] libvirt question

Hello,I wrote a program using libvirt API to get vm information like this: /*dom is virDomainPtr type*/ dom=virDomainLookupByID(conn,activeDomains[i]); if(dom!=NULL) printf("%d ----------%s\n",activeDomains[i],dom->name); ...... but when compile it,error occured like this: vm_eraser_detect.c:125:54: error: dereferencing pointer to incomplete type printf("%d ----------%s\n",activeDomains[i],dom->name); what is the reason of it??? thanka a lot! zhunxun@gmail.com

On Fri, May 19, 2017 at 10:52:32AM +0800, zhunxun@gmail.com wrote:
Hello,I wrote a program using libvirt API to get vm information like this: /*dom is virDomainPtr type*/ dom=virDomainLookupByID(conn,activeDomains[i]); if(dom!=NULL) printf("%d ----------%s\n",activeDomains[i],dom->name); ...... but when compile it,error occured like this: vm_eraser_detect.c:125:54: error: dereferencing pointer to incomplete type printf("%d ----------%s\n",activeDomains[i],dom->name); what is the reason of it??? thanka a lot!
TL;DR s/dom->name/virDomainGetName(dom)/ Explanation: Where did you get the idea that virDomainPtr has a name in it? Is that in some of our documentation? Even if you saw it in the sources, the compiler has no way of knowing that because you haven't included that structure definition anywhere. That's because we don't expose it in any public header files. That way we can change it at any point in the future. And for callers to access it, we just expose a function to get the name.
zhunxun@gmail.com
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

Thanks a lot! zhunxun@gmail.com From: Martin Kletzander Date: 2017-05-19 14:16 To: zhunxun@gmail.com CC: libvir-list Subject: Re: [libvirt] libvirt question On Fri, May 19, 2017 at 10:52:32AM +0800, zhunxun@gmail.com wrote:
Hello,I wrote a program using libvirt API to get vm information like this: /*dom is virDomainPtr type*/ dom=virDomainLookupByID(conn,activeDomains[i]); if(dom!=NULL) printf("%d ----------%s\n",activeDomains[i],dom->name); ...... but when compile it,error occured like this: vm_eraser_detect.c:125:54: error: dereferencing pointer to incomplete type printf("%d ----------%s\n",activeDomains[i],dom->name); what is the reason of it??? thanka a lot!
TL;DR s/dom->name/virDomainGetName(dom)/ Explanation: Where did you get the idea that virDomainPtr has a name in it? Is that in some of our documentation? Even if you saw it in the sources, the compiler has no way of knowing that because you haven't included that structure definition anywhere. That's because we don't expose it in any public header files. That way we can change it at any point in the future. And for callers to access it, we just expose a function to get the name.
zhunxun@gmail.com
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (2)
-
Martin Kletzander
-
zhunxun@gmail.com