Ubuntu Suomen keskustelualueet
Ubuntun käyttö => Ohjelmointi, palvelimet ja muu edistyneempi käyttö => Aiheen aloitti: teele - 11.01.22 - klo:21.06
-
Githubista on haettu libhttpserver, mutta. ./bootstrap ilmoitti LIBTOOLIN puuttumisesta
$ ./bootstrap
./bootstrap: line 25: libtoolize: command not found
configure.ac:39: installing './compile'
configure.ac:32: installing './config.guess'
configure.ac:32: installing './config.sub'
configure.ac:29: installing './install-sh'
configure.ac:29: installing './missing'
examples/Makefile.am: installing './depcomp'
src/Makefile.am:21: error: Libtool library used but 'LIBTOOL' is undefined
src/Makefile.am:21: The usual way to define 'LIBTOOL' is to add 'LT_INIT'
src/Makefile.am:21: to 'configure.ac' and run 'aclocal' and 'autoconf' again.
src/Makefile.am:21: If 'LT_INIT' is in 'configure.ac', make sure
src/Makefile.am:21: its definition is in aclocal's search path.
parallel-tests: installing './test-driver'
Makefile.am on tällainen
LIBTOOL_DEPS = @LIBTOOL_DEPS@
AUTOMAKE_OPTIONS = foreign 1.4
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src
DIST_SUBDIRS = src
if !COND_CROSS_COMPILE
SUBDIRS += test
DIST_SUBDIRS += test
if BUILD_EXAMPLES
SUBDIRS += examples
DIST_SUBDIRS += examples
endif
endif
EXTRA_DIST = libhttpserver.pc.in $(DX_CONFIG)
MOSTLYCLEANFILES = $(DX_CLEANFILES) *.gcda *.gcno *.gcov
DISTCLEANFILES = DIST_REVISION
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libhttpserver.pc
cmakemoduledir = $(datadir)/cmake/Modules
cmakemodule_DATA = cmakemodule/FindLibHttpServer.cmake
include $(top_srcdir)/aminclude.am
# Update libtool, if needed.
libtool: $(LIBTOOL_DEPS)
$(SHELL) ./config.status --recheck
dist-hook:
date >DIST_REVISION
git branch -vv >>DIST_REVISION
cp DIST_REVISION $(distdir)/
Mutta LT_INIT näyttää jo olevan configure.ac :ssä
.
.
.
OLD_CXXFLAGS=$CXXFLAGS
LT_INIT
AC_PROG_CC
AC_PROG_CXX()
AC_PROG_LN_S
CXXFLAGS=$OLD_CXXFLAGS
AC_LANG([C++])
AC_SYS_LARGEFILE[
.
.
.
/code]
Miten saisi LIBTOOL - puutteen korjattua.
-
Githubista on haettu libhttpserver, mutta. ./bootstrap ilmoitti LIBTOOLIN puuttumisesta
$ ./bootstrap
./bootstrap: line 25: libtoolize: command not found
Asenna libtool:
sudo apt install libtool
-
Edistyy, mutta make ei onnistunut, missä makefilen pitäisi olla
$ make
make: *** No targets specified and no makefile found. Stop.
Pitäisikö olla jossain muussa hakemistossa, kun makea yrittää. Melkein samannimisiä tiedostja makefilen kanssa on kyllä, mutta make kai haluaa aina juuri makefilen. Makelle ei myöskään ole annettu kohdetta?
Olisiko ../configure -virheellä osuutta asiaan
./configure
configure: WARNING: "gnutls/gnutls.h not found. TLS will be disabled"
checking microhttpd.h usability... no
checking microhttpd.h presence... no
checking for microhttpd.h... no
configure: error: "microhttpd.h not found"
Kokonaisuudessaan ../config -ilmoitukset ovat tässä (aika pitkä listaus)
$ ../configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for valgrind... no
checking how to print strings... printf
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... /usr/bin/ld -m elf_x86_64
checking if the linker (/usr/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC -DPIC
checking if g++ PIC flag -fPIC -DPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether ln -s works... yes
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking whether g++ supports C++14 features by default... yes
checking whether it is possible to compile in the same directory... no
checking for ANSI C header files... (cached) yes
checking for stdint.h... (cached) yes
checking for inttypes.h... (cached) yes
checking errno.h usability... yes
checking errno.h presence... yes
checking for errno.h... yes
checking for unistd.h... (cached) yes
checking ctype.h usability... yes
checking ctype.h presence... yes
checking for ctype.h... yes
checking for sys/stat.h... (cached) yes
checking for sys/types.h... (cached) yes
checking arpa/inet.h usability... yes
checking arpa/inet.h presence... yes
checking for arpa/inet.h... yes
checking signal.h usability... yes
checking signal.h presence... yes
checking for signal.h... yes
checking gnutls/gnutls.h usability... no
checking gnutls/gnutls.h presence... no
checking for gnutls/gnutls.h... no
configure: WARNING: "gnutls/gnutls.h not found. TLS will be disabled"
checking microhttpd.h usability... no
checking microhttpd.h presence... no
checking for microhttpd.h... no
configure: error: "microhttpd.h not found"
-
Olisiko ../configure -virheellä osuutta asiaan
./configure
configure: WARNING: "gnutls/gnutls.h not found. TLS will be disabled"
checking microhttpd.h usability... no
checking microhttpd.h presence... no
checking for microhttpd.h... no
configure: error: "microhttpd.h not found"
Asenna libmicrohttpd-dev. Jos tarvitset HTTPS-tuen (SSL/TLS), asenna myös libgnutls28-dev.
sudo apt install libmicrohttpd-dev
-
Libbhttpserverin asennus on mahdollisesti onnistunut. /home/k1/.bash_history -tiedostosta katsottuna on tarvittu tällaisia komentoja Ubuntu 20.04 -peruskoneella
sudo apt install aclocal
sudo apt install automake
sudo apt install git
sudo apt install libtool
sudo apt install libmicrohttpd-dev
sudo apt install libgnutls28-dev
sudo apt autoremove
d /home/koti/Documents/koti_libhttpserver
git clone https://github.com/git-guides/git-clone
git config –global user.name "oma-git-tunnus"
mkdir git-noudot
cd git-noudot
git init
git remote add origin https://github.com/oma-git-tunnus/.git/
git clone https://github.com/etr/libhttpserver
ls
cd libhttpserver
ls
./bootstrap
./configure
make
Yhtään kokeiluohjelmaa en vielä ole ehtinyt kääntää, mutta toivon parasta ja uskaltanen laittaa tämän asennussäikeen ratkaistuksi. Kiitos neuvoista :)
-
Yritin Hello_worldin kääntämistä, mutta
$ g++ lbhttpser01.cpp -o lbhttpser01 -Wall -pedantic -L/usr/local/lib -pthread -std=c++17
/usr/bin/ld: /tmp/ccTd04do.o: in function `hello_world_resource::render(httpserver::http_request const&)':
lbhttpser01.cpp:(.text+0xb6): undefined reference to `httpserver::http_request::get_arg(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/usr/bin/ld: lbhttpser01.cpp:(.text+0x1e9): undefined reference to `httpserver::http::http_utils::text_plain'
/usr/bin/ld: /tmp/ccTd04do.o: in function `main':
lbhttpser01.cpp:(.text+0x41b): undefined reference to `httpserver::webserver::webserver(httpserver::create_webserver const&)'
/usr/bin/ld: lbhttpser01.cpp:(.text+0x487): undefined reference to `httpserver::webserver::register_resource(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, httpserver::http_resource*, bool)'
/usr/bin/ld: lbhttpser01.cpp:(.text+0x4b9): undefined reference to `httpserver::webserver::start(bool)'
/usr/bin/ld: lbhttpser01.cpp:(.text+0x4dc): undefined reference to `httpserver::webserver::~webserver()'
/usr/bin/ld: lbhttpser01.cpp:(.text+0x575): undefined reference to `httpserver::webserver::~webserver()' ..... jne
Olisiko tehnyt virheen (taas :( ) siinä, että laitoin github kloonauksen alihakemistorakenteeseen näin
/home/k1/Documents/my_libhttpserver/libhttpserveri/libhttpserver/
ja
käännettävän ohjelman paikkaan
~/Documents/my_libhttpserver/kokeilut/
Virheimitushan voisi tarkoittaa, että oikeaa (viittaus)tiedostoa ei löydy mistään. Ehkä libhttpserverin asennuksessa käytetyt make ja make install olettavat jotain hakemistorakenteesta?
Hello_world on tässä alla libhttpserver01.cpp -nimisenä.
#include <iostream>
#include "/home/k1/Documents/my_libhttpserver/libhttpserveri/libhttpserver/src/httpserver.hpp"
class hello_world_resource : public httpserver::http_resource {
public:
const std::shared_ptr<httpserver::http_response> render(const httpserver::http_request&);
void set_some_data(const std::string &s) {data = s;}
std::string data;
};
// Using the render method you are able to catch each type of request you receive
const std::shared_ptr<httpserver::http_response> hello_world_resource::render(const httpserver::http_request& req) {
// It is possible to store data inside the resource object that can be altered through the requests
std::cout << "Data was: " << data << std::endl;
std::string datapar = req.get_arg("data");
set_some_data(datapar == "" ? "no data passed!!!" : datapar);
std::cout << "Now data is:" << data << std::endl;
// It is possible to send a response initializing an http_string_response that reads the content to send in response from a string.
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response("Hello World!!!", 200));
}
int main() {
// It is possible to create a webserver passing a great number of parameters. In this case we are just passing the port and the number of thread running.
httpserver::webserver ws = httpserver::create_webserver(8080).start_method(httpserver::http::http_utils::INTERNAL_SELECT).max_threads(5);
hello_world_resource hwr;
// This way we are registering the hello_world_resource to answer for the endpoint
// "/hello". The requested method is called (if the request is a GET we call the render_GET
// method. In case that the specific render method is not implemented, the generic "render"
// method is called.
ws.register_resource("/hello", &hwr, true);
// This way we are putting the created webserver in listen. We pass true in order to have
// a blocking call; if we want the call to be non-blocking we can just pass false to the method.
ws.start(true);
return 0;
}
-
Yritin Hello_worldin kääntämistä, mutta
$ g++ lbhttpser01.cpp -o lbhttpser01 -Wall -pedantic -L/usr/local/lib -pthread -std=c++17
/usr/bin/ld: /tmp/ccTd04do.o: in function `hello_world_resource::render(httpserver::http_request const&)':
lbhttpser01.cpp:(.text+0xb6): undefined reference to `httpserver::http_request::get_arg(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
Binääriin pitää linkittää libhttpserver ja libmicrohttpd, sekä mahdollisesti muita kirjastoja riippuen siitä, onko TLS-tuki käännetty mukaan libhttpserveriin.
Eli jotenkin tähän suuntaan:
g++ lbhttpser01.cpp -o lbhttpser01 -Wall -pedantic -L/usr/local/lib -lhttpserver -lmicrohttpd -pthread -std=c++17
-
Nyt kokeiluohjelma näytti kääntyvän,
$ g++ libhttpserver01.cpp -o libhttpserver01 -Wall -pedantic -L/usr/local/lib -lhttpserver -lmicrohttpd -pthread -std=c++17
Mutta
$ ./libhttpserver01
./libhttpserver01: error while loading shared libraries: libhttpserver.so.0: cannot open shared object file: No such file or directory
eli libhttpserver.so.0: -tiedostoa ei löydy. En ole vielä etsinyt sitä koneelta, olisiko se jossain, mistä käännös ei sitä löydä.
-
eli libhttpserver.so.0: -tiedostoa ei löydy. En ole vielä etsinyt sitä koneelta, olisiko se jossain, mistä käännös ei sitä löydä.
Pitäisi olla /usr/local/lib-hakemistossa. Tarkista sijainti ja varmista, että kyseinen hakemisto on järjestelmän kirjastopolussa.
-
Tiedosto on olemassa
$ find /usr/local/lib/ -name libhttpserver.so.0
/usr/local/lib/libhttpserver.so.0
Mutta
echo $LD_LIBRARY_PATH
eli onko järjestelmäkirjasto tyhjä. En ole aikaisemmin muokannut $LD_LIBRARY -asetuksia esim. exportilla. Netissä varoitettiin sen käyttämisestä. Voinko vain lisätä puuttuvan tiedoston järjestelmäkirjastomuuttujaan.
-
Kokeile riittäisikö kirjastovälimuistin päivittäminen:
sudo ldconfig
Jos ei auta, kokeile vielä näin:
sudo ldconfig /usr/local/lib
-
Nyt ohjelma kääntyi ja käynnistyi. sudo ldconfig taisi olla ratkaisu, mutta en kyllä vieläkään saanut järjestelmäkirjastomuuttujalle mitään arvoa echolla ( ?? )
Käännetty ohjelma on tässä alla
#include <iostream>
#include "/home/k1/Documents/my_libhttpserver/libhttpserveri/libhttpserver/src/httpserver.hpp"
class hello_world_resource : public httpserver::http_resource {
public:
const std::shared_ptr<httpserver::http_response> render(const httpserver::http_request&);
void set_some_data(const std::string &s) {data = s;}
std::string data;
};
// Using the render method you are able to catch each type of request you receive
const std::shared_ptr<httpserver::http_response> hello_world_resource::render(const httpserver::http_request& req) {
// It is possible to store data inside the resource object that can be altered through the requests
std::cout << "Data was: " << data << std::endl;
std::string datapar = req.get_arg("data");
set_some_data(datapar == "" ? "no data passed!!!" : datapar);
std::cout << "Now data is:" << data << std::endl;
// It is possible to send a response initializing an http_string_response that reads the content to send in response from a string.
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response("Hello World!!!", 200));
}
int main() {
// It is possible to create a webserver passing a great number of parameters. In this case we are just passing the port and the number of thread running.
httpserver::webserver ws = httpserver::create_webserver(8080).start_method(httpserver::http::http_utils::INTERNAL_SELECT).max_threads(5);
hello_world_resource hwr;
// This way we are registering the hello_world_resource to answer for the endpoint
// "/hello". The requested method is called (if the request is a GET we call the render_GET
// method. In case that the specific render method is not implemented, the generic "render"
// method is called.
ws.register_resource("/hello", &hwr, true);
// This way we are putting the created webserver in listen. We pass true in order to have
// a blocking call; if we want the call to be non-blocking we can just pass false to the method.
ws.start(true);
return 0;
}
Käännöskomento oli
g++ libhttpserver01.cpp -o libhttpserver01 -Wall -pedantic -L/usr/local/lib -lhttpserver -lmicrohttpd -pthread -std=c++17
Postdata näyttää löytyvän curlin kanssa
$ curl -X POST -F 'name=linuxize' -F 'data=ööö pp öö åååååååh' http://localhost:8080/hello
joka näkyy tällaisena
Data was: no data passed!!!
Now data is:ööö pp öö åååååååh
Mutta jos yritän html-sivulta postia lomakkeen kanssa
<!DOCTYPE html>
<html>
<body>
<h1>Lomakekokeilu post- ja get-menetelmät</h1>
<form action=" http://localhost:8080/hello" method="post">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="data">Last data:</label>
<input type="text" id="data" name="datatekstiä"><br><br>
<button type="submit">Lähetä post</button>
</form>
</br> </br> </br> </br>
<form action=" http://localhost:8080/hello" method="get">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="data">Last data:</label>
<input type="text" id="data" name="datatekstiä"><br><br>
<button type="submit">Lähetä get</button>
</form>
" "
</br> </br> </br> </br>
<form>
<button type="submit" formaction="http://localhost:8080/hello"
method="post">Lähetä tyhjä post
</button>
</form>
</body>
</html>
käännettypalvelin näyttää vain
Data was: no data passed!!!
Now data is:no data passed!!!
Hello world kyllä ilmestyy selaimeen aukeavaan ikkunaan. Selaimen kautta yritettäessä postin data ei näytä menevän perille, vaikka curlilla menee?
-
Muistelenpa, että tuo argumentin nimi piti antaa tuolla namella eli inputin pitäisi näyttää jokseenkin tältä:
<input type="text" id="voiollamitävaan" name="data">
-
Niin taitaa olla. Nyt lomakkeen arvot siirtyvät selaimestakin.
Laitan tämän säikeen ratkaistuksi, otsikossahan on kysymystä vain kääntämisestä.
Kiitos kaikista vastauksista :)
<!DOCTYPE html>
<html>
<body>
<h1>Lomakekokeilu post- ja get-menetelmät</h1>
<form action=" http://localhost:8080/hello" method="post">
<label for="fname1">First name:</label>
<input type="text" id="fnameid1" name="data"><br><br>
<label for="fnmame2">Last data:</label>
<input type="text" id="dataid2" name="data"><br><br>
<button type="submit">Lähetä post</button>
</form>
</br> </br> </br> </br>
<!-- get ei lähettäne ääkkösiä oikein --!>
<form action=" http://localhost:8080/hello" method="GET">
<label for="fname">First name:</label>
<input type="text" id="fname" name="data"><br><br>
<label for="data">Last data:</label>
<input type="text" id="data" name="data"><br><br>
<button type="submit">Lähetä get</button>
</form>
" "
</br> </br> </br> </br>
<form>
<button type="submit" formaction="http://localhost:8080/hello"
method="post">Lähetä tyhjä post
</button>
</form>
</body>
</html>