[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] Compiling C++ program with libvirt



Hi everyone

I am trying to compile a C++ program which uses libvirt to connect to an ESXi host. I got the code running if I wrote it in C, directly in the hellolibvirt.c example. However, I am now trying to compile that code in a C++ file which is not inside the example directory.

I tried to compile with the following command:
g++ -g -D debug=1 -c -llibvirt ESXWrapper.cpp
g++ -g -D debug=1 -o ESXWrapper ESXWrapper.o

The first line passes and creates ESXWrapper.o file. But when I run the second line, it gives me the following error:
---
g++ -g -D debug=1 -c -llibvirt ESXWrapper.cpp
g++ -g -D debug=1 -o ESXWrapper ESXWrapper.o
ESXWrapper.o: In function `VPopCWrapper':
/home/wyssen/school/Dropbox/virtualPOPC-1/NEW/vpopcwrapper/ESXWrapper.cpp:124: undefined reference to `virConnectOpenAuth'
/home/wyssen/school/Dropbox/virtualPOPC-1/NEW/vpopcwrapper/ESXWrapper.cpp:133: undefined reference to `virConnectGetURI'
/home/wyssen/school/Dropbox/virtualPOPC-1/NEW/vpopcwrapper/ESXWrapper.cpp:144: undefined reference to `virConnectClose'
/home/wyssen/school/Dropbox/virtualPOPC-1/NEW/vpopcwrapper/ESXWrapper.cpp:124: undefined reference to `virConnectOpenAuth'
/home/wyssen/school/Dropbox/virtualPOPC-1/NEW/vpopcwrapper/ESXWrapper.cpp:133: undefined reference to `virConnectGetURI'
/home/wyssen/school/Dropbox/virtualPOPC-1/NEW/vpopcwrapper/ESXWrapper.cpp:144: undefined reference to `virConnectClose'
ESXWrapper.o: In function `showError':
/home/wyssen/school/Dropbox/virtualPOPC-1/NEW/vpopcwrapper/ESXWrapper.cpp:186: undefined reference to `virConnCopyLastError'
/home/wyssen/school/Dropbox/virtualPOPC-1/NEW/vpopcwrapper/ESXWrapper.cpp:202: undefined reference to `virResetError'
collect2: ld returned 1 exit status
make: *** [all] Error 1
---

My makefile is the follwing:
---
#vars
CC=g++
OUTPUTFILE=ESXWrapper
O_FILES=ESXWrapper.o
FLAGS=-g -D debug=1


.PHONY: all
all: esxwrapper
$(CC) $(FLAGS) -o $(OUTPUTFILE) $(O_FILES)

esxwrapper: ESXWrapper.cpp VPopCWrapper.h
$(CC) $(FLAGS) -c -llibvirt ESXWrapper.cpp


.PHONY: run
run: all
./bignum


.PHONY: clean
clean:
rm -f $(O_FILES)

.PHONY: clean_all
clean_all: clean
rm -f $(OUTPUTFILE)
---

Can anybody give me a hint, how to link correctly to libvirt. And also tell me, if there are special functions to use with C++, other than the examples provided in the source code, which are written in C.

Thank you
Adrian

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]