Reputation: 343
I am attempting to move my module to Linux Apache 2.4 and I am having linking issues. On windows a libhttpd.lib is available to link against as well as the apr/apr-util libraries. lib* httpd apr and aprutil are all statically linked on my windows installation. I want to do the same for the Linux installation.
According to the limited documentation available I am unable to use APXS because my module is written in C++.
I am having difficulties finding the archive files for the server on Linux. What do I need to link against for my module to work?
The source is able to link and execute on a Windows host.
Sample errors:
/home/ec2-user/httpd-2.4.2/srclib/apr/locks/unix/proc_mutex.c:367: undefined reference to `pthread_mutexattr_init'
/home/ec2-user/httpd-2.4.2/srclib/apr/locks/unix/proc_mutex.c:374: undefined reference to `pthread_mutexattr_setpshared'
/home/ec2-user/httpd-2.4.2/srclib/apr/locks/unix/proc_mutex.c:384: undefined reference to `pthread_mutexattr_setrobust_np'
/home/ec2-user/httpd-2.4.2/srclib/apr/locks/unix/proc_mutex.c:393: undefined reference to `pthread_mutexattr_setprotocol'
/home/ec2-user/httpd-2.4.2/srclib/apr/locks/unix/proc_mutex.c:414: undefined reference to `pthread_mutexattr_destroy'
/home/ec2-user/httpd-2.4.2/srclib/apr/locks/unix/proc_mutex.c:408: undefined reference to `pthread_mutexattr_destroy'
Thanks
Upvotes: 1
Views: 2312
Reputation: 343
So anyone else searching for this may get the answer.
You do not need to compile statically like I needed to, but I wanted to be able to move my module to any Linux host without worry about the necessary components. Apache needs pcre(regex), apr(all libraries), threads (proc/thread mutex), dl(dynamic loading), and crypt(apr password) to work. Since thread, dl, and crypt will most like already be on the machine, I chose to not compile them statically.
Happy hunting. I hope my never ending story over 3 days helps someone else!
Upvotes: 1
Reputation: 2036
For those building Apache modules in C++ and want dynamic linking, here's the g++ command line I used to successfully build a module; briefly tested on Apache 2.2.22/CentOS 6.2.
g++ [my files].cpp -I/httpd/include/ -I/httpd/srclib/apr/include/
-I/httpd/srclib/apr-util/include/ -I/usr/include/ -I/usr/include/apr-1/
-I/httpd/os/unix/ -shared -fPIC -o mod_mymodule.so
I'm an Apache/linux programming noob and was unable to find this info anywhere else; thanks to the OP's solution I was able to finish the job after a few days of frustration.
Here's also a link which helped explain how to work around the 'unresolved reference' linker issue when it couldn't find the apache functions contained within the httpd server core code (libhttpd.lib on Windows) -- which doesn't exist in *nix, unless you make it manually like the OP did. Basically, the answer was to use the -shared flag so these references are automagically resolved at run time. http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
Don't forget the 'extern C' in your module code, and build in DSO support when building HTTPD.
Hope this helps someone else!
Upvotes: 1
Reputation: 206841
These errors means you didn't add -pthread
to your compile command line, so you're not getting the pthread
library linked in.
(Note: it's -pthread
, not -lpthread
- it's not just a linker option.)
Upvotes: 1