How do I fix the build for mod_mono when it cannot find strndup on FreeBSD?
Question
I am installing mod_mono with Apache 2 on FreeBSD and I get the following error when Apache tries to load the mod_mono.so module.
Cannot load /usr/local/apache/modules/mod_mono.so into server: /usr/local/apache/modules/mod_mono.so: Undefined symbol "strndup"
The prefix I set for Apache is /usr/local/apache and I have PHP and other modules working already. I found that strndup is referenced in roken.h in /usr/include and I tried the following additions to configure command but it did not work.
--libdir=/usr/lib --includedir=/usr/include
I also tried...
--with-mono-prefix=/usr
I do not know what to try next. It does not appear that mod_mono has many build options. Since Mono and XSP are both built successfully I just need mod_mono to work.
I appreciate any tips to get this working.
Solution
Add strndup via implementing it:
ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#if !_LIBC
# include "strndup.h"
#endif
#include <stdlib.h>
#include <string.h>
#if !_LIBC
# include "strnlen.h"
# ifndef __strnlen
# define __strnlen strnlen
# endif
#endif
#undef __strndup
#if _LIBC
# undef strndup
#endif
#ifndef weak_alias
# define __strndup strndup
#endif
char *
__strndup (s, n)
const char *s;
size_t n;
{
size_t len = __strnlen (s, n);
char *new = malloc (len + 1);
if (new == NULL)
return NULL;
new[len] = '\0';
return memcpy (new, s, len);
}
#ifdef libc_hidden_def
libc_hidden_def (__strndup)
#endif
#ifdef weak_alias
weak_alias (__strndup, strndup)
#endif