由于 link 错误,无法使用 Pistache.io 构建 C++ 程序
Can't build C++ program using Pistache.io due to link errors
我按照官方网站上的说明构建和安装Pistache.io。现在,我正在尝试从官方存储库构建这个示例程序:https://github.com/pistacheio/pistache/blob/master/examples/hello_server.cc
但是,即使我使用了 -lpistache
标志,我仍然收到以下错误:
g++ -Wall -Wextra -std=c++17 -lpistache hellopis.cpp -o hellopis
/usr/bin/ld: /tmp/ccuHXrLC.o: warning: relocation against `_ZTVN8Pistache3Tcp7HandlerE' in read-only section `.text._ZN8Pistache3Tcp7HandlerC2ERKS1_[_ZN8Pistache3Tcp7HandlerC5ERKS1_]'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `main':
hellopis.cpp:(.text+0x3b): undefined reference to `Pistache::Port::Port(unsigned short)'
/usr/bin/ld: hellopis.cpp:(.text+0x4a): undefined reference to `Pistache::IP::any()'
/usr/bin/ld: hellopis.cpp:(.text+0x9f): undefined reference to `Pistache::Address::Address(Pistache::IP, Pistache::Port)'
/usr/bin/ld: hellopis.cpp:(.text+0xb2): undefined reference to `Pistache::Http::Endpoint::options()'
/usr/bin/ld: hellopis.cpp:(.text+0xc6): undefined reference to `Pistache::Http::Endpoint::Options::threads(int)'
/usr/bin/ld: hellopis.cpp:(.text+0x103): undefined reference to `Pistache::Http::Endpoint::Endpoint(Pistache::Address const&)'
/usr/bin/ld: hellopis.cpp:(.text+0x11c): undefined reference to `Pistache::Http::Endpoint::init(Pistache::Http::Endpoint::Options const&)'
/usr/bin/ld: hellopis.cpp:(.text+0x151): undefined reference to `Pistache::Http::Endpoint::setHandler(std::shared_ptr<Pistache::Http::Handler> const&)'
/usr/bin/ld: hellopis.cpp:(.text+0x178): undefined reference to `Pistache::Http::Endpoint::serve()'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Http::Endpoint::~Endpoint()':
hellopis.cpp:(.text._ZN8Pistache4Http8EndpointD2Ev[_ZN8Pistache4Http8EndpointD5Ev]+0x3c): undefined reference to `Pistache::Tcp::Listener::~Listener()'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Async::Promise<long> Pistache::Http::ResponseWriter::send<13ul>(Pistache::Http::Code, char const (&) [13ul], Pistache::Http::Mime::MediaType const&)':
hellopis.cpp:(.text._ZN8Pistache4Http14ResponseWriter4sendILm13EEENS_5Async7PromiseIlEENS0_4CodeERAT__KcRKNS0_4Mime9MediaTypeE[_ZN8Pistache4Http14ResponseWriter4sendILm13EEENS_5Async7PromiseIlEENS0_4CodeERAT__KcRKNS0_4Mime9MediaTypeE]+0x3b): undefined reference to `Pistache::Http::ResponseWriter::sendImpl(Pistache::Http::Code, char const*, unsigned long, Pistache::Http::Mime::MediaType const&)'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Tcp::Handler::Handler(Pistache::Tcp::Handler const&)':
hellopis.cpp:(.text._ZN8Pistache3Tcp7HandlerC2ERKS1_[_ZN8Pistache3Tcp7HandlerC5ERKS1_]+0x26): undefined reference to `vtable for Pistache::Tcp::Handler'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Http::Handler::Handler(Pistache::Http::Handler const&)':
hellopis.cpp:(.text._ZN8Pistache4Http7HandlerC2ERKS1_[_ZN8Pistache4Http7HandlerC5ERKS1_]+0x26): undefined reference to `vtable for Pistache::Http::Handler'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Http::Handler::~Handler()':
hellopis.cpp:(.text._ZN8Pistache4Http7HandlerD2Ev[_ZN8Pistache4Http7HandlerD5Ev]+0xf): undefined reference to `vtable for Pistache::Http::Handler'
/usr/bin/ld: hellopis.cpp:(.text._ZN8Pistache4Http7HandlerD2Ev[_ZN8Pistache4Http7HandlerD5Ev]+0x22): undefined reference to `Pistache::Tcp::Handler::~Handler()'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Http::Handler::Handler()':
hellopis.cpp:(.text._ZN8Pistache4Http7HandlerC2Ev[_ZN8Pistache4Http7HandlerC5Ev]+0x15): undefined reference to `Pistache::Tcp::Handler::Handler()'
/usr/bin/ld: hellopis.cpp:(.text._ZN8Pistache4Http7HandlerC2Ev[_ZN8Pistache4Http7HandlerC5Ev]+0x1c): undefined reference to `vtable for Pistache::Http::Handler'
/usr/bin/ld: hellopis.cpp:(.text._ZN8Pistache4Http7HandlerC2Ev[_ZN8Pistache4Http7HandlerC5Ev]+0x7b): undefined reference to `Pistache::Tcp::Handler::~Handler()'
/usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTV12HelloHandler[_ZTV12HelloHandler]+0x28): undefined reference to `Pistache::Http::Handler::onInput(char const*, unsigned long, std::shared_ptr<Pistache::Tcp::Peer> const&)'
/usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTV12HelloHandler[_ZTV12HelloHandler]+0x30): undefined reference to `Pistache::Http::Handler::onConnection(std::shared_ptr<Pistache::Tcp::Peer> const&)'
/usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTV12HelloHandler[_ZTV12HelloHandler]+0x38): undefined reference to `Pistache::Tcp::Handler::onDisconnection(std::shared_ptr<Pistache::Tcp::Peer> const&)'
/usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTV12HelloHandler[_ZTV12HelloHandler]+0x48): undefined reference to `Pistache::Http::Handler::onTimeout(Pistache::Http::Request const&, Pistache::Http::ResponseWriter)'
/usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTI12HelloHandler[_ZTI12HelloHandler]+0x10): undefined reference to `typeinfo for Pistache::Http::Handler'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [<builtin>: hellopis] Error 1
这是什么错误,我该如何解决?
当我在不使用 Makefile
的情况下自己调用 g++
命令时,问题已解决。特别是,我 运行 以下命令:g++ -Wall -Wextra -std=c++17 hellopis.cpp -o hellopis -lpistache
.
我的Makefile
如下:
CXXFLAGS=-Wall -Wextra -std=c++17
LDFLAGS=-lpistache
我按照官方网站上的说明构建和安装Pistache.io。现在,我正在尝试从官方存储库构建这个示例程序:https://github.com/pistacheio/pistache/blob/master/examples/hello_server.cc
但是,即使我使用了 -lpistache
标志,我仍然收到以下错误:
g++ -Wall -Wextra -std=c++17 -lpistache hellopis.cpp -o hellopis
/usr/bin/ld: /tmp/ccuHXrLC.o: warning: relocation against `_ZTVN8Pistache3Tcp7HandlerE' in read-only section `.text._ZN8Pistache3Tcp7HandlerC2ERKS1_[_ZN8Pistache3Tcp7HandlerC5ERKS1_]'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `main':
hellopis.cpp:(.text+0x3b): undefined reference to `Pistache::Port::Port(unsigned short)'
/usr/bin/ld: hellopis.cpp:(.text+0x4a): undefined reference to `Pistache::IP::any()'
/usr/bin/ld: hellopis.cpp:(.text+0x9f): undefined reference to `Pistache::Address::Address(Pistache::IP, Pistache::Port)'
/usr/bin/ld: hellopis.cpp:(.text+0xb2): undefined reference to `Pistache::Http::Endpoint::options()'
/usr/bin/ld: hellopis.cpp:(.text+0xc6): undefined reference to `Pistache::Http::Endpoint::Options::threads(int)'
/usr/bin/ld: hellopis.cpp:(.text+0x103): undefined reference to `Pistache::Http::Endpoint::Endpoint(Pistache::Address const&)'
/usr/bin/ld: hellopis.cpp:(.text+0x11c): undefined reference to `Pistache::Http::Endpoint::init(Pistache::Http::Endpoint::Options const&)'
/usr/bin/ld: hellopis.cpp:(.text+0x151): undefined reference to `Pistache::Http::Endpoint::setHandler(std::shared_ptr<Pistache::Http::Handler> const&)'
/usr/bin/ld: hellopis.cpp:(.text+0x178): undefined reference to `Pistache::Http::Endpoint::serve()'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Http::Endpoint::~Endpoint()':
hellopis.cpp:(.text._ZN8Pistache4Http8EndpointD2Ev[_ZN8Pistache4Http8EndpointD5Ev]+0x3c): undefined reference to `Pistache::Tcp::Listener::~Listener()'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Async::Promise<long> Pistache::Http::ResponseWriter::send<13ul>(Pistache::Http::Code, char const (&) [13ul], Pistache::Http::Mime::MediaType const&)':
hellopis.cpp:(.text._ZN8Pistache4Http14ResponseWriter4sendILm13EEENS_5Async7PromiseIlEENS0_4CodeERAT__KcRKNS0_4Mime9MediaTypeE[_ZN8Pistache4Http14ResponseWriter4sendILm13EEENS_5Async7PromiseIlEENS0_4CodeERAT__KcRKNS0_4Mime9MediaTypeE]+0x3b): undefined reference to `Pistache::Http::ResponseWriter::sendImpl(Pistache::Http::Code, char const*, unsigned long, Pistache::Http::Mime::MediaType const&)'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Tcp::Handler::Handler(Pistache::Tcp::Handler const&)':
hellopis.cpp:(.text._ZN8Pistache3Tcp7HandlerC2ERKS1_[_ZN8Pistache3Tcp7HandlerC5ERKS1_]+0x26): undefined reference to `vtable for Pistache::Tcp::Handler'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Http::Handler::Handler(Pistache::Http::Handler const&)':
hellopis.cpp:(.text._ZN8Pistache4Http7HandlerC2ERKS1_[_ZN8Pistache4Http7HandlerC5ERKS1_]+0x26): undefined reference to `vtable for Pistache::Http::Handler'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Http::Handler::~Handler()':
hellopis.cpp:(.text._ZN8Pistache4Http7HandlerD2Ev[_ZN8Pistache4Http7HandlerD5Ev]+0xf): undefined reference to `vtable for Pistache::Http::Handler'
/usr/bin/ld: hellopis.cpp:(.text._ZN8Pistache4Http7HandlerD2Ev[_ZN8Pistache4Http7HandlerD5Ev]+0x22): undefined reference to `Pistache::Tcp::Handler::~Handler()'
/usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Http::Handler::Handler()':
hellopis.cpp:(.text._ZN8Pistache4Http7HandlerC2Ev[_ZN8Pistache4Http7HandlerC5Ev]+0x15): undefined reference to `Pistache::Tcp::Handler::Handler()'
/usr/bin/ld: hellopis.cpp:(.text._ZN8Pistache4Http7HandlerC2Ev[_ZN8Pistache4Http7HandlerC5Ev]+0x1c): undefined reference to `vtable for Pistache::Http::Handler'
/usr/bin/ld: hellopis.cpp:(.text._ZN8Pistache4Http7HandlerC2Ev[_ZN8Pistache4Http7HandlerC5Ev]+0x7b): undefined reference to `Pistache::Tcp::Handler::~Handler()'
/usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTV12HelloHandler[_ZTV12HelloHandler]+0x28): undefined reference to `Pistache::Http::Handler::onInput(char const*, unsigned long, std::shared_ptr<Pistache::Tcp::Peer> const&)'
/usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTV12HelloHandler[_ZTV12HelloHandler]+0x30): undefined reference to `Pistache::Http::Handler::onConnection(std::shared_ptr<Pistache::Tcp::Peer> const&)'
/usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTV12HelloHandler[_ZTV12HelloHandler]+0x38): undefined reference to `Pistache::Tcp::Handler::onDisconnection(std::shared_ptr<Pistache::Tcp::Peer> const&)'
/usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTV12HelloHandler[_ZTV12HelloHandler]+0x48): undefined reference to `Pistache::Http::Handler::onTimeout(Pistache::Http::Request const&, Pistache::Http::ResponseWriter)'
/usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTI12HelloHandler[_ZTI12HelloHandler]+0x10): undefined reference to `typeinfo for Pistache::Http::Handler'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [<builtin>: hellopis] Error 1
这是什么错误,我该如何解决?
当我在不使用 Makefile
的情况下自己调用 g++
命令时,问题已解决。特别是,我 运行 以下命令:g++ -Wall -Wextra -std=c++17 hellopis.cpp -o hellopis -lpistache
.
我的Makefile
如下:
CXXFLAGS=-Wall -Wextra -std=c++17
LDFLAGS=-lpistache