A rather dull worKLOG. This is just a scratchpad for solutions to IT problems that might be useful to someone else. Expect no opinions, no brilliant insights and definitely no pictures of pets or children. Expect stack traces, code snippets and other hints for the Google Indexer.

Monday, November 06, 2006

xml-rpc from C++ on Windows pt I

As part of the Plastic http://plastic.sourceforge.net project I'm
looking at making xml-rpc calls from different languages. Current focus
is on C/C++ since it opens up the possibility of using SWIG to get
Plastic access from a large range of other languages "for free".

My setup:
OS: Windows XP
IDE: Eclipse, with the CDT plugin
Tools: g++ and make, as part of the MinGW and MSYS systems

The most promising xml-rpc library is this one:
http://xmlrpcpp.sourceforge.net/links.html. Promising because a) I've
got it working before b) It has no dependencies c) It does client and
server (necessary for a fully-fledged plastic application).

Steps
1) Download and install the xml-rpc library files into a suitable folder.
2) Add this folder to the list of source folders in project
properties/c++ build/Tool settings/compiler/directories
3) Add the _WINDOWS flag to the compiler/preprocessor
If you hit build now, you'll get linker errors as listed below. The
problem is that although you get the winsock header files included on
the path automatically, you need to explicitly specify the corresponding
library to the linker. The library in question is probably called
something like: libws2_32.a and can be found in the MinGW/lib folder.
4) project properties/c++ build/Tool settings/linker/libraries/ add
library ..... and here's the real doozy....you add ws2_32 (!!!not!!!
libws2_32.a .... the linker prepends the lib and adds the .a for you).

Hit build, and you're away. All the above assumes that you have already
written your xml-rpc client of course....

=================================================================
The linker errors (for google's benefit):
E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:45:
undefined reference to `WSAStartup@8'
./xmlrpc/XmlRpcSocket.o(.text+0x5d): In function
`ZN6XmlRpc12XmlRpcSocket6socketEv':
E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:80:
undefined reference to `socket@12'
./xmlrpc/XmlRpcSocket.o(.text+0x8e): In function
`ZN6XmlRpc12XmlRpcSocket5closeEi':
E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:89:
undefined reference to `closesocket@4'
./xmlrpc/XmlRpcSocket.o(.text+0xbc): In function
`ZN6XmlRpc12XmlRpcSocket14setNonBlockingEi':
E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:103:
undefined reference to `ioctlsocket@12'
./xmlrpc/XmlRpcSocket.o(.text+0x10b): In function
`ZN6XmlRpc12XmlRpcSocket12setReuseAddrEi':
E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:115:
undefined reference to `setsockopt@20'
./xmlrpc/XmlRpcSocket.o(.text+0x157): In function
`ZN6XmlRpc12XmlRpcSocket4bindEii':
E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:126:
undefined reference to `htonl@4'
./xmlrpc/XmlRpcSocket.o(.text+0x16b):E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:127:
undefined reference to `htons@4'
./xmlrpc/XmlRpcSocket.o(.text+0x18c):E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:128:
undefined reference to `bind@12'
./xmlrpc/XmlRpcSocket.o(.text+0x1bc): In function
`ZN6XmlRpc12XmlRpcSocket6listenEii':
E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:136:
undefined reference to `listen@8'
./xmlrpc/XmlRpcSocket.o(.text+0x1fa): In function
`ZN6XmlRpc12XmlRpcSocket6acceptEi':
E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:151:
undefined reference to `accept@12'
./xmlrpc/XmlRpcSocket.o(.text+0x23a): In function
`ZN6XmlRpc12XmlRpcSocket7connectEiRSsi':
E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:164:
undefined reference to `gethostbyname@4'
./xmlrpc/XmlRpcSocket.o(.text+0x290):E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:169:
undefined reference to `htons@4'
./xmlrpc/XmlRpcSocket.o(.text+0x2b1):E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:173:
undefined reference to `connect@12'
./xmlrpc/XmlRpcSocket.o(.text+0x383): In function
`ZN6XmlRpc12XmlRpcSocket6nbReadEiRSsPb':
E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:191:
undefined reference to `recv@16'
./xmlrpc/XmlRpcSocket.o(.text+0x49e): In function
`ZN6XmlRpc12XmlRpcSocket7nbWriteEiRSsPi':
E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:223:
undefined reference to `send@16'
./xmlrpc/XmlRpcSocket.o(.text+0x517): In function
`ZN6XmlRpc12XmlRpcSocket8getErrorEv':
E:/jdt/data/experiments/PlasticListener2/Debug/../xmlrpc/XmlRpcSocket.cpp:248:
undefined reference to `WSAGetLastError@0'

--
------------------------------------------------------------------------
AstroGrid/VOTech
&
WFAU, Institute for Astronomy, Edinburgh
Skype:johndavidtaylor <skype:johndavidtaylor?chat>

------------------------------------------------------------------------
*Gratuitous advertising:*
Plastic - http://plastic.sourceforge.net | AstroRuntime -
http://www2.astrogrid.org/desktop
AstroGrid - http://www.astrogrid.org | WFAU -
http://www.roe.ac.uk/ifa/wfau/