c++ - 无法编译 Hello Web 服务客户端

标签 c++ linux wso2

为了熟悉使用 WSF/C++ 框架的 RESTful Web 服务定义(服务器和客户端),我决定遵循快速入门指南(参见 http://wso2.org/project/wsf/cpp/2.0.0/docs/)。我已经成功地从源代码和 hello 服务器编译并安装了框架。 问题是当我尝试编译 hello 客户端时。

请在下面找到 c++ 代码 (hello_cli.cpp) 和编译输出。

#include <stdio.h>
#include <ServiceClient.h>
#include <OMElement.h>
#include <iostream>
#include <WSFault.h> /*I have replaced AxisFault.h by this file since the AxisFault does not exist anymore*/
#include <Environment.h>

using namespace std;
using namespace wso2wsf;

int main(int argc, char *argv[])
{
    Environment::initialize("hello.log", AXIS2_LOG_LEVEL_TRACE);

    string end_point = "http://localhost:9090/axis2/services/hello";

    ServiceClient sc(end_point);

    OMElement * payload = new OMElement("greet"); 
    payload->setText("Test service!");
    try
    {
           OMElement* response = sc.request(payload, "");
            if (response)
            {
                cout << endl << "Response: " << response << endl;
            }
        }
        catch (AxisFault & e)
        {
            if (sc.getLastSOAPFault())
            {
                cout << endl << "Fault: " << sc.getLastSOAPFault() << endl;
            }
            else
            {
                cout << endl << "Error: " << e << endl;
            }
        }
        delete payload;
    }

使用给定的编译命令行:

gcc -o hello_cli -I$WSFCPP_HOME/include/axis2-1.6.0/ -L$WSFCPP_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -laxis2_engine -lpthread -laxis2_http_sender -laxis2_http_receiver -lwso2_wsf hello_cli.cpp -ldl -Wl,--rpath -Wl,$WSFCPP_HOME/lib

我遇到了这个错误:

hello_cli.cpp:19:27: fatal error: ServiceClient.h : No such file or directory

为了解决这个问题,我还包含了 ServiceClient 所在的目录:

gcc -o hello_cli -I$WSFCPP_HOME/include/ -I$WSFCPP_HOME/include/axis2-1.6.0/ -L$WSFCPP_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -laxis2_engine -lpthread -laxis2_http_sender -laxis2_http_receiver -lwso2_wsf --verbose hello_cli.cpp -ldl -Wl,--rpath -Wl,$WSFCPP_HOME/lib

这会导致以下错误(我只是提供一个示例):

    hello_cli.cpp:(.text+0x23): undefined reference to `std::allocator<char>::allocator()'
hello_cli.cpp:(.text+0x3b): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
hello_cli.cpp:(.text+0x4f): undefined reference to `wso2wsf::Environment::initialize(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, axutil_log_levels)'
hello_cli.cpp:(.text+0x5e): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
hello_cli.cpp:(.text+0x6a): undefined reference to `std::allocator<char>::~allocator()'
hello_cli.cpp:(.text+0x76): undefined reference to `std::allocator<char>::allocator()'

通过使用 g++ 而不是 gcc(这看起来很自然,因为我正在操作 C++ 对象)我得到了以下结果。

命令行:

g++ -o hello_cli -I$WSFCPP_HOME/include/ -I$WSFCPP_HOME/include/axis2-1.6.0/ -L$WSFCPP_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -laxis2_engine -lpthread -laxis2_http_sender -laxis2_http_receiver -lwso2_wsf --verbose hello_cli.cpp -ldl -Wl,--rpath -Wl,$WSFCPP_HOME/lib

输出:

/tmp/cccyHkNn.o: In function `main':

hello_cli.cpp:(.text+0x4f): 未定义对 wso2wsf::Environment::initialize(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, axutil_log_levels)' hello_cli.cpp:(.text+0xc0): undefined reference to 的引用wso2wsf::ServiceClient::ServiceClient(std::basic_string, std::allocator >)' hello_cli.cpp:(.text+0x109): 未定义对 wso2wsf::OMElement::OMElement(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' hello_cli.cpp:(.text+0x159): undefined reference to 的引用wso2wsf::OMElement::setText(std::basic_string, std::allocator >)' hello_cli.cpp:(.text+0x1ac): 未定义对 wso2wsf::ServiceClient::request(wso2wsf::OMElement*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' hello_cli.cpp:(.text+0x234): undefined reference to 的引用wso2wsf::ServiceClient::~ServiceClient()' hello_cli.cpp:(.text+0x36b): 未定义对 wso2wsf::ServiceClient::getLastSOAPFault()' hello_cli.cpp:(.text+0x384): undefined reference to 的引用wso2wsf::ServiceClient::getLastSOAPFault()' hello_cli.cpp:(.text+0x411): 未定义对 wso2wsf::ServiceClient::~ServiceClient()' /tmp/cccyHkNn.o:(.gcc_except_table+0xc4): undefined reference to 的引用wso2wsf::WSFault' 的类型信息

我的操作系统是 Ubuntu 12.04.1 LTS(64 位),g++ 版本是 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

最佳答案

由于 Mat 的评论,问题已解决

Use only g++ to compile and link C++, and put your libraries (-lfoo) after your source and object files

关于c++ - 无法编译 Hello Web 服务客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13699535/

相关文章:

css - WSO2 碳 : Re-Theming a single page

c++ - sse类型: Segmentation Fault的数组

c++ - 如何将 C++17 stdc++fs 库链接到混合语言(C++ 和 Fortran)CMake 项目?

regex - sed 正则表达式地址范围

tomcat - 如何将 CARBON_HOME 系统属性设置为创建的 'carbon_repo' 目录,

java - WSO2 身份服务器 - Carbon 无法执行 Java

c++ - 使用 Visual Studio-commander 配置 Qt 4.7.3 失败(返回 #2)

c++ - 将 CPen 绑定(bind)到列表框

Linux 内核模块 ABI (x86)

linux - 如何在 Ubuntu 20.04 中安装 Git