[libvirt] [libvirt-users] C API example

Dave Allan dallan at redhat.com
Thu Jul 1 21:19:09 UTC 2010


On Thu, Jul 01, 2010 at 01:43:55PM -0700, steven765 at yahoo.com wrote:
> Hi Dave, 
>    Thanks for the reply after getting some sleep the question I should have asked is what libraries do I need to link the application against?  If I just try gcc -o a.out hellolibvirt.c it can't find any of the libvirt calls.

[cc'ing the list again so the answer gets archived]

Libvirt's no different from any other library, you need to link
against libvirt, and you need to have the libvirt headers installed.
On Fedora, that's:

yum install libvirt-devel

If you want to build hellolibvirt without using make, you'll need to
edit hellolibvirt.c and take out config.h, which is unused.  Then you
can do:

gcc -o hellolibvirt -lvirt hellolibvirt.c

Then you just need to learn the API and decide what you want to do
with it. ;-)

The API is documented at:

http://libvirt.org/html/libvirt-libvirt.html

Dave



> Thanks,
> Steve
> 
> --- On Thu, 7/1/10, Dave Allan <dallan at redhat.com> wrote:
> 
> > From: Dave Allan <dallan at redhat.com>
> > Subject: Re: [libvirt-users] C API example
> > To: steven765 at yahoo.com
> > Cc: "Justin Clift" <justin at salasaga.org>, libvirt-users at redhat.com
> > Date: Thursday, July 1, 2010, 2:06 PM
> > On Wed, Jun 30, 2010 at 07:37:27PM
> > -0700, steven765 at yahoo.com
> > wrote:
> > > I think so, but I'm locked out at home. I'll have to
> > try at school tomorrow.  It gave me a remote error, but
> > with the correct directory so fingers crossed thanks! 
> > 
> > > 
> > > btw might you or anyone know what I have to include to
> > start a clean project of my own?  So if I want to just
> > build an application that uses the API with nothing else but
> > what's necessary?
> > 
> > If you're talking about a C application, you're pretty much
> > describing
> > hellolibvirt.  I tried to put enough in there to
> > demonstrate a couple
> > of different calls, but hopefully not so much that it's
> > overwhelming.
> > If it seems like there's a lot there, cut some of it
> > out.  You don't
> > need the showDomains function, for example.  Remove
> > it, compile and
> > see what happens.
> > 
> > Dave
> > 
> > 
> > > Thanks,
> > > Steve
> > > 
> > > --- On Wed, 6/30/10, Justin Clift <justin at salasaga.org>
> > wrote:
> > > 
> > > > From: Justin Clift <justin at salasaga.org>
> > > > Subject: Re: [libvirt-users] C API example
> > > > To: "Dave Allan" <dallan at redhat.com>
> > > > Cc: steven765 at yahoo.com,
> > libvirt-users at redhat.com
> > > > Date: Wednesday, June 30, 2010, 10:09 PM
> > > > On 07/01/2010 11:54 AM, Dave Allan
> > > > wrote:
> > > > <snip>
> > > > > ./hellolibvirt \
> > > > >
> > > >
> > qemu+unix:///system?socket=/var/run/libvirt/libvirt-sock
> > > > 
> > > > Thanks Dave.  The +unix:// and ?socket=xxx bits
> > are
> > > > what I'd not been picking up on.  Should be good
> > now.
> > > > 
> > > > Steven, is it working for you?
> > > > 
> > > > Regards and best wishes,
> > > > 
> > > > Justin Clift
> > > > 
> > > > -- Salasaga  -  Open Source eLearning IDE
> > > >               http://www.salasaga.org
> > > > 
> > > 
> > > 
> > > 
> > 
> 
> 
> 




More information about the libvir-list mailing list