Port Mongoose web server to FreeBSD - freebsd

I was wondering if anyone had success in porting the Linux versions of the Mongoose web server or the Civetweb web server to FreeBSD. I've tried to do a Make, but there is a compatibility issue between Linux and BSD, in that it cannot find -ldl. I've seen reference to this in a google search, and the recommended solution is probably beyond my skill level.

Linux uses GNU make by default. Its makefiles tend to be incompatible with FreeBSD's make. So you need to install GNU make using the /usr/ports/devel/gmake port. The program is called gmake on FreeBSD.
So for mongoose, download the latest mongoose source from github.
Then install GNU make using the /usr/ports/devel/gmake port. Unpack mongoose;
> tar xf mongoose-5.3.tar.gz
> cd mongoose-5.3/examples
Then compile it;
> gmake
cc hello.c ../mongoose.c -o hello -W -Wall -I.. -pthread -g -pipe
perl mkdata.pl websocket.html > websocket_html.c
cc websocket.c websocket_html.c ../mongoose.c -o websocket -W -Wall -I.. -pthread -g -pipe
cc server.c ../mongoose.c -o server -W -Wall -I.. -pthread -g -pipe
cc post.c ../mongoose.c -o post -W -Wall -I.. -pthread -g -pipe
cc multi_threaded.c ../mongoose.c -o multi_threaded -W -Wall -I.. -pthread -g -pipe
cc upload.c ../mongoose.c -o upload -W -Wall -I.. -pthread -g -pipe
cc auth.c ../mongoose.c -o auth -W -Wall -I.. -pthread -g -pipe
Civetweb also compiles without errors using gmake.

Related

Tesseract error while building training tools related to uchar.h file and ICU version

I have tried to follow the tutorials from here to build training tools for Tesseract. I get this error.
depbase=`echo boxchar.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
/bin/sh ../../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. -I../.. -DNDEBUG -DPANGO_ENABLE_ENGINE -I../../src/api -I../../src/api -I../../src/ccmain -I../../src/ccutil -I../../src/ccstruct -I../../src/lstm -I../../src/arch -I../../src/viewer -I../../src/textord -I../../src/dict -I../../src/classify -I../../src/wordrec -I../../src/cutil -I/usr/local/include/leptonica -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng15 -I/usr/include/uuid -I/usr/include/libdrm -g -O2 -std=c++11 -MT boxchar.lo -MD -MP -MF $depbase.Tpo -c -o boxchar.lo boxchar.cpp &&\
mv -f $depbase.Tpo $depbase.Plo
libtool: compile: g++ -DHAVE_CONFIG_H -I. -I../.. -DNDEBUG -DPANGO_ENABLE_ENGINE -I../../src/api -I../../src/api -I../../src/ccmain -I../../src/ccutil -I../../src/ccstruct -I../../src/lstm -I../../src/arch -I../../src/viewer -I../../src/textord -I../../src/dict -I../../src/classify -I../../src/wordrec -I../../src/cutil -I/usr/local/include/leptonica -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng15 -I/usr/include/uuid -I/usr/include/libdrm -g -O2 -std=c++11 -MT boxchar.lo -MD -MP -MF .deps/boxchar.Tpo -c boxchar.cpp -fPIC -DPIC -o .libs/boxchar.o
boxchar.cpp: In member function 'void tesseract::BoxChar::GetDirection(int*, int*) const':
boxchar.cpp:66:42: error: 'U_RIGHT_TO_LEFT_ISOLATE' was not declared in this scope
dir == U_ARABIC_NUMBER || dir == U_RIGHT_TO_LEFT_ISOLATE) {
^
make[1]: *** [boxchar.lo] Error 1
make[1]: Leaving directory `/home/vmuser/ocrd-train-master/tesseract-fd492062d08a2f55001a639f2015b8524c7e9ad4/src/training'
make: *** [training] Error 2
I looked at this Github comment here which states:
http://source.icu-project.org/repos/icu/tags/release-52-1/icu4c/source/common/unicode/uchar.h
http://source.icu-project.org/repos/icu/tags/release-50-1-2/icu4c/source/common/unicode/uchar.h
The training tools need icu version 52 and up. The icu version in RHEL & CentOS 7 is 50.
And from locate uchar.h I found that it resides in /usr/include/uchar.h and
/usr/include/unicode/uchar.h
I am not sure which file to change now. I don't know if it seems like a really stupid question
Thanks in Advance.
So, I finally figured it out myself:
download icu packages from:
http://download.icu-project.org/files/icu4c/
I used this file: http://download.icu-project.org/files/icu4c/59.1/icu4c-59_1-src.tgz
After that
tar zxf (tar file)
cd icu/source
make
sudo make install
After this in the Tesseract Directory
make training
sudo make training-install

How invoke dpkg-buildflags for manual compilation?

On Debian stretch when trying to manually compile e.g. libpopt (I'm not intending to create debian packages), after I did
export DEB_BUILD_OPTIONS=hardening=+all
I've trouble passing dpkg-buildflags to ./configure:
./configure $(dpkg-buildflags --export=cmdline)
configure: error: unrecognized option: -O2
Try `./configure --help' for more information.
If I do:
dpkg-buildflags --export=cmdline
I get:
CFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" CPPFLAGS="-Wdate-time -D_FORTIFY_SOURCE=2" CXXFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" FCFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong" FFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong" GCJFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong" LDFLAGS="-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now" OBJCFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" OBJCXXFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security"
When I now pass this output manually (copy&paste) to ./configure it works:
./configure CFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" CPPFLAGS="-Wdate-time -D_FORTIFY_SOURCE=2" CXXFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" FCFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong" FFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong" GCJFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong" LDFLAGS="-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now" OBJCFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" OBJCXXFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security"
checking build system type... x86_64-unknown-linux-gnu
[...]
How can I invoke dpkg-buildflags to automatically pass its flags to ./configure?
Why does manual copy&paste work but not the other approach?
Why does manual copy&paste work but not the other approach?
This is related to argument escaping. Consider the following function:
# This function simply prints its arguments, each on separate line
test () {
for arg in "$#"; do
echo "$arg"
done
}
This is what happens when you pass the output of dpkg-buildflags manually:
$ test ROSES=red VIOLETS=blue CFLAGS="-O0 -ggdb"
ROSES=red
VIOLETS=blue
CFLAGS=-O0 -ggdb
Note that CFLAGS=-O0 -ggdb is seen as a single argument, so escaping works.
Now let's try to evaluate an inline expression:
$ test $(echo ROSES=red VIOLETS=blue CFLAGS="-O0 -ggdb")
ROSES=red
VIOLETS=blue
CFLAGS=-O0
-ggdb
Boom! Somehow CFLAGS=-O0 -ggdb got broken into CFLAGS=-O0 and -ggdb. The same is happening in your case: the value of CFLAGS gets split into multiple arguments, and indeed -O2 is not a valid option. This is why you're getting an error.
How can I invoke dpkg-buildflags to automatically pass its flags to ./configure?
You can work this around using a pipe and xargs command:
dpkg-buildflags --export=cmdline | xargs ./configure
This solution works for me.

How to build dynamic-library in qt static build

I try to build my dynamic library project in linux. I build my qt library in static. But if i use it to build my proj, qt creator builds only libname.a file. However if i use original qt library qt creator builds libname.so file. Wats is the problem?
Pro file.
`#------------------------------------------------- # #
Project created by QtCreator 2020-10-22T07:46:59
# #-------------------------------------------------
QT -= gui TARGET = up_api_send
TEMPLATE = lib
DEFINES += UP_API_SEND_LIBRARY
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += up_api_send.cpp
HEADERS += up_api_send.h\
up_api_send_global.h
unix { target.path = /usr/lib INSTALLS += target }
unix:!macx: LIBS += -L$$PWD/libplot/ -lplot2
INCLUDEPATH += $$PWD/headerplot
DEPENDPATH += $$PWD/headerplot`
Build log.
Original library.
16:04:07: Start build project up_api_send...
16:04:07: Starts: «/opt/Qt5.7.1/5.7/gcc_64/bin/qmake» /root/QT/QT_SO/up_api_send/up_api_send.pro -spec linux-g++
Info: creating stash file /root/QT/QT_SO/build-up_api_send-Desktop_Qt_5_7_1_GCC_64bit-Release/.qmake.stash
16:04:07: Процесс «/opt/Qt5.7.1/5.7/gcc_64/bin/qmake» success.
16:04:07: Starts: «/usr/bin/make» qmake_all
make: Target `qmake_all' action is not required.
16:04:07: Process «/usr/bin/make» success.
16:04:07: Starts: «/usr/bin/make»
g++ -c -pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DUP_API_SEND_LIBRARY -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_CORE_LIB -I../up_api_send -I. -I../up_api_send/headerplot -I/opt/Qt5.7.1/5.7/gcc_64/include -I/opt/Qt5.7.1/5.7/gcc_64/include/QtCore -I. -I/opt/Qt5.7.1/5.7/gcc_64/mkspecs/linux-g++ -o up_api_send.o ../up_api_send/up_api_send.cpp
../up_api_send/up_api_send.cpp: In member function ‘bool DgateTrans::PLOT_sendMsg(const char*, const char*, int)’:
../up_api_send/up_api_send.cpp:143:19: warning: unused variable ‘tid’ [-Wunused-variable]
/opt/Qt5.7.1/5.7/gcc_64/bin/moc -DUP_API_SEND_LIBRARY -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_CORE_LIB -I/opt/Qt5.7.1/5.7/gcc_64/mkspecs/linux-g++ -I/root/QT/QT_SO/up_api_send -I/root/QT/QT_SO/up_api_send/headerplot -I/opt/Qt5.7.1/5.7/gcc_64/include -I/opt/Qt5.7.1/5.7/gcc_64/include/QtCore -I. -I/usr/include/c++/4.7 -I/usr/include/c++/4.7/x86_64-linux-gnu -I/usr/include/c++/4.7/backward -I/usr/lib/gcc/x86_64-linux-gnu/4.7/include -I/usr/local/include -I/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed -I/usr/include/x86_64-linux-gnu -I/usr/include ../up_api_send/up_api_send.h -o moc_up_api_send.cpp
g++ -c -pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DUP_API_SEND_LIBRARY -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_CORE_LIB -I../up_api_send -I. -I../up_api_send/headerplot -I/opt/Qt5.7.1/5.7/gcc_64/include -I/opt/Qt5.7.1/5.7/gcc_64/include/QtCore -I. -I/opt/Qt5.7.1/5.7/gcc_64/mkspecs/linux-g++ -o moc_up_api_send.o moc_up_api_send.cpp
rm -f libup_api_send.so.1.0.0 libup_api_send.so libup_api_send.so.1 libup_api_send.so.1.0
g++ -Wl,-O1 -Wl,-rpath,/opt/Qt5.7.1/5.7/gcc_64/lib -shared -Wl,-soname,libup_api_send.so.1 -o libup_api_send.so.1.0.0 up_api_send.o moc_up_api_send.o -L/root/QT/QT_SO/up_api_send/libplot/ -lplot2 -L/opt/Qt5.7.1/5.7/gcc_64/lib -lQt5Core -lpthread
ln -s libup_api_send.so.1.0.0 libup_api_send.so
ln -s libup_api_send.so.1.0.0 libup_api_send.so.1
ln -s libup_api_send.so.1.0.0 libup_api_send.so.1.0
16:04:09: Process «/usr/bin/make» success.
16:04:09: Time passed: 00:02.
Build log. Static library.
16:05:00: Start build project up_api_send...
16:05:00: Settings not changed, stage qmake is skipped.
16:05:00: Starts: «/usr/bin/make»
g++ -c -pipe -O2 -fPIC -std=gnu++11 -Wall -W -D_REENTRANT -DUP_API_SEND_LIBRARY -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_CORE_LIB -I../up_api_send -I. -I../up_api_send/headerplot -I/usr/local/Qt-5.7.1/include -I/usr/local/Qt-5.7.1/include/QtCore -I. -I/usr/local/Qt-5.7.1/mkspecs/linux-g++ -o up_api_send.o ../up_api_send/up_api_send.cpp
../up_api_send/up_api_send.cpp: In member function ‘bool DgateTrans::PLOT_sendMsg(const char*, const char*, int)’:
../up_api_send/up_api_send.cpp:143:19: warning: unused variable ‘tid’ [-Wunused-variable]
/usr/local/Qt-5.7.1/bin/moc -DUP_API_SEND_LIBRARY -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_CORE_LIB -I/usr/local/Qt-5.7.1/mkspecs/linux-g++ -I/root/QT/QT_SO/up_api_send -I/root/QT/QT_SO/up_api_send/headerplot -I/usr/local/Qt-5.7.1/include -I/usr/local/Qt-5.7.1/include/QtCore -I. -I/usr/include/c++/4.7 -I/usr/include/c++/4.7/x86_64-linux-gnu -I/usr/include/c++/4.7/backward -I/usr/lib/gcc/x86_64-linux-gnu/4.7/include -I/usr/local/include -I/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed -I/usr/include/x86_64-linux-gnu -I/usr/include ../up_api_send/up_api_send.h -o moc_up_api_send.cpp
g++ -c -pipe -O2 -fPIC -std=gnu++11 -Wall -W -D_REENTRANT -DUP_API_SEND_LIBRARY -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_CORE_LIB -I../up_api_send -I. -I../up_api_send/headerplot -I/usr/local/Qt-5.7.1/include -I/usr/local/Qt-5.7.1/include/QtCore -I. -I/usr/local/Qt-5.7.1/mkspecs/linux-g++ -o moc_up_api_send.o moc_up_api_send.cpp
rm -f libup_api_send.a
ar cqs libup_api_send.a up_api_send.o moc_up_api_send.o
16:05:02: Process «/usr/bin/make» success.
16:05:02: Time passed: 00:02.
Maybe i wrote wrong parameters when build qt library?
./configure -platform linux-g++
-release
-static
-fontconfig
-opensource
-confirm-license
-gtkstyle
-no-webkit
-nomake demos
-nomake examples

Makefile for Linux and Mac with address sanitizer

I am trying to write a makefile that I can use on linux and mac that builds with an address sanitizer. This works on my vagrant instance:
CC = gcc
ASAN_FLAGS = -fsanitize=address -fno-omit-frame-pointer -Wno-format-security
ASAN_LIBS = -static-libasan
CFLAGS := -Wall -Werror --std=gnu99 -g3
LDFLAGS += -lpthread
all: hello
hello: tiny_queue.o hello.o
$(CC) -o $# $(CFLAGS) $(ASAN_FLAGS) $(CURL_CFLAGS) $^ $(LDFLAGS) $(CURL_LIBS) $(ASAN_LIBS)
This works on ubuntu/trusty64 but fails on my mac with
$ make
gcc -Wall -Werror --std=gnu99 -g3 -I/opt/X11/include -c -o hello.o hello.c
gcc -o hello -Wall -Werror --std=gnu99 -g3 -fsanitize=address -fno-omit-frame-pointer -Wno-format-security tiny_queue.o hello.o -lpthread -static-libasan
clang: error: unknown argument: '-static-libasan'
make: *** [hello] Error 1
Does anyone know how to write a compatible makefile for the mac and linux?
p.s. I'm very new to C, sorry if this question is super basic.
CC = gcc
ASAN_FLAGS = -fsanitize=address -fno-omit-frame-pointer -Wno-format-security
ASAN_LIBS = -static-libasan
CFLAGS := -Wall -Werror --std=gnu99 -g3
LDFLAGS += -lpthread
all: hello
hello: tiny_queue.o hello.o
$(CC) -o $# $(CFLAGS) $(ASAN_FLAGS) $(CURL_CFLAGS) $^ $(LDFLAGS) $(CURL_LIBS) $(ASAN_LIBS)
You should not specify an Asan library (or a UBsan library, for that matter). Since you are using the compiler driver to drive link, just use -fsanitize=address (this is the recommended way of doing it). Do not add -static-libasan. The compiler driver will add the proper libraries for you.

How to use static library with gcc under linux

I'm trying to use a static library 'mylib.a' created with 'ar'. The examples I have seen use -L and -l to name the library. My attempts at using these fail. However, if I simply put the library file name on the linker command it works. (I'm overlooking something obvious?) Using gcc 4.8.4 Ubuntu 14.04 (see comment in code.) The f?.c and mymain.c are trivially simple. Thanks!
#!/bin/bash
# cc -v shows...
# gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1)
cc -c -Wall -Wstrict-prototypes -o fa.o fa.c
cc -c -Wall -Wstrict-prototypes -o fb.o fb.c
cc -c -Wall -Wstrict-prototypes -o fc.o fc.c
cc -c -Wall -Wstrict-prototypes -o mymain.o mymain.c
ar -rcs mylib.a fa.o fb.o fc.o
# THIS WORKS
#cc -o mypgm mymain.o mylib.a
# THESE FAIL WITH ERROR '/usr/bin/ld: cannot find -lmylib'
cc -o mypgm mymain.o -L. -lmylib
# OR
cc -o mypgm mymain.o -static -L. -lmylib
###
As noted in a comment…
When you use -lname, the linker looks for libname.a or libname.so in one of the directories that it has (already) been told to search for libraries.
You can either rename your library to libmine.a and then -L. -lmine will work, or rename it to libmylib.a and then -lmylib will work (but the repeated lib looks a bit clumsy, or neophytic).

Resources