Coder Social home page Coder Social logo

Comments (12)

jeffvandyke avatar jeffvandyke commented on August 15, 2024 4

Solved... Would anyone else have guessed that -lnet had to come after the name of the source file? Didn't know that, but I tested a bit and that seems to be the case.

Final command: g++ demo.cpp -lnet -std=c++11 -o demo

Also, for a cmake build, the above command is accomplished by adding target_link_libraries(demo net), again AFTER add_executable(demo demo.cpp).

from pistache.

oktal avatar oktal commented on August 15, 2024

Hello,

If you look carefully at the compile error, you'll see that you triggered a static assertion:

/usr/local/include/pistache/http.h:758:5: error: static assertion failed: An http handler must be an http prototype, did you forget the HTTP_PROTOTYPE macro ?

You have to use the HTTP_PROTOTYPE macro in your Handler:

struct HelloHandler : public Http::Handler {

    HTTP_PROTOTYPE(HelloHandler)

    void onRequest(const Http::Request& request, Http::ResponseWriter writer) {
                writer.send(Http::Code::Ok, "Hello, World!");

    }

};

I'll update the README

from pistache.

xens avatar xens commented on August 15, 2024

Thanks, I'm going further but here's the next issue:

gcc -std=c++11 hello.cc
/tmp/ccVAa4xI.o: In function `main':
hello.cc:(.text+0x13d): undefined reference to `Net::Address::Address(char const*)'
/tmp/ccVAa4xI.o: In function `__static_initialization_and_destruction_0(int, int)':
hello.cc:(.text+0x1b8): undefined reference to `std::ios_base::Init::Init()'
hello.cc:(.text+0x1c7): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccVAa4xI.o: In function `Async::PromiseBase::~PromiseBase()':
hello.cc:(.text._ZN5Async11PromiseBaseD2Ev[_ZN5Async11PromiseBaseD5Ev]+0x29): undefined reference to `operator delete(void*)'
/tmp/ccVAa4xI.o: In function `Async::PromiseBase::~PromiseBase()':
hello.cc:(.text._ZN5Async11PromiseBaseD0Ev[_ZN5Async11PromiseBaseD5Ev]+0x20): undefined reference to `operator delete(void*)'
/tmp/ccVAa4xI.o: In function `Net::Http::Mime::MediaType::MediaType()':
hello.cc:(.text._ZN3Net4Http4Mime9MediaTypeC2Ev[_ZN3Net4Http4Mime9MediaTypeC5Ev]+0x38): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
/tmp/ccVAa4xI.o: In function `Net::Http::Header::Header::~Header()':
hello.cc:(.text._ZN3Net4Http6Header6HeaderD2Ev[_ZN3Net4Http6Header6HeaderD5Ev]+0xd): undefined reference to `vtable for Net::Http::Header::Header'
hello.cc:(.text._ZN3Net4Http6Header6HeaderD2Ev[_ZN3Net4Http6Header6HeaderD5Ev]+0x29): undefined reference to `operator delete(void*)'
/tmp/ccVAa4xI.o: In function `Net::Http::Header::Header::~Header()':
hello.cc:(.text._ZN3Net4Http6Header6HeaderD0Ev[_ZN3Net4Http6Header6HeaderD5Ev]+0x20): undefined reference to `operator delete(void*)'
/tmp/ccVAa4xI.o: In function `Net::Http::Header::Header::Header()':

from pistache.

oktal avatar oktal commented on August 15, 2024

You should:

1/ Compile with g++, not gcc.
2/ Make sure to link with -lnet

from pistache.

xens avatar xens commented on August 15, 2024

I'm certainly missing something, still got errors with g++

g++ -lnet -std=c++11 hello.cc
/tmp/ccxhJsLk.o: In function `main':
hello.cc:(.text+0x13d): undefined reference to `Net::Address::Address(char const*)'
/tmp/ccxhJsLk.o: In function `Net::Http::Header::Header::~Header()':
hello.cc:(.text._ZN3Net4Http6Header6HeaderD2Ev[_ZN3Net4Http6Header6HeaderD5Ev]+0xd): undefined reference to `vtable for Net::Http::Header::Header'
/tmp/ccxhJsLk.o: In function `Net::Http::Header::Header::Header()':
hello.cc:(.text._ZN3Net4Http6Header6HeaderC2Ev[_ZN3Net4Http6Header6HeaderC5Ev]+0x9): undefined reference to `vtable for Net::Http::Header::Header'
/tmp/ccxhJsLk.o: In function `Net::Http::Header::ContentType::ContentType(Net::Http::Mime::MediaType const&)':
hello.cc:(.text._ZN3Net4Http6Header11ContentTypeC2ERKNS0_4Mime9MediaTypeE[_ZN3Net4Http6Header11ContentTypeC5ERKNS0_4Mime9MediaTypeE]+0x1e): undefined reference to `vtable for Net::Http::Header::ContentType'

from pistache.

oktal avatar oktal commented on August 15, 2024

How did you build and install Pistache ?

from pistache.

xens avatar xens commented on August 15, 2024

I followed this guide: http://pistache.io/quickstart#installing-pistache

from pistache.

jlesech avatar jlesech commented on August 15, 2024

I've had the same issue. I had to execute the ldconfig command as root.

from pistache.

jeffvandyke avatar jeffvandyke commented on August 15, 2024

Similar errors for me, even after ldconfig. However, the guide to compile the sources also compiles the examples, and there's a working binary of http_server under pistache/build/examples. Some more investigation needed...

from pistache.

xens avatar xens commented on August 15, 2024

same issue as @jeffvandyke running ldconfig doesn't help

from pistache.

dynahcatq avatar dynahcatq commented on August 15, 2024

same issue here. ldconfig helps but after executing my binary it throws:

terminate called after throwing an instance of 'std::invalid_argument'
  what():  Invalid address
Aborted (core dumped)

any luck?
command to build: sudo g++ test.cpp -o test -std=c++11

UPDATE
Sorry, it's my fault. So I googled the error and I found the reason on StackOverflow: "it means you are giving bad input for what()"

So I look in my code and found out I had a typo at Http::listenAndServe <HelloHandler> ("*:6666");, which I accidentally wrote Http::listenAndServe <HelloHandler> ("*.6666");

Now my code is running like charm, I'm using ubuntu 16.04 LTS on parallel desktop on my Mbp2013

from pistache.

xens avatar xens commented on August 15, 2024

@jeffvandyke t-h-a-n-k-y-o-u ! Working as expected with -lnet after the source

from pistache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.