Undefined references when compiling gSOAP client

Blackguard picture Blackguard · May 26, 2012 · Viewed 7.9k times · Source

I'm trying to create a client for a web service in C. I was generated C files with the wsdl2h and soapcpp2. In netbeans I'm added the generated files and the gSOAP include dir to the project's include directories. my main file looks like this:

#include <stdio.h> 
#include <stdlib.h>
#include <soapH.h>
#include <webserviceSoap12.nsmap>

int main(int argc, char** argv) {

    struct soap *soap1 = soap_new();
    struct _ns1__getAllCustomer *quote;
    struct _ns1__getAllCustomerResponse *quote2;
    if (soap_call___ns2__getAllCustomer(soap1, NULL, NULL, quote, quote2) == SOAP_OK)
        printf("asd\n");
    else // an error occurred  
        soap_print_fault(soap1, stderr); // display the SOAP fault on the stderr stream
    return (EXIT_SUCCESS);
}

I copied the most of this from the gSOAP website's getting started section. When I try to compile i get the following error:

build/Debug/MinGW-Windows/main.o: In function `main':
\NetBeansProjects\WebServiceClient/main.c:19: undefined reference to `soap_new_LIBRARY_VERSION_REQUIRED_20808'
\NetBeansProjects\WebServiceClient/main.c:22: undefined reference to `soap_call___ns2__getAllCustomer'
\NetBeansProjects\WebServiceClient/main.c:25: undefined reference to `soap_print_fault'

If I add the "soapC.c" "soapClient.c" "soapClientLib.c" files to the project I get a bunch of more undefinied reference. What am I doing wrong? I'm using Netbeans ide with MinGW compiler on Win7. What other libraries I need or what other files should I include?

Answer

dirkgently picture dirkgently · May 26, 2012

You will need to link in the proper libraries. You will need to add the appropriate libraries using the -l switch and you will optionally need to pass the path to where these libraries reside via -L. Also, note that the libraries ending with a ++ are typically the ones you should use if you're using C++. So, your command line shoulde include at least:

For C:

gcc ... -lgsoap -L/path/to/gsoap/binaries 

For C++:

g++ ... -lgsoap++ -L/path/to/gsoap/binaries 

Also, depending on whether you're using additional features such as SSL, cookies etc. you will need to link these libraries in too:

g++ ... -lgsoap++ -lgsoapssl++ -L/path/...

If you're using a different toolchain, lookup the documentation for the exact switches.