我正在尝试编译并运行我的第一个gsoap ..但是在我的main()中,我收到undefined reference to
错误。我在网上搜索,很多解决方案都适用于Windows ..我在Linux(CentOS)中编程并使用Qt ..
我的.pro文件是:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp \
stdsoap2.cpp \
soapC.cpp \
soapClient.cpp
HEADERS += \
stdsoap2.h \
soapStub.h \
soapH.h \
soapCountryInfoServiceSoapBindingProxy.h
我没有提供libgsoap++.a
的链接,因为我已在项目中添加了stdsoap2
。
错误信息是:
/.1/Projects/calisma/soapCountries/main.cpp:47: error: undefined reference to `__ns1__ListOfLanguagesByCode(soap*, _i__ListOfLanguagesByCode*, _i__ListOfLanguagesByCodeResponse*)'
:-1: error: collect2: ld returned 1 exit status
这是我的main.cpp,我在行__ns1__ListOfLanguagesByCode(soap, code, result);
main.cpp:
#include <iostream>
#include "CountryInfoServiceSoapBinding.nsmap"
#include "soapCountryInfoServiceSoapBindingProxy.h"
int main()
{
CountryInfoServiceSoapBinding *countryObj;
struct soap *soap = soap_new();
countryObj = (CountryInfoServiceSoapBinding *)malloc(sizeof(CountryInfoServiceSoapBinding));
if(countryObj == NULL)
{
std::cout << "Cannot allocate memory for countryobj";
exit(EXIT_FAILURE);
}
_i__ListOfLanguagesByCode *code;
code = (_i__ListOfLanguagesByCode *)malloc(sizeof(_i__ListOfLanguagesByCode));
if(code == NULL)
{
std::cout << "Cannot Allocate Memory for code";
exit(EXIT_FAILURE);
}
_i__ListOfLanguagesByCodeResponse *result;
result = (_i__ListOfLanguagesByCodeResponse *)malloc(sizeof(_i__ListOfLanguagesByCodeResponse));
if(result == NULL)
{
std::cout << "Cannot Allocate Memory for result";
exit(EXIT_FAILURE);
}
code = (_i__ListOfLanguagesByCode *)("tur");
__ns1__ListOfLanguagesByCode(soap, code, result);
std::cout << "result = " << result << std::endl;
return 0;
}
我无法弄清楚我的错误在哪里,或者我错过了哪一部分。基本上我想给代码(在我的例子中是“tur”)并查看服务结果。
任何帮助将不胜感激。
编辑:这是项目中所有cpp和.h文件的列表..
mg@mg-CentOS soapCountries]$ ll
total 1408
-rw-rw-r-- 1 mg papilon 560 May 22 10:04 CountryInfoServiceSoapBinding.nsmap
-rw-rw-r-- 1 mg papilon 1220 May 22 13:00 main.cpp
-rw-rw-r-- 1 mg papilon 1135 May 22 13:21 main.cpp.autosave
-rw-rw-r-- 1 mg papilon 707557 May 22 10:04 soapC.cpp
-rw-rw-r-- 1 mg papilon 48024 May 22 10:04 soapClient.cpp
-rw-rw-r-- 1 mg papilon 373 May 22 10:04 soapClientLib.cpp
-rw-rw-r-- 1 mg papilon 252 May 22 12:58 soapCountries.pro
-rw-rw-r-- 1 mg papilon 17907 May 22 15:02 soapCountries.pro.user
-rw-rw-r-- 1 mg papilon 7148 May 22 12:01 soapCountryInfoServiceSoapBindingProxy.h
-rw-rw-r-- 1 mg papilon 151092 May 22 10:04 soapH.h
-rw-rw-r-- 1 mg papilon 39137 May 22 10:04 soapServer.cpp
-rw-rw-r-- 1 mg papilon 373 May 22 10:04 soapServerLib.cpp
-rw-rw-r-- 1 mg papilon 49034 May 22 10:04 soapStub.h
-rw-r--r-- 1 mg papilon 311882 Jun 6 2004 stdsoap2.cpp
-rw-r--r-- 1 mg papilon 56325 Jun 6 2004 stdsoap2.h
编辑2:
位于__ns1__ListOfLanguagesByCode
"soapCountryInfoServiceSoapBindingProxy.h"
的定义
virtual int __ns1__ListOfLanguagesByCode(_i__ListOfLanguagesByCode *i__ListOfLanguagesByCode, _i__ListOfLanguagesByCodeResponse *i__ListOfLanguagesByCodeResponse) { return soap ? soap_call___ns1__ListOfLanguagesByCode(soap, endpoint, NULL, i__ListOfLanguagesByCode, i__ListOfLanguagesByCodeResponse) : SOAP_EOM; }
答案 0 :(得分:0)
我认为在.pro文件中需要添加下一个字符串: LIBS + = -lgsoap