compiling gsoap sample hello service - c++

i downloaded gsoap 2.8.14, configure and install with the following commands:
./configure --disable-ssl --enable-samples --enable-debug
make
make install
im tried to compile gsoap sample "hello". so i took the the wsdl file from the sample and did the following:
wsdl2h -s -o hello.h h.wsdl
soapcpp2 hello.h
i copied the generated files into a new eclipse c++ project and excluded soapClientLib.cpp and soapServerLib.cpp because i was receiving errors like
multiple definition of .....
i then created a helloserver.cpp and here is the content:
#include "soapH.h"
#include "Service.nsmap"
int main()
{
return soap_serve(soap_new);
}
int __ns1__hello(struct soap *soap, char* helloReq, char* &helloResponse)
{
return SOAP_OK;
}
when i build in eclipse, i receives an error:
...soapServer.cpp:77 undefined reference to __ns1__hello(soap*,_ns2_hello*, _ns__helloResponse*)
when i trace to soapServer.cpp, this line is getting the error:
soap->error=__ns1_hello(soap,soap_tmp___ns1_hello.ns2__hello,&ns2__helloResponse);
why am i getting this error? im using the sample hello wsdl from gsoap

Well as you can see from the error message (and the soapServer.cpp code) you are supposed to write a function
int __ns1__hello(struct soap *soap,
_ns2_hello* helloReq,
_ns__helloResponse* helloResponse)
{
return SOAP_OK;
}
not the function you wrote.

Related

Microsoft Visual Studio Code doesn't do anything when running an executable

I wanted to create a simple local web server using this library.
So, I created a new project in Visual Studio, created main.cpp and type in this code into my main.cpp.
#include "httplib.h"
using namespace httplib;
int main(void) {
Server svr;
svr.Get("/hi", [](const Request & /*req*/, Response &res) {
res.set_content("Hello World!", "text/plain");
});
svr.listen("localhost", 8080);
}
And I also created httplib.h and copied this code into my httplib.h.
I ran it. A blank terminal pop-up, then I go to localhost:8080/hi via Google Chrome and it works. There's "Hello World" output in there.
Then, I do the same thing with Visual Studio Code. But when I compile it, there's an error says
/usr/bin/ld: /tmp/ccUgoSsW.o: in function
'std::thread::thread<httplib::ThreadPool::worker, ,
void>(httplib::ThreadPool::worker&&)':
/usr/include/c++/9/thread:126:
undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
I searched a bit and found a solution. So, I compile it manually using Visual Studio Code terminal by typing "g++ main.cpp -o demo -pthread" and it compiled successfully. But, then I try to run the demo via terminal "./demo" it just doesn't do anything. I try to connect to localhost:8080/hi via Google Chrome but it said This site can’t be reached.
How to reproduce my problem
1- Create a folder
2- Create a main.cpp in that folder and type in this code into it
#include "httplib.h"
using namespace httplib;
int main(void) {
Server svr;
svr.Get("/hi", [](const Request & /*req*/, Response &res) {
res.set_content("Hello World!", "text/plain");
});
svr.listen("localhost", 8080);
}
3- Create a httplib.h file into the folder and copy this code into it
4- Compile it via Visual Studio Code terminal by using this command "g++ main.cpp -o demo -pthread"
5- Run the build via terminal by using this command "./demo"
6- Go to Google Chrome and type this address "localhost:8080/hi" If it can't be accessed then that's my problem
ps: I'm using WSL2 Ubuntu 20.04

Compiling without "-L /usr/local/lib" yields a "cannot connect to socket" error while trying out jaeger opentracing in C++

I'm trying out OpenTracing Jaeger and have the following file test.cpp:
#include <opentracing/tracer.h>
#include <jaegertracing/Tracer.h>
#include <yaml-cpp/yaml.h>
#include <iostream>
void setUpTracer(const char* configFilePath)
{
auto configYAML = YAML::LoadFile(configFilePath);
auto config = jaegertracing::Config::parse(configYAML);
auto tracer = jaegertracing::Tracer::make(
"example-service", config, jaegertracing::logging::consoleLogger());
opentracing::Tracer::InitGlobal(
std::static_pointer_cast<opentracing::Tracer>(tracer));
}
int main(int argc, char* argv[]){
setUpTracer(argv[1]);
std::cout<<"Hello\n";
return 0;
}
And consider config.yml to be:
disabled: false
reporter:
logSpans: true
sampler:
type: const
param: 1
Now if I compile test.cpp with g++ test.cpp -lopentracing -ljaegertracing -lyaml-cpp and run ./a.out config.yml, I get a
ERROR: cannot connect to socket: Cannot connect socket to remote address { scheme="http", host="127.0.0.1", port=5778, path="/sampling", query="" }
While if I compile with g++ test.cpp -L /usr/local/lib -lopentracing -ljaegertracing -lyaml-cpp, I get a good
INFO: Initializing logging reporter
Hello
The contents of my /usr/local/lib are:
cmake libopentracing.so.1.6.0 libthriftqt.so
libjaegertracing.a libthrift-0.11.0.so libthrift.so
libjaegertracing.so libthrift.a libthriftz-0.11.0.so
libjaegertracing.so.0 libthrift_c_glib.a libthriftz.a
libjaegertracing.so.0.6.0 libthrift_c_glib.la libthriftz.la
libopentracing.a libthrift_c_glib.so libthriftz.so
libopentracing_mocktracer.a libthrift_c_glib.so.0 libyaml-cpp.a
libopentracing_mocktracer.so libthrift_c_glib.so.0.0.0 pkgconfig
libopentracing_mocktracer.so.1 libthrift.la python2.7
libopentracing_mocktracer.so.1.6.0 libthriftqt-0.11.0.so python3.6
libopentracing.so libthriftqt.a
libopentracing.so.1 libthriftqt.la
I'm using Jaeger in conjunction with a larger project involving ROS and get the same error even if I add_compile_options(-L /usr/local/lib) for CMakeLists.txt of the appropriate package; so, I wanted to better understand what the exact cause of the above error is, so hopefully that helps me to fix the one involved in ROS.
Thanks!
You are missing the configuration of Jaeger address. Since you did not provided it, it is trying to connect to the default one, which is TCP protocol, 127.0.0.1 and port 5778.
Check for details the configuration section here.

How to use available libraries from within mbed-os?

I have pulled down a fresh copy of mbed-os by using the mbed-cli tool.
$ mbed new mbed-os-test
[mbed] Creating new program "mbed-os-test" (git)
[mbed] Adding library "mbed-os" from "https://github.com/ARMmbed/mbed-os" at latest revision in the current branch
[mbed] Updating reference "mbed-os" -> "https://github.com/ARMmbed/mbed-os/#dda7f7d77abd4330b05e686ce3bbe58230eb7876"
Ultimately I am working to enable uVisor on my NXP FRDM-K64F device, but for now I am only using the QuickStart tutorial to get a simple example working without enabling the uVisor.
So, as suggested in the link above, I make a source directory in the newly created clone of mbed-os:
$ mkdir mbed-os-test/mbed-os/source
I copy in the basic main.cpp and compile. It works. However, when I try and create a problem using some of the library routines -- specifically EthernetInterface.
Replacing my simple main.cpp from the uVisor example with the more complicated one (using EthernetInterface) from the above link:
#include "mbed.h"
#include "EthernetInterface.h"
int main() {
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("IP Address is %s\n", eth.getIPAddress());
TCPSocketConnection sock;
sock.connect("mbed.org", 80);
char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
sock.send_all(http_cmd, sizeof(http_cmd)-1);
char buffer[300];
int ret;
while (true) {
ret = sock.receive(buffer, sizeof(buffer)-1);
if (ret <= 0)
break;
buffer[ret] = '\0';
printf("Received %d chars from server:\n%s\n", ret, buffer);
}
sock.close();
eth.disconnect();
while(1) {}
}
Compiling with:
mbed compile -m K64F -t GCC_ARM
I am met with compilation errors stating that the EthernetInterface class does not have members that I am trying to invoke.
../../mbed-os/source/main.cpp: In function 'int main()':
../../mbed-os/source/main.cpp:34:9: error: 'class EthernetInterface' has no member named 'init'
eth.init(); //Use DHCP
^
../../mbed-os/source/main.cpp:36:38: error: 'class EthernetInterface' has no member named 'getIPAddress'
printf("IP Address is %s\n", eth.getIPAddress());
^
../../mbed-os/source/main.cpp:38:5: error: 'TCPSocketConnection' was not declared in this scope
TCPSocketConnection sock;
^
../../mbed-os/source/main.cpp:39:5: error: 'sock' was not declared in this scope
sock.connect("mbed.org", 80);
^
When, of course, the EthernetInterface class does have such members. I think the problem is related to the mbed utilities not compiling against the correct source code because it seems to find the header. If I add a --source= option to the mbed compilation I am met with other errors regarding things that EthernetInterface.cpp includes.
mbed compile -m K64F -t GCC_ARM --source=../libraries/net/eth/EthernetInterface/
[ERROR] In file included from ../libraries/net/eth/EthernetInterface/EthernetInterface.cpp:19:0:
../libraries/net/eth/EthernetInterface/EthernetInterface.h:27:18: fatal error: rtos.h: No such file or directory
The files are certainly contained with mbed-os, I am just not sure how to actually use them.
$ find . -name EthernetInterface.cpp
./libraries/net/eth/EthernetInterface/EthernetInterface.cpp
./features/net/FEATURE_IPV4/lwip-interface/EthernetInterface.cpp
tl;dr -- How can we link against the library code given at libraries/? I can directly include the header files by directly including the file, but the corresponding source appears to be that located in the features/ directory rather than the one in libraries/.
I'm wondering what you're doing that I'm missing, because this works for me:
$ mbed new ethernet-test
$ cd ethernet-test
$ mbed target K64F
$ mbed toolchain GCC_ARM
Open ethernet-test/main.cpp and put in:
#include "mbed.h"
#include "EthernetInterface.h"
int main(int, char**) {
EthernetInterface eth;
eth.connect();
}
Then:
$ mbed compile
...
Total Flash memory (text + data + misc): 108092 bytes
Image: ./.build/K64F/GCC_ARM/ethernet-test.bin

C++ compiles but gives error when executed

I am new to Linux Ubuntu 11.10 and have basic C++exposure.
I installed the g++ by
sudo apt-get install build-essential
and created a directory cpp in my home directory. I then wrote a program hello.cpp in my cpp directory
#include <iostream>
using namespace std;
int main() {
cout << "Hello !" ; return 0;
}
and compiled using
g++ -W hello.cpp -o hello
The program compiles without any errors/warnings. When I try to execute the file
./hello.cpp
I get error messages:
line 3: using: command not found
line 6: syntax error near unexpected token `('
line 6: `int main() {'
I tried looking at a lot of posts but could not resolve this. I have MS VisualStudio on Windows, but I would rather learn C++ on Ubuntu. Thanks in advance.
I think that the problem is that you're trying to execute the .cpp source file rather than the generated executable. Try running ./hello instead of ./hello.cpp, since hello is the actual executable. The errors you're currently getting are caused by the shell interpreter choking on C++ syntax, since it's trying to run it as a shell script.
Hope this helps!

Trying to get fastcgi to work in nginx and c++

Below is my c++ code and my config file.
when I run spawn-fcgi -a120.0.0.1 -p9000 -n ./rtb.o
I get this error
spawn-fcgi: exec failed: Exec format error
Here is my c++ code that I complied as rtb.o
#include "fcgi_stdio.h"
#include <stdlib.h>
using namespace std;
int main()
{
int count = 1;
while(FCGI_Accept() >= 0)
printf("Content-type: text/html\r\n"
"\r\n"
"<title>FastCGI Hello!</title>"
"<h1>FastCGI Hello!</h1>"
"Request number %d running on host \n",
++count);
return 0;
}
So, what did I do wrong?
You're attempting to run a program called rtb.o? Is this an object file or an executable? You might want to show us how you compile your program. If you're doing something like
g++ -c rtb.cpp
Then you will get an object file and you need to link it to get a working program. Try to run it from your terminal using ./rtb.o. If it prints the same message, then you've got an object file and need to try something like this instead:
g++ -o rtb rtb.cpp
Remember to add a reference to the FCGI library when you link (use the -l option).