[BUG] hello_world: build failed
dancesWithCycles opened this issue · 2 comments
Hi folks,
Thank you so much for maintaining this repository. May I share the following issue with you?
Describe the issue
I am following the Hello World example.
To Reproduce
I build and installed the library like this
./bootstrap
mkdir build
cd build
../configure
make
sudo make install
make install replied like this.
sudo make install
Making install in src
make[1]: Entering directory '/home/begerad/git/github/libhttpserver/build/src'
make[2]: Entering directory '/home/begerad/git/github/libhttpserver/build/src'
/usr/bin/mkdir -p '/usr/local/lib'
/bin/bash ../libtool --mode=install /usr/bin/install -c libhttpserver.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libhttpserver.so.0.19.0 /usr/local/lib/libhttpserver.so.0.19.0
libtool: install: (cd /usr/local/lib && { ln -s -f libhttpserver.so.0.19.0 libhttpserver.so.0 || { rm -f libhttpserver.so.0 && ln -s libhttpserver.so.0.19.0 libhttpserver.so.0; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libhttpserver.so.0.19.0 libhttpserver.so || { rm -f libhttpserver.so && ln -s libhttpserver.so.0.19.0 libhttpserver.so; }; })
libtool: install: /usr/bin/install -c .libs/libhttpserver.lai /usr/local/lib/libhttpserver.la
libtool: install: /usr/bin/install -c .libs/libhttpserver.a /usr/local/lib/libhttpserver.a
libtool: install: chmod 644 /usr/local/lib/libhttpserver.a
libtool: install: ranlib /usr/local/lib/libhttpserver.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib
...
I created the following makefile.
# Source, Executable, Includes, Library Defines
LIBS = -lhttpserver
# Compiler, Linker Defines
LIBPATH = -L. -L/usr/local/lib/
LDFLAGS = -o main $(LIBPATH) $(LIBS)
RM = /bin/rm -f
# *****************************************************
# Variables to control Makefile operation
CC = g++
CFLAGS = -Wall -g
# ****************************************************
# Targets needed to bring the executable up to date
main: main.o
$(CC) $(CFLAGS) $(LDFLAGS) -o main main.o
# The main.o target can be written more simply
main.o: main.cpp
$(CC) $(CFLAGS) -c main.cpp
clean:
$(RM) main.o main
The call for make replied like this.
make
g++ -Wall -g -c main.cpp
In file included from /usr/local/include/httpserver/basic_auth_fail_response.hpp:29,
from /usr/local/include/httpserver.hpp:26,
from main.cpp:23:
/usr/local/include/httpserver/http_utils.hpp:287:27: error: ‘std::string_view’ has not been declared
287 | bool operator()(std::string_view x, std::string_view y) const {
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:287:47: error: ‘std::string_view’ has not been declared
287 | bool operator()(std::string_view x, std::string_view y) const {
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp: In member function ‘bool httpserver::http::header_comparator::operator()(int, int) const’:
/usr/local/include/httpserver/http_utils.hpp:288:10: error: request for member ‘size’ in ‘x’, which is of non-class type ‘int’
288 | COMPARATOR(x, y, std::toupper);
| ^~~~~~~~~~
...
Expected behavior
I expected make to build the hello_world example.
System:
- OS/Environment: Debian GNU/Linux 11 (bullseye)
Do you have an idea how to build this example? I am happy with each and every hint in the right direction.
Cheers!
Today, I came back to this issue:
- Source file: main.cpp
#include <httpserver.hpp>
using namespace httpserver;
class hello_world_resource : public http_resource {
public:
std::shared_ptr<http_response> render(const http_request&) {
return std::shared_ptr<http_response>(new string_response("Hello, World!"));
}
};
int main(int argc, char** argv) {
webserver ws = create_webserver(8080);
hello_world_resource hwr;
ws.register_resource("/hello", &hwr);
ws.start(true);
return 0;
}
Makefile: makefile
RM = /bin/rm -f
OBJ = main.o
EXE = main
CC = /usr/bin/g++
CXXFLAGS = -Wall
LDFLAGS = -L/usr/local/lib -lhttpserver
#
all: $(EXE)
#
$(EXE): $(OBJ)
$(CC) $(CXXFLAGS) $(LDFLAGS) $(OBJ) -o $(EXE)
#
main.o: main.cpp
$(CC) -c main.cpp -o main.o
#
clean:
$(RM) $(OBJ) $(EXE) *~
I installed libhttpserver as documented in the README.md
Today, I am ending up with this build error:
$ make
/usr/bin/g++ -c main.cpp -L/usr/local/lib -lhttpserver -o main.o
In file included from /usr/local/include/httpserver/basic_auth_fail_response.hpp:29,
from /usr/local/include/httpserver.hpp:26,
from main.cpp:1:
/usr/local/include/httpserver/http_utils.hpp:287:27: error: ‘std::string_view’ has not been declared
287 | bool operator()(std::string_view x, std::string_view y) const {
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:287:47: error: ‘std::string_view’ has not been declared
287 | bool operator()(std::string_view x, std::string_view y) const {
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp: In member function ‘bool httpserver::http::header_comparator::operator()(int, int) const’:
/usr/local/include/httpserver/http_utils.hpp:288:10: error: request for member ‘size’ in ‘x’, which is of non-class type ‘int’
288 | COMPARATOR(x, y, std::toupper);
| ^~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:288:10: error: request for member ‘size’ in ‘y’, which is of non-class type ‘int’
288 | COMPARATOR(x, y, std::toupper);
| ^~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:288:10: error: invalid types ‘int[size_t {aka long unsigned int}]’ for array subscript
288 | COMPARATOR(x, y, std::toupper);
| ^~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:288:10: error: invalid types ‘int[size_t {aka long unsigned int}]’ for array subscript
288 | COMPARATOR(x, y, std::toupper);
| ^~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp: At global scope:
/usr/local/include/httpserver/http_utils.hpp:307:27: error: ‘std::string_view’ has not been declared
307 | bool operator()(std::string_view x, std::string_view y) const {
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:307:47: error: ‘std::string_view’ has not been declared
307 | bool operator()(std::string_view x, std::string_view y) const {
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp: In member function ‘bool httpserver::http::arg_comparator::operator()(int, int) const’:
/usr/local/include/httpserver/http_utils.hpp:311:10: error: request for member ‘size’ in ‘x’, which is of non-class type ‘int’
311 | COMPARATOR(x, y,); // NOLINT(whitespace/comma)
| ^~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:311:10: error: request for member ‘size’ in ‘y’, which is of non-class type ‘int’
311 | COMPARATOR(x, y,); // NOLINT(whitespace/comma)
| ^~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:311:10: error: invalid types ‘int[size_t {aka long unsigned int}]’ for array subscript
311 | COMPARATOR(x, y,); // NOLINT(whitespace/comma)
| ^~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:311:10: error: invalid types ‘int[size_t {aka long unsigned int}]’ for array subscript
311 | COMPARATOR(x, y,); // NOLINT(whitespace/comma)
| ^~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp: In member function ‘bool httpserver::http::arg_comparator::operator()(const string&, const string&) const’:
/usr/local/include/httpserver/http_utils.hpp:315:32: error: ‘string_view’ is not a member of ‘std’
315 | return operator()(std::string_view(x), std::string_view(y));
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:315:32: note: ‘std::string_view’ is only available from C++17 onwards
/usr/local/include/httpserver/http_utils.hpp:315:53: error: ‘string_view’ is not a member of ‘std’
315 | return operator()(std::string_view(x), std::string_view(y));
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:315:53: note: ‘std::string_view’ is only available from C++17 onwards
/usr/local/include/httpserver/http_utils.hpp: At global scope:
/usr/local/include/httpserver/http_utils.hpp:320:39: error: ‘string_view’ is not a member of ‘std’
320 | using header_view_map = std::map<std::string_view, std::string_view, http::header_comparator>;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:320:39: note: ‘std::string_view’ is only available from C++17 onwards
/usr/local/include/httpserver/http_utils.hpp:320:39: error: ‘string_view’ is not a member of ‘std’
/usr/local/include/httpserver/http_utils.hpp:320:39: note: ‘std::string_view’ is only available from C++17 onwards
/usr/local/include/httpserver/http_utils.hpp:320:57: error: ‘string_view’ is not a member of ‘std’
320 | using header_view_map = std::map<std::string_view, std::string_view, http::header_comparator>;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:320:57: note: ‘std::string_view’ is only available from C++17 onwards
/usr/local/include/httpserver/http_utils.hpp:320:57: error: ‘string_view’ is not a member of ‘std’
/usr/local/include/httpserver/http_utils.hpp:320:57: note: ‘std::string_view’ is only available from C++17 onwards
/usr/local/include/httpserver/http_utils.hpp:320:93: error: template argument 1 is invalid
320 | using header_view_map = std::map<std::string_view, std::string_view, http::header_comparator>;
| ^
/usr/local/include/httpserver/http_utils.hpp:320:93: error: template argument 2 is invalid
/usr/local/include/httpserver/http_utils.hpp:320:93: error: template argument 4 is invalid
/usr/local/include/httpserver/http_utils.hpp:322:36: error: ‘string_view’ is not a member of ‘std’
322 | using arg_view_map = std::map<std::string_view, std::string_view, http::arg_comparator>;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:322:36: note: ‘std::string_view’ is only available from C++17 onwards
/usr/local/include/httpserver/http_utils.hpp:322:36: error: ‘string_view’ is not a member of ‘std’
/usr/local/include/httpserver/http_utils.hpp:322:36: note: ‘std::string_view’ is only available from C++17 onwards
/usr/local/include/httpserver/http_utils.hpp:322:54: error: ‘string_view’ is not a member of ‘std’
322 | using arg_view_map = std::map<std::string_view, std::string_view, http::arg_comparator>;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_utils.hpp:322:54: note: ‘std::string_view’ is only available from C++17 onwards
/usr/local/include/httpserver/http_utils.hpp:322:54: error: ‘string_view’ is not a member of ‘std’
/usr/local/include/httpserver/http_utils.hpp:322:54: note: ‘std::string_view’ is only available from C++17 onwards
/usr/local/include/httpserver/http_utils.hpp:322:87: error: template argument 1 is invalid
322 | using arg_view_map = std::map<std::string_view, std::string_view, http::arg_comparator>;
| ^
/usr/local/include/httpserver/http_utils.hpp:322:87: error: template argument 2 is invalid
/usr/local/include/httpserver/http_utils.hpp:322:87: error: template argument 4 is invalid
/usr/local/include/httpserver/http_utils.hpp:370:79: error: ‘header_view_map’ in namespace ‘httpserver::http’ does not name a type; did you mean ‘header_map’?
370 | void dump_header_map(std::ostream& os, const std::string& prefix, const http::header_view_map& map);
| ^~~~~~~~~~~~~~~
| header_map
/usr/local/include/httpserver/http_utils.hpp:378:76: error: ‘arg_view_map’ in namespace ‘httpserver::http’ does not name a type
378 | void dump_arg_map(std::ostream& os, const std::string& prefix, const http::arg_view_map& map);
| ^~~~~~~~~~~~
In file included from /usr/local/include/httpserver.hpp:30,
from main.cpp:1:
/usr/local/include/httpserver/http_request.hpp:63:11: error: ‘string_view’ in namespace ‘std’ does not name a type
63 | std::string_view get_user() const;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:63:6: note: ‘std::string_view’ is only available from C++17 onwards
63 | std::string_view get_user() const;
| ^~~
/usr/local/include/httpserver/http_request.hpp:69:11: error: ‘string_view’ in namespace ‘std’ does not name a type
69 | std::string_view get_digested_user() const;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:69:6: note: ‘std::string_view’ is only available from C++17 onwards
69 | std::string_view get_digested_user() const;
| ^~~
/usr/local/include/httpserver/http_request.hpp:75:11: error: ‘string_view’ in namespace ‘std’ does not name a type
75 | std::string_view get_pass() const;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:75:6: note: ‘std::string_view’ is only available from C++17 onwards
75 | std::string_view get_pass() const;
| ^~~
/usr/local/include/httpserver/http_request.hpp:81:11: error: ‘string_view’ in namespace ‘std’ does not name a type
81 | std::string_view get_path() const {
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:81:6: note: ‘std::string_view’ is only available from C++17 onwards
81 | std::string_view get_path() const {
| ^~~
/usr/local/include/httpserver/http_request.hpp:110:11: error: ‘string_view’ in namespace ‘std’ does not name a type
110 | std::string_view get_method() const {
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:110:6: note: ‘std::string_view’ is only available from C++17 onwards
110 | std::string_view get_method() const {
| ^~~
/usr/local/include/httpserver/http_request.hpp:119:18: error: ‘header_view_map’ in namespace ‘httpserver::http’ does not name a type; did you mean ‘header_map’?
119 | const http::header_view_map get_headers() const;
| ^~~~~~~~~~~~~~~
| header_map
/usr/local/include/httpserver/http_request.hpp:126:18: error: ‘header_view_map’ in namespace ‘httpserver::http’ does not name a type; did you mean ‘header_map’?
126 | const http::header_view_map get_footers() const;
| ^~~~~~~~~~~~~~~
| header_map
/usr/local/include/httpserver/http_request.hpp:133:18: error: ‘header_view_map’ in namespace ‘httpserver::http’ does not name a type; did you mean ‘header_map’?
133 | const http::header_view_map get_cookies() const;
| ^~~~~~~~~~~~~~~
| header_map
/usr/local/include/httpserver/http_request.hpp:140:18: error: ‘arg_view_map’ in namespace ‘httpserver::http’ does not name a type
140 | const http::arg_view_map get_args() const;
| ^~~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:163:11: error: ‘string_view’ in namespace ‘std’ does not name a type
163 | std::string_view get_header(std::string_view key) const;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:163:6: note: ‘std::string_view’ is only available from C++17 onwards
163 | std::string_view get_header(std::string_view key) const;
| ^~~
/usr/local/include/httpserver/http_request.hpp:165:11: error: ‘string_view’ in namespace ‘std’ does not name a type
165 | std::string_view get_cookie(std::string_view key) const;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:165:6: note: ‘std::string_view’ is only available from C++17 onwards
165 | std::string_view get_cookie(std::string_view key) const;
| ^~~
/usr/local/include/httpserver/http_request.hpp:172:11: error: ‘string_view’ in namespace ‘std’ does not name a type
172 | std::string_view get_footer(std::string_view key) const;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:172:6: note: ‘std::string_view’ is only available from C++17 onwards
172 | std::string_view get_footer(std::string_view key) const;
| ^~~
/usr/local/include/httpserver/http_request.hpp:179:11: error: ‘string_view’ in namespace ‘std’ does not name a type
179 | std::string_view get_arg(std::string_view key) const;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:179:6: note: ‘std::string_view’ is only available from C++17 onwards
179 | std::string_view get_arg(std::string_view key) const;
| ^~~
/usr/local/include/httpserver/http_request.hpp:185:11: error: ‘string_view’ in namespace ‘std’ does not name a type
185 | std::string_view get_content() const {
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:185:6: note: ‘std::string_view’ is only available from C++17 onwards
185 | std::string_view get_content() const {
| ^~~
/usr/local/include/httpserver/http_request.hpp:200:11: error: ‘string_view’ in namespace ‘std’ does not name a type
200 | std::string_view get_querystring() const;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:200:6: note: ‘std::string_view’ is only available from C++17 onwards
200 | std::string_view get_querystring() const;
| ^~~
/usr/local/include/httpserver/http_request.hpp:206:11: error: ‘string_view’ in namespace ‘std’ does not name a type
206 | std::string_view get_version() const {
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:206:6: note: ‘std::string_view’ is only available from C++17 onwards
206 | std::string_view get_version() const {
| ^~~
/usr/local/include/httpserver/http_request.hpp:228:11: error: ‘string_view’ in namespace ‘std’ does not name a type
228 | std::string_view get_requestor() const;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:228:6: note: ‘std::string_view’ is only available from C++17 onwards
228 | std::string_view get_requestor() const;
| ^~~
/usr/local/include/httpserver/http_request.hpp:375:11: error: ‘string_view’ in namespace ‘std’ does not name a type
375 | std::string_view get_connection_value(std::string_view key, enum MHD_ValueKind kind) const;
| ^~~~~~~~~~~
/usr/local/include/httpserver/http_request.hpp:375:6: note: ‘std::string_view’ is only available from C++17 onwards
375 | std::string_view get_connection_value(std::string_view key, enum MHD_ValueKind kind) const;
| ^~~
/usr/local/include/httpserver/http_request.hpp:376:18: error: ‘header_view_map’ in namespace ‘httpserver::http’ does not name a type; did you mean ‘header_map’?
376 | const http::header_view_map get_headerlike_values(enum MHD_ValueKind kind) const;
| ^~~~~~~~~~~~~~~
| header_map
make: *** [makefile:17: main.o] Error 1
I appreciate any advice solving this issue.
Cheers!
What version of C++ are you building with? std::string_view was added in C++17 so trying to build with anything older than that will not work.