Compiling in FreeBSD 10

Issue #284 resolved
J B created an issue

i installed all the prereqs. (i also had to

ln -s /usr/local/include/tre /usr/include/tre

for the configure to find tre.)

gmake gives errors about the includes:

$ gmake
Making all in src
cc -O2 -Wall -g -c dirs.c
dirs.c:13:10: error: 'piler.h' file not found with <angled> include; use "quotes" instead
#include <piler.h>
         ^~~~~~~~~
         "piler.h"
In file included from dirs.c:13:
./piler.h:8:10: error: 'misc.h' file not found with <angled> include; use "quotes" instead
#include <misc.h>
         ^~~~~~~~
         "misc.h"
In file included from dirs.c:13:
In file included from ./piler.h:8:
./misc.h:11:10: error: 'cfg.h' file not found with <angled> include; use "quotes" instead
#include <cfg.h>
         ^~~~~~~
         "cfg.h"
In file included from dirs.c:13:
In file included from ./piler.h:8:
In file included from ./misc.h:11:
In file included from ./cfg.h:8:
./config.h:9:10: fatal error: 'piler-config.h' file not found
#include "piler-config.h"
         ^
4 errors generated.
*** Error code 1

Stop.
make[1]: stopped in /usr/home/piler/piler-0.1.24/src
gmake: *** [all-recursive] Error 1

i went in and changed all of the includes it was complaining about to quotes. now when i gmake it returns this:

Making all in src
cc -O2 -Wall -g -c dirs.c
In file included from dirs.c:13:
In file included from ./piler.h:8:
./misc.h:41:26: warning: declaration of 'struct sockaddr' will not be visible outside of this function [-Wvisibility]
void *get_in_addr(struct sockaddr *sa);
                         ^
In file included from dirs.c:13:
In file included from ./piler.h:20:
./sql.h:11:55: error: unknown type name 'MYSQL_STMT'
int prepare_sql_statement(struct session_data *sdata, MYSQL_STMT **stmt, char *s);
                                                      ^
./sql.h:13:46: error: unknown type name 'MYSQL_STMT'
int p_exec_query(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *data);
                                             ^
./sql.h:14:49: error: unknown type name 'MYSQL_STMT'
int p_store_results(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *data);
                                                ^
./sql.h:15:21: error: unknown type name 'MYSQL_STMT'
int p_fetch_results(MYSQL_STMT *stmt);
                    ^
./sql.h:16:21: error: unknown type name 'MYSQL_STMT'
void p_free_results(MYSQL_STMT *stmt);
                    ^
./sql.h:18:24: error: unknown type name 'MYSQL_STMT'
uint64 p_get_insert_id(MYSQL_STMT *stmt);
                       ^
./sql.h:19:25: error: unknown type name 'MYSQL_STMT'
int p_get_affected_rows(MYSQL_STMT *stmt);
                        ^
./sql.h:20:31: error: unknown type name 'MYSQL_STMT'
void close_prepared_statement(MYSQL_STMT *stmt);
                              ^
1 warning and 8 errors generated.
*** Error code 1

Stop.
make[1]: stopped in /usr/home/piler/piler-0.1.24/src
gmake: *** [all-recursive] Error 1

Comments (13)

  1. Janos SUTO repo owner

    I think that cc misses the -I. and other options, ie. cc -O2 -Wall -g -c dirs.c -I. -I..

  2. Jason Jorgensen

    Any progress on this? Im getting the same error with 0.1.24 trying to compile this on FreeBSD 10. I also tried 0.1.25-rc2 and it does the same thing.

    env CPPFLAGS="-I. -I.. -I/usr/include -I/usr/local/include -I/usr/include/mysql" LDFLAGS="-L/usr/local/include -L/usr/include/mysql" ./configure --localstatedir=/var --with-database=mysql --enable-starttls --enable-tcpwrappers
    
    gmake
    Making all in src
    cc -O2 -Wall -g -I. -I.. -I/usr/include -I/usr/local/include -I/usr/include/mysql -c dirs.c
    In file included from dirs.c:13:
    In file included from ./piler.h:8:
    ./misc.h:41:26: warning: declaration of 'struct sockaddr' will not be visible outside of this function [-Wvisibility]
    void *get_in_addr(struct sockaddr *sa);
                             ^
    In file included from dirs.c:13:
    In file included from ./piler.h:20:
    ./sql.h:11:55: error: unknown type name 'MYSQL_STMT'
    int prepare_sql_statement(struct session_data *sdata, MYSQL_STMT **stmt, char *s);
                                                          ^
    ./sql.h:13:46: error: unknown type name 'MYSQL_STMT'
    int p_exec_query(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *data);
                                                 ^
    ./sql.h:14:49: error: unknown type name 'MYSQL_STMT'
    int p_store_results(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *data);
                                                    ^
    ./sql.h:15:21: error: unknown type name 'MYSQL_STMT'
    int p_fetch_results(MYSQL_STMT *stmt);
                        ^
    ./sql.h:16:21: error: unknown type name 'MYSQL_STMT'
    void p_free_results(MYSQL_STMT *stmt);
                        ^
    ./sql.h:18:24: error: unknown type name 'MYSQL_STMT'
    uint64 p_get_insert_id(MYSQL_STMT *stmt);
                           ^
    ./sql.h:19:25: error: unknown type name 'MYSQL_STMT'
    int p_get_affected_rows(MYSQL_STMT *stmt);
                            ^
    ./sql.h:20:31: error: unknown type name 'MYSQL_STMT'
    void close_prepared_statement(MYSQL_STMT *stmt);
                                  ^
    1 warning and 8 errors generated.
    *** Error code 1
    
    Stop.
    make[1]: stopped in /root/mailpiler/piler-0.1.24/src
    gmake: *** [all-recursive] Error 1
    
  3. Jason Jorgensen

    I dont know C for crap. Just a dirty hack.

    But I was screwing around and it seems the defines from configure "HAVE_TRE" and "NEED_MYSQL" aren't visible anymore when make is compiling. I have no idea why.

    MYSQL_STMT type should be provided by mysql.h, so it seemed it wasn't actually being included. And its inclusion was dependent on the define NEED_MYSQL.

    I added a #define at the top of each file that uses HAVE_TRE and NEED_MYSQL. The compile went much further after that, but then run in to a different error.

    diff -ur piler-0.1.24/src/defs.h piler-0.1.24-modified/src/defs.h
    --- piler-0.1.24/src/defs.h 2013-09-02 10:45:43.000000000 +0000
    +++ piler-0.1.24-modified/src/defs.h    2014-07-22 13:54:50.504105052 +0000
    @@ -2,11 +2,13 @@
      * defs.h, SJ
      */
    
    +#define NEED_MYSQL yes
    +#define HAVE_TRE yes
    +
     #ifndef _DEFS_H
        #define _DEFS_H
    -
     #ifdef NEED_MYSQL
    -  #include <mysql.h>
    +  #include <mysql/mysql.h>
     #endif
     #ifdef NEED_PSQL
       #include <libpq-fe.h>
    
    
    diff -ur piler-0.1.24/src/retr.c piler-0.1.24-modified/src/retr.c
    --- piler-0.1.24/src/retr.c 2013-09-02 10:45:43.000000000 +0000
    +++ piler-0.1.24-modified/src/retr.c    2014-07-22 13:52:58.022115031 +0000
    @@ -18,6 +18,7 @@
     #include <openssl/err.h>
     #include <piler.h>
    
    +#define NEED_MYSQL yes
    
     int stat_file(struct session_data *sdata, char *f, char **buf, int buflen, struct __config *cfg){
        struct stat st;
    
    
    diff -ur piler-0.1.24/src/session.c piler-0.1.24-modified/src/session.c
    --- piler-0.1.24/src/session.c  2013-09-02 10:45:43.000000000 +0000
    +++ piler-0.1.24-modified/src/session.c 2014-07-22 13:52:42.277115465 +0000
    @@ -18,6 +18,7 @@
     #include <openssl/err.h>
     #include <piler.h>
    
    +#define NEED_MYSQL yes
    
     int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
        int i, ret, pos, n, inj=ERR, state, prevlen=0;
    

    New error:

    ...
    cc -O2 -Wall -g -I. -I.. -I/usr/include -I/usr/local/include -I/usr/include/mysql -c retr.c
    cc -O2 -Wall -g -I. -I.. -I/usr/include -I/usr/local/include -I/usr/include/mysql -c mysql.c
    ar cr libpiler.a dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o retr.o mysql.o
    ranlib libpiler.a
    cc -shared -o libpiler.so.0.1.1 dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o retr.o mysql.o
    /usr/bin/ld: dirs.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
    dirs.o: could not read symbols: Bad value
    cc: error: linker command failed with exit code 1 (use -v to see invocation)
    *** Error code 1
    
    Stop.
    make[1]: stopped in /root/mailpiler/piler-0.1.24/src
    gmake: *** [all-recursive] Error 1
    
  4. Jason Jorgensen

    Apparently you dont need the -ldl on freebsd? Another coder mentioned that elsewhere. Removing that from the configure script.

    Now I get,

    /usr/bin/ld: cannot find -ltre
    cc: error: linker command failed with exit code 1 (use -v to see invocation)
    *** Error code 1
    

    BAH. Perhaps this just wasnt meant to be.

  5. Jason Jorgensen

    Also removed references to '-lnsl' from configure as per

    "-lnsl is another one you can remove - it is included in libc in FreeBSD."

    env CPPFLAGS="-I. -I.. -I/usr/include -I/usr/local/include -I/usr/include/mysql -fPIC" LDFLAGS="-L/usr/local/lib -L/usr/include/mysql" ./configure --localstatedir=/var --with-database=mysql --enable-starttls --enable-tcpwrappers
    

    That picks up the libtre now.

    Also had to add '-liconv' to the libs. I shoved it on the antispam_libs because.... it was convenient.

    Making all in test
    cc -O2 -Wall -g -I. -I.. -I/usr/include -I/usr/local/include -I/usr/include/mysql -fPIC -c import_helper.c
    import_helper.c:17:10: fatal error: 'piler.h' file not found
    #include <piler.h>
             ^
    1 error generated.
    *** Error code 1
    

    Sorry I'm spamming. I just want the changes im making documented and if it helps you get this working on freebsd, YAY!

  6. Jason Jorgensen

    I havent tested the program or anything, but after my changes and the following ugly configure line it finally compiled with no errors.

    env CPPFLAGS="-I. -I.. -I/usr/include -I/usr/local/include -I/usr/include/mysql -I../.. -I../../src -I../src -fPIC" LDFLAGS="-L/usr/local/lib -L/usr/include/mysql" ./configure --localstatedir=/var --with-database=mysql --enable-starttls --enable-tcpwrappers
    
    diff -ur piler-0.1.24/configure piler-0.1.24-modified/configure
    --- piler-0.1.24/configure  2013-09-02 10:45:43.000000000 +0000
    +++ piler-0.1.24-modified/configure 2014-07-22 14:51:02.512874407 +0000
    @@ -3455,7 +3455,7 @@
    
     have_static_build="no"
    
    -antispam_libs="-lz -lm -ldl -lcrypto -lssl"
    +antispam_libs="-lz -lm -lcrypto -lssl -liconv"
     defs=""
     objs=""
     user_obj=""
    @@ -4289,7 +4289,6 @@
     fi
    
    
    -
           if test x$MYSQL_CONFIG = xyes; then
              have_mysql="yes"
           fi
    @@ -4538,7 +4537,7 @@
    
     $as_echo "#define HAVE_DAEMON 0" >>confdefs.h
    
    -   sunos_libs="-lnsl -lsocket"
    +   sunos_libs="-lsocket"
    
        if test -x /usr/xpg4/bin/id; then id_bin="/usr/xpg4/bin/id"; fi
     fi
    @@ -4613,7 +4612,7 @@
     #define HAVE_LIBWRAP 1
     _ACEOF
    
    -   antispam_libs="$antispam_libs -lwrap -lnsl"
    +   antispam_libs="$antispam_libs -lwrap"
     else
        echo "tcpwrappers support: no"
     fi
    diff -ur piler-0.1.24/configure.in piler-0.1.24-modified/configure.in
    --- piler-0.1.24/configure.in   2013-09-02 10:45:43.000000000 +0000
    +++ piler-0.1.24-modified/configure.in  2014-07-22 14:27:55.757970285 +0000
    @@ -56,7 +56,7 @@
    
     have_static_build="no"
    
    -antispam_libs="-lz -lm -ldl -lcrypto -lssl"
    +antispam_libs="-lz -lm -lcrypto -lssl"
     defs=""
     objs=""
     user_obj=""
    
    
    diff -ur piler-0.1.24/src/defs.h piler-0.1.24-modified/src/defs.h
    --- piler-0.1.24/src/defs.h 2013-09-02 10:45:43.000000000 +0000
    +++ piler-0.1.24-modified/src/defs.h    2014-07-22 14:21:30.987996798 +0000
    @@ -2,11 +2,17 @@
      * defs.h, SJ
      */
    
    +#ifndef NEED_MYSQL
    +   #define NEED_MYSQL yes
    +#endif
    +#ifndef HAVE_TRE
    +   #define HAVE_TRE yes
    +#endif
    +
     #ifndef _DEFS_H
        #define _DEFS_H
    -
     #ifdef NEED_MYSQL
    -  #include <mysql.h>
    +  #include <mysql/mysql.h>
     #endif
     #ifdef NEED_PSQL
       #include <libpq-fe.h>
    
    
    diff -ur piler-0.1.24/src/retr.c piler-0.1.24-modified/src/retr.c
    --- piler-0.1.24/src/retr.c 2013-09-02 10:45:43.000000000 +0000
    +++ piler-0.1.24-modified/src/retr.c    2014-07-22 14:20:43.028000155 +0000
    @@ -18,6 +18,9 @@
     #include <openssl/err.h>
     #include <piler.h>
    
    +#ifndef NEED_MYSQL
    +   #define NEED_MYSQL yes
    +#endif
    
     int stat_file(struct session_data *sdata, char *f, char **buf, int buflen, struct __config *cfg){
        struct stat st;
    
    
    diff -ur piler-0.1.24/src/session.c piler-0.1.24-modified/src/session.c
    --- piler-0.1.24/src/session.c  2013-09-02 10:45:43.000000000 +0000
    +++ piler-0.1.24-modified/src/session.c 2014-07-22 14:20:51.359001070 +0000
    @@ -18,6 +18,9 @@
     #include <openssl/err.h>
     #include <piler.h>
    
    +#ifndef NEED_MYSQL
    +   #define NEED_MYSQL yes
    +#endif
    
     int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
        int i, ret, pos, n, inj=ERR, state, prevlen=0;
    
  7. Janos SUTO repo owner

    Hello Jason, feel free to experiment with the compilation. However I've also played with a fresh Freebsd 10.0 install, and managed to make it. This is how.

    Firstly, you need to download the latest master branch, I've just updated it to support compiling on Freebsd.

    You also need the following packages from the ports collection (I assume, you have it):

    textproc/libtre textproc/unrtf textproc/catdoc archivers/libzip database/mysql56-client (You may pick a different mysql version if you prefer)

    Then run the following:

    LDFLAGS="-L/usr/local/lib" CPPFLAGS="-I/usr/local/include" ./configure --localstatedir=/var --with-database=mysql --enable-tcpwrappers --enable-starttls

    And finally use "gmake" instead of the usual bsd make, eg.

    gmake clean all

    This should compile piler (with some warnings). Let me know if you can make it.

  8. Jason Jorgensen

    Thank you very much for fixing that!

    I still get 1 error when compiling the master branch as of today.

    cc -O2 -Wall -g -I/usr/local/include -I. -I..  -I/usr/local/include/mysql -pipe -fno-strict-aliasing -g -DNDEBUG -DFREEBSD -DHAVE_TRE -DNEED_MYSQL -o piler piler.c -lpiler -lz -lm -lcrypto -lssl -ltre -lzip -lwrap   -L/usr/local/lib/mysql   -lmysqlclient_r  -pthread -lz -lm -L.  -L/usr/local/lib -L/usr/local/lib 
    ./libpiler.so: undefined reference to `libiconv'
    ./libpiler.so: undefined reference to `libiconv_close'
    ./libpiler.so: undefined reference to `libiconv_open'
    cc: error: linker command failed with exit code 1 (use -v to see invocation)
    gmake[1]: *** [piler] Error 1
    

    ./configure says i should be able to supply LIBS="-liconv" but it doesnt seem to pick up that environment variable.

    If I add LIBS="-liconv $LIBS" in configure, then it will compile for me on a fresh freebsd 10 install.

  9. Jason Jorgensen

    Also the make install fails trying to put init scripts in /etc/init.d instead of /usr/local/etc/rc.d/

  10. Janos SUTO repo owner

    How about instead of LIBS="-liconv", try adding it to LDFLAGS, eg. LDFLAGS="-liconv -L/usr/local/lib".

  11. Log in to comment