Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Compile errors on custom plugin |
|
Author |
|
DoHITB
Joined: 16 Feb 2017 Posts: 8 Location: Catalonia, Lleida
|
Posted: Thu 16 Feb '17 20:53 Post subject: Compile errors on custom plugin |
|
|
Hi!
I'm trying to learn about custom plug-in on Apache, so I searched for some info. Then, I tried to make my first C program, but I'm having some errors while compiling...
Quote: |
C:\Users\user\AppData\Local\Temp\ccnz6AP9.o custom-handler.c:(.text+0x29): undefined reference to `__imp_ap_rwrite'
C:\Users\user\AppData\Local\Temp\ccnz6AP9.o custom-handler.c:(.text+0x5c): undefined reference to `__imp_ap_hook_handler'
C:\Users\user\Desktop\collect2.exe [Error] ld returned 1 exit status
|
So, the compiler options are:
Quote: |
- C Compiler: C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\gcc.exe
- Command: gcc.exe "C:\Users\user\Desktop\custom-handler.c" -o "C:\Users\user\Desktop\custom-handler.exe" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include" -I"C:\wamp\bin\apache\apache2.4.23\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib" -L"C:\wamp\bin\apache\apache2.4.23\include" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib" -static-libgcc -shared -fpic
|
I know there is a little messup with libraries, but that's because I was trying different ways to solve my problem...
And finaly, my code:
Code: |
/* Include the required headers from httpd */
#include <httpd.h>
#include <http_config.h>
#include <http_protocol.h>
#include <ap_config.h>
#include <http_core.h>
#include <http_request.h>
/* Define prototypes of our functions in this module */
static void register_hooks(apr_pool_t *pool);
static int custom_handler(request_rec *r);
/* Define our module as an entity and assign a function for registering hooks */
module AP_MODULE_DECLARE_DATA example_module =
{
STANDARD20_MODULE_STUFF,
NULL, // Per-directory configuration handler
NULL, // Merge handler for per-directory configurations
NULL, // Per-server configuration handler
NULL, // Merge handler for per-server configurations
NULL, // Any directives we may have for httpd
register_hooks // Our hook registering function
};
/* register_hooks: Adds a hook to the httpd process */
static void register_hooks(apr_pool_t *pool){
/* Hook the request handler */
ap_hook_handler(custom_handler, NULL, NULL, APR_HOOK_LAST);
}
/* The handler function for our module.
* This is where all the fun happens!
*/
static int custom_handler(request_rec *r){
/* First off, we need to check if this is a call for the "example" handler.
* If it is, we accept it and do our things, it not, we simply return DECLINED,
* and Apache will try somewhere else.
*/
if (!r->handler || strcmp(r->handler, "custom-handler")) return (DECLINED);
// The first thing we will do is write a simple "Hello, world!" back to the client.
ap_rputs("Hello, world!<br/>", r);
return OK;
}
|
I know the main code needs a header before printing anything (I was just trying to compile at this point).
Can anyone help me a bit, please? :D Any other information you will need just say it and I'll give it...
Thank you!! |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Fri 17 Feb '17 18:44 Post subject: |
|
|
I've never used gcc but
-I"C:\wamp\bin\apache\apache2.4.23\include" correct
-L"C:\wamp\bin\apache\apache2.4.23\include" incorrect, try
-L"C:\wamp\bin\apache\apache2.4.23\lib"
You need to link to libhttpd.lib (where the ap_* functions are) and you may also need libapr-1.lib and maybe even libaprutil-1.lib. All are located in Apache's /lib folder. |
|
Back to top |
|
DoHITB
Joined: 16 Feb 2017 Posts: 8 Location: Catalonia, Lleida
|
Posted: Fri 17 Feb '17 19:16 Post subject: |
|
|
Just added lib and same error. As I was trying, I reinstalled Apache and when compiling again an error prompted (I forgot it happened) saying that "include ap_config_auto.h cannot be found (on ap_config line 138).
Also a warning saying strcasecmp and strncasecmp are redefined... (apr_general line 117 - 127). The solution I found was commenting that parts, but maybe that caused my actual problem?
And just one thought: dev-cpp comes with more compilers than gcc, is recommended to use any other? |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Sat 18 Feb '17 0:08 Post subject: |
|
|
DoHITB wrote: | Just added lib and same error. As I was trying, I reinstalled Apache and when compiling again an error prompted (I forgot it happened) saying that "include ap_config_auto.h cannot be found (on ap_config line 138). |
That is a private header not included in C:\wamp\bin\apache\apache2.4.23\include but would have to be obtained by downloading Apache's source distribution. BUT, it actually is not needed as I built it from just what is included in a Apache binary distribution.
Quote: | Also a warning saying strcasecmp and strncasecmp are redefined... (apr_general line 117 - 127). The solution I found was commenting that parts, but maybe that caused my actual problem? |
If that actually allowed it to compile, the resulting module would never work in the server.
Quote: | And just one thought: dev-cpp comes with more compilers than gcc, is recommended to use any other? |
While it can be built with MinGW and msys or cygwin, that Apache at C:\wamp\bin\apache\apache2.4.23 was built with Visuall C++ 2015 also known as VC14.
I have built it with both VC11 & 14, x86 & x64 without warnings or errors at https://www.apachehaus.net/build/mod_example_build.zip
Built using the VC command prompts and the commands in the !buildme.txt file also included in the above zip.
Live demo: https://www.apachehaus.net/custom-module-example |
|
Back to top |
|
|
|
|
|
|