1. 程式人生 > >win7下Qt Creator使用Gsoap

win7下Qt Creator使用Gsoap

1 獲取gsoap原始碼
解壓到相應目錄,得到D:\Codes\gsoap-2.8\

2 新增環境變數

set GSOAP=D:\Codes\gsoap-2.8\gsoap

set PATH=%PATH%;%GSOAP%\bin\win32
3 編譯
wsdl2h -c -I%GSOAP% -o calc.h http://www.genivia.com/calc.wsdl
soapcpp2 -cCL -I%GSOAP%\import calc.h
4 複製
建立Qt Creator 純C工程
並把上面編譯生成的下面檔案加入到工程
calc.nsmap
soapH.h
soapStub.h
soapC.c
soapClient.c
stdsoap2.c
stdsoap2.h
5 新增庫路徑

LIBS += \
C:\Qt\qtcreator-2.4.1\mingw\lib\libws2_32.a
在.pro檔案中加入上面的程式碼,意思是加入libws2_32.a的路徑
6 編輯程式碼
<span style="white-space:pre">	</span>#include "soapH.h"
	#include "calc.nsmap"
	
	int main(void)
	{
	    struct soap *soap = soap_new();
	    int exit_code = 0;
	    const double x = 1;
	    const double y = 2;
	    double result;
	
	    if (soap_call_ns2__add(soap, NULL, NULL, x, y, &result) == SOAP_OK) {
	        printf("The result:%lg", result);
	    } else {
	        soap_print_fault(soap, stderr);
	        exit_code = 1;
	    }
	
	    soap_end(soap);
	    soap_free(soap);
	
	    return exit_code;
	}


7 編譯執行
The result:3

成功