How to compile apache module with included sds library using apxs2 - apache

I get example apache2 module here:
https://httpd.apache.org/docs/2.4/developer/modguide.html
and I want to use there this sds library https://github.com/antirez/sds
So I will create new module and goto module dir:
apxs -g -n mymodule
cd mod_mymodule
add on line 44 of mod_mymodule.c:
#include "sds.h"
and into the mymodule_handler on line 49 I will add
sds a = sdsnew("a");
sds b = sdsnew("b");
if (sdscmp(a, b) == 0)
return (DECLINED);
I also put library files (sds.c, sds.h, sdsalloc.h) into the same directory as my module source code file and then I will call:
sudo apxs -i -a -c mod_mymodule.c
Then I will restart apache, but it fails to start because of:
apache2: Syntax error on line 146 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/mymodule.load: Cannot load /usr/lib/apache2/modules/mod_mymodule.so into server: /usr/lib/apache2/modules/mod_mymodule.so: undefined symbol: sdscmp
Question: How can I modify apxs command to make my new module work with included library?

If you want to link them together into your module, you'd pass in all the .c files. Keep the one that's a module first otherwise you have to also pass -n for the module name.
If "sds" were instead an installed library, you'd pass -lsds to apxs just as you would to compiple without apxs.

Related

How to fix "undefined symbol: BrotliEncoderTakeOutput" when apache start

I have compiled mod_brotli.so, but when I restart apache, it cannot load module.
Error :
httpd: Syntax error on line 155 of /usr/local/apache2/etc/httpd.conf: Cannot load modules/mod_brotli.so into server: /usr/local/apache2/modules/mod_brotli.so: undefined symbol: BrotliEncoderTakeOutput
I am having the same problem. I don't know if it is the cause... in my case we are trying to add mod_brotli to Apache 2.4.34, from the Red Hat software collection (why they don't compile it with Brotli and include the Brotli package as a dependency, I have no idea).
I am not C developer, coming from the admin side, I can't see why it isn't working.
At first I thought it was an ldconfig issue, so I added a new file to the config dir, but it still doesn't work...
# apachectl -M
httpd: Syntax error on line 129 of /opt/rh/httpd24/root/etc/httpd/conf/httpd.conf: Cannot load /opt/rh/httpd24/root/usr/lib64/httpd/modules/mod_brotli.so into server: /opt/rh/httpd24/root/usr/lib64/httpd/modules/mod_brotli.so: undefined symbol: BrotliEncoderTakeOutput
Here you can see that ld knows about it, and that lib has the symbol...
# ldconfig -p | grep brotli
libbrotlienc.so.1 (libc6,x86-64) => /usr/local/lib64/brotli/libbrotlienc.so.1
libbrotlienc.so (libc6,x86-64) => /usr/local/lib64/brotli/libbrotlienc.so
libbrotlidec.so.1 (libc6,x86-64) => /usr/local/lib64/brotli/libbrotlidec.so.1
libbrotlidec.so (libc6,x86-64) => /usr/local/lib64/brotli/libbrotlidec.so
libbrotlicommon.so.1 (libc6,x86-64) => /usr/local/lib64/brotli/libbrotlicommon.so.1
libbrotlicommon.so (libc6,x86-64) => /usr/local/lib64/brotli/libbrotlicommon.so
# nm /usr/local/lib64/brotli/libbrotlienc.so | grep BrotliEncoderTakeOutput
0000000000090970 T BrotliEncoderTakeOutput
Meanwhile, you can see the undefined symbol in mod_brotli:
# nm /opt/rh/httpd24/root/usr/lib64/httpd/modules/mod_brotli.so | grep BrotliEncoderTakeOutput
U BrotliEncoderTakeOutput
Compiling the Apache module was done with
apxs -i -c -I /usr/local/include/brotli/ mod_brotli.c
Brotli itself was compiled from the latest tarball from github...
Apache is otherwise running fine, with the brotli line commented out.
Will post again if I find the answer...
====
Edit:
I got it working (well, having issues related to haproxy and h2c (unencrypted http2), but that's another matter)
In my case, the two issues were
A) I had compiled brotli in a bad way (based on some blog posts), compiling it per the google github readme worked
B) I was compiling the module with apxs command, but it turns out that is only for third party modules. The correct way for Apache built in modules that just didn't get compiled originally is:
./configure --prefix=/opt/rh/httpd24/root/etc/httpd --enable-brotli --with-brotli=/usr/local
and then make install (prefix is for the RH SCL version of course) (I actually did make install from the modules/filters/ dir, so it would install as little as possible as an override... not sure if it was needed, but that's what I did).
I figured out B) first, but it wasn't picking up the Brotli libs, after A) it worked fully.
I have no idea what apxs is doing differently, or why there should be different ways to compile modules, but hey.
I hope this will be at least some help.

How to include mruby after installing with rbenv/ruby-build?

I'm trying to compile the "Source Code (.c)" example from this tutorial.
I have installed mruby using rbenv: rbenv install mruby-1.2.0
I get an error when trying to compile the program:
$ gcc -std=c99 -Imruby/include test_program.c -o test_program
test_program.c:1:10: fatal error: 'mruby.h' file not found
#include "mruby.h"
^
1 error generated.
How am I supposed to reference the mruby library when installing via rbenv/ruby-build?
Seems like rbenv install mruby-1.2.0 doesn't install header files of mruby(it's only a dump of build/host directory after mruby is built):
% ls $(rbenv prefix mruby-1.2.0)
LEGAL bin lib mrbgems mrblib src
You need
# get mruby's code
git clone https://github.com/mruby/mruby.git mruby
# build mruby
cd mruby && rake
# go back to directory of `test_program.c`
cd ..
before test_program.c's compilation instead.
And you need mruby/build/host/lib/libmruby.a -lm compile options too.
add -lm
in mruby is /include directory in my source is possible -I mruby_directory/include
next add ~/mruby/build/host/lib/libmruby.a

Cannot find input file: makefile.in

I've bin trying to integrate Apache and with Django.
I downloaded the mod_wsgi-3.4 folder from the net and tried running the ./configure command from git bash.
I'm using dev c++ as my c compiler.
I get the following errors:
./configure: line 1877: apxs: command not found ln: creating symbolic link 'Makefile.in' to 'posix-apX.mk.in': No such file directory configure: creating ./config.status config.status:error: cannot find input file: Makefile.in
Can someone help me with this?
You can specify the location of apxs
./configure --with-apxs=/usr/local/apache/bin/apxs

Compiling First Obj-C source under Windows

I'm trying to compile for the first time, a Obj-C source under Windows 7.
I installed GNUstep and when I try to compile a simple hello world file it says to me
I had MinGW installed before with CodeBlocks fwiw...
Here is the error message I get from the GNUstep shell:
EDIT: I tryed to add this GNUmakefile
include $(GNUSTEP_MAKEFILES)/common.make
APP_NAME = PanelTest
PanelTest_OBJC_FILES = main.m
include $(GNUSTEP_MAKEFILES)/application.make
but nothing changes.
EDIT 2: See #crashmstr reply to overcame the issue.
Now when I compile it says to me this
fatal error: Foundation/Foundation.h: No such file or directory
compilaion terminated.
What should I do?
C:\ is leaving you in the cd command, and in the next line, you are then adding g++ to send to the cd command.
Note the > in front of g++ instead of the $, plus the fact that it says sh: cd: C:g++
In the shell, you need to use Unix style paths and / as the path separator.
Is your path set correctly? The error message I see in your screenshot refers to g++ was not found.

Problems adding DKMS support to kernel module

I'm trying to add DKMS support in a kernel module i'm working on.
I have placed the kernel module source with a static lib to be linked against in the following directory:
/usr/src/dpx/1.0
With the following files:
dkms.conf
Makefile
dpxmtt.c
lib.a
dkms.conf file is like this:
MAKE="make"
CLEAN="make clean"
BUILT_MODULE_NAME=dpx
BUILT_MODULE_LOCATION=src/
DEST_MODULE_LOCATION=/kernel/drivers/input/touchscreen
PACKAGE_NAME=dpxm
PACKAGE_VERSION=1.0
REMAKE_INITRD=yes
And the makefile is like this:
EXTRA_CFLAGS+=-DLINUX_DRIVER -mhard-float
obj-m += dpx.o
dpx-objs:= dpxmtt.o ../source/lib.a
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
The ../source/lib.a is an hack since when the makefile is invoked by the dkms building system it was saying that it couldn't be found in directory (the build directory), but since it was being copied to the source directory, i'm referencing it relatively.
When I call
sudo dkms build -m dpx -v 1.0
The result is almost perfect:
santos#NS-PC:~$ sudo dkms build -m dpx -v 1.0
Kernel preparation unnecessary for this kernel. Skipping...
Building module:
cleaning build area....
make KERNELRELEASE=3.0.0-14-generic....
ERROR (dkms apport): binary package for dpx: 1.0 not found
Error! Build of dpx.ko failed for: 3.0.0-14-generic (i686)
Consult the make.log in the build directory
/var/lib/dkms/dpx/1.0/build/ for more information.
nsantos#NS-PC:~$
And the content of the log file is:
DKMS make.log for dpx-1.0 for kernel 3.0.0-14-generic (i686)
Thu Jan 19 11:07:54 WET 2012
make -C /lib/modules/3.0.0-14-generic/build M=/var/lib/dkms/dpx/1.0/build modules
make[1]: Entering directory `/usr/src/linux-headers-3.0.0-14-generic'
CC [M] /var/lib/dkms/dpx/1.0/build/dpxmtt.o
LD [M] /var/lib/dkms/dpx/1.0/build/dpx.o
Building modules, stage 2.
MODPOST 1 modules
CC /var/lib/dkms/dpx/1.0/build/dpx.mod.o
LD [M] /var/lib/dkms/dpx/1.0/build/dpx.ko
make[1]: Leaving directory `/usr/src/linux-headers-3.0.0-14-generic'
The module was built correctly but it ends with the error:
ERROR (dkms apport): binary package for dpx: 1.0 not found
Error! Build of dpx.ko failed for: 3.0.0-14-generic (i686)
And I don't know what it means. Does anybody know?
Using:
$(shell uname -r)
in the Makefile it might be also wrong! The "shell uname -r" refers to the currently running kernel, but the main reason to use the dkms it's because it offers an automated method to recompile the kernel modules that reside outside of the kernel tree for every newly installed kernel. What i mean is that the Makefile might refers to a different kernel which the dkms is building the module for.
Use:
${kernelver} instead.
I had a similar problem. I think your BUILT_MODULE_LOCATION is set incorrectly to the src directory. It should be set in your example to the current directory, or you can just omit this variable and dkms would default to the current directory.