Description
In order to get my bearings in the sdk, I have created a simple pair of test programs. They do the following:
Speak | Listen |
---|---|
|
|
If I compile cpprestsdk according to your windows instructions and include the cpprestsdk libraries in my project, the test programs work, like so:
Listen (my project, in windows)
Press ENTER to exit. [no go run speak]
PUT /RESTtest/post HTTP/1.1
Connection: Keep-Alive
Content-Length: 25
Content-Type: application/json
Host: localhost:8080
User-Agent: cpprestsdk/2.8.0
{"string":"Hello World!"}
Speak (my project, in windows)
{"string":"Hello World!"}
status: OK
Press ENTER to exit.
However, when I build the same code on Linux, I get the following output instead:
Listen (my project, in linux)
matt@instance-4:~/HelloWorld-cpprestsdk/build$ ./helloworldlistener
Press ENTER to exit. [now go run speak]
Segmentation fault
Speak (my project, in linux)
matt@instance-4:~/HelloWorld-cpprestsdk/build$ ./helloworldspeaker
{"string":"Hello World!"}
terminate called after throwing an instance of 'web::http::http_exception'
what(): Failed to read HTTP status line
Aborted
If I try running everything as root, the Segmentation Fault
line does not appear, but everything is otherwise the same.
In order to narrow this down I tried forking your repo and added my test apps as samples. The samples were added in this commit, in case you'd like to look at the code.
When included in the same build as your other samples, I got this:
Listen (cpprestsdk sample, in linux)
Press ENTER to exit.
PUT /RESTtest HTTP/1.1
Connection: Keep-Alive
Content-Length: 25
Content-Type: application/json
Host: localhost:8080
User-Agent: cpprestsdk/2.8.0
Speak (cpprestsdk sample, in linux)
{"string":"Hello World!"}
status: OK
Press ENTER to exit.
No segmentation fault this time, which is good, but the content is missing from the listener output.
Conclusion
Since I can achieve error-free operation by building the test programs as part of my project on windows, and as a sample in your project on Linux, I suspect that there is something wrong with either:
- The way I am building cpprestsdk in linux
- The way I am linking to the result of that build
I made a copy of my project and gutted everything not necessary to run the test apps on both Windows and Linux. The behavior of the test programs in the copy is the same as the behavior of the original, so I don't think there were any conflicts with my other code. That copy contains scripts that build the REST sdk and set it up to be linked to. As far as I can tell, those scripts are in line with your documented build instructions.
My primary concern is this: When it comes to building cpprestsdk separately and then linking my project to it, what do I need to do to prevent the segmentation fault indicated above? I haven't looked as closely at the missing content problem, but once I have cpprestsdk linked to my project in a way that doesn't cause it to crash, my next endeavor will be gaining access to that data. Any thoughts about how to get at it would be appreciated as well.
Some ideas
One thing I notice is that the unix section of the CMakeLists.txt in your project does not specify a particular boost version, which means that it picks up Boost_1.60 which is in use in my project. Debian didn't have a libboost-1.54-all-dev
but I tried installing boost 1.54 from source and found that your project ran with Boost_1.60 anyhow.
I also notice that I need to specify -lboost_system
as a compiler flag in order to build the above project. I had considered forcing the cpprestsdk build to use boost 1.54, which is the version indicated by your linux directions, but then I wasn't sure whether that would invite conflicts into my project since other parts of it use a later version of boost.