编译gSOAP客户端时未定义的引用

时间:2012-05-26 10:25:47

标签: c gsoap

我正在尝试在C中为Web服务创建客户端。我使用wsdl2h和soapcpp2生成了C文件。在netbeans中,我添加了生成的文件,gSOAP将dir添加到项目的include目录中。 我的主文件如下所示:

#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);
}

我从gSOAP网站的入门部分复制了大部分内容。 当我尝试编译时,我得到以下错误:

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'

如果我将“soapC.c”“soapClient.c”“soapClientLib.c”文件添加到项目中,我会得到一堆更多未完成的引用。 我究竟做错了什么?我在Win7上使用Netbeans ide和MinGW编译器。我需要哪些其他库或我应该包含哪些其他文件?

2 个答案:

答案 0 :(得分:1)

您需要链接到适当的库。您需要使用-l开关添加相应的库,您可以选择通过-L将路径传递到这些库所在的位置。另请注意,以++结尾的库通常是您在使用C ++时应该使用的库。所以,你的命令行应至少包括:

对于C:

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

对于C ++:

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

此外,根据您是否使用其他功能(如SSL,Cookie等),您还需要链接这些库:

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

如果您使用的是其他工具链,请查找确切开关的文档。

答案 1 :(得分:1)

我设法通过将文件“soapC.c”“soapClient.c”“stdsoap.c”添加到项目文件和项目属性中来解决问题 - 包含目录添加soapcpp2和gSOAP工具包生成的文件gsoap目录

相关问题