0

I am trying to create a new Apache 2 module, to hold a complex piece of software. The code consists of my own C files, which compile into .o files and are then linked into a .so file. The problem is that my code uses tcl to handle scripting. Up to now, I have compiled the tcl (version 8.4.13 -- yes, it is that old) into a .a archive and linked it to the .o files to create a single .so file, which Apache loads as a module and all works. I found this tricky on the Mac BSD-based system, but was able finally to make it work by: 1. Compiling tcl with --enable-threads --disable-shared --disable-corefoundation options 2. Link the .o files from my code to the tcl library with this:

gcc -DSHARED_MODULE -bundle -undefined suppress -flat_namespace -o mod_anastasia.so Release/*.o libtcl8.5.a

This works for BSD/Mac. So now I need to compile this module for a Linux server. Here is the apxs command which should (in theory) work:

apxs -i -c mod_anastasia.c ana_browsegrove.c libtcl8.4.a

This gives the following warning:

* Warning: Linking the shared library mod_anastasia.la against the static library libtcl8.4.a is not portable!*

And sure enough when I try to load the .so file created into Apache, I get this error:

httpd: Syntax error on line 156 of /usr/local/apache2/conf/httpd.conf: Cannot load modules/mod_anastasia.so into server: /usr/local/apache2/modules/mod_anastasia.so: undefined symbol: acos

So my question... does anyone know the magic formula for compiling a .a file so that Apache can link it to .o files made by apxs?

1 Answer 1

1

acos() is a function of libm. You have to specify, that your shared library also needs to link libm to satisfies its requirements.

Try compiling this way:

apxs -i -c mod_anastasia.c ana_browsegrove.c libtcl8.4.a -lm

This should fix your undefined symbol issue.

For the other warning: You could also try to link the shared version of the tcl library instead by replacing libtcl8.4.a by -ltcl8.4 (if the corresponding tcl library is installed correctly in the system). Linking static libraries to a shared library can be problematic and should be avoided.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! simply adding -lm solved the problem. Superb.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.