Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile the Hello web service client

Tags:

c++

linux

wso2

In order to get familiar with restful web service definition (both server and client) using the WSF/C++ framework, I have decided to follow the quick start guide (see http://wso2.org/project/wsf/cpp/2.0.0/docs/). I have successfully compile and install the framework from sources and the hello server as well. The problem is when I try to compile the hello client.

Please find below the c++ code (hello_cli.cpp) and the compilation output.

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

Using the given compilation command line:

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

I got this error:

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

To fix this issue I have also included the directory where ServiceClient is located:

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

This leads to the following errors (I just provide a sample):

    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()'

By using g++ instead of gcc (it seems natural since I am manipulating C++ objects) I got the following.

Command line:

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

Output:

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

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+0xc0): undefined reference towso2wsf::ServiceClient::ServiceClient(std::basic_string, std::allocator >)' hello_cli.cpp:(.text+0x109): undefined reference to wso2wsf::OMElement::OMElement(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' hello_cli.cpp:(.text+0x159): undefined reference towso2wsf::OMElement::setText(std::basic_string, std::allocator >)' hello_cli.cpp:(.text+0x1ac): undefined reference to wso2wsf::ServiceClient::request(wso2wsf::OMElement*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' hello_cli.cpp:(.text+0x234): undefined reference towso2wsf::ServiceClient::~ServiceClient()' hello_cli.cpp:(.text+0x36b): undefined reference to wso2wsf::ServiceClient::getLastSOAPFault()' hello_cli.cpp:(.text+0x384): undefined reference towso2wsf::ServiceClient::getLastSOAPFault()' hello_cli.cpp:(.text+0x411): undefined reference to wso2wsf::ServiceClient::~ServiceClient()' /tmp/cccyHkNn.o:(.gcc_except_table+0xc4): undefined reference totypeinfo for wso2wsf::WSFault'

My OS is Ubuntu 12.04.1 LTS (64bits) and g++ version is 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

like image 753
Yoann Pitarch Avatar asked Mar 17 '26 03:03

Yoann Pitarch


1 Answers

The issue is fixed thanks to Mat's comment

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

like image 193
Yoann Pitarch Avatar answered Mar 19 '26 02:03

Yoann Pitarch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!