Hello,
I am trying to run the test.c connector to see what Modsecurity version 3 is, and having following error while compiling test.c.
https://github.com/SpiderLabs/ModSecurity/blob/v3/master/examples/simple_example_using_c/test.c <https://github.com/SpiderLabs/ModSecurity/blob/v3/master/examples/simple_example_using_c/test.c>
I used Ubuntsu 17.10 also CentOS 7 Minimal and basically got the same problem.
And followed the recipe (note: I added pkg-config).
https://github.com/SpiderLabs/ModSecurity/wiki/Compilation-recipes <https://github.com/SpiderLabs/ModSecurity/wiki/Compilation-recipes>
$ sudo apt-get install g++ flex bison curl doxygen libyajl-dev libgeoip-dev libtool dh-autoreconf libcurl4-gnutls-dev libxml2 libpcre++-dev libxml2-dev pkg-config
$ cd /opt/
$ git clone https://github.com/SpiderLabs/ModSecurity
$ cd ModSecurity/
$ git checkout -b v3/master origin/v3/master
$ sh build.sh
$ git submodule init
$ git submodule update #[for bindings/python, others/libinjection, test/test-cases/secrules-language-tests]
$ ./configure
$ make
$ make install
Here is some more details from my Ubuntsu.
When I compile test.c, I get following errors.
root@ubuntu:/opt/ModSecurity/examples/simple_example_using_c# gcc -W test.c -o foo.o -L/usr/local/modsecurity/lib -I/opt/ModSecurity/headers/modsecurity/
/tmp/ccCMawz3.o: In function `main':
test.c:(.text+0x34): undefined reference to `msc_init'
test.c:(.text+0x4b): undefined reference to `msc_set_connector_info'
test.c:(.text+0x55): undefined reference to `msc_create_rules_set'
test.c:(.text+0x70): undefined reference to `msc_rules_add_file'
test.c:(.text+0xc9): undefined reference to `msc_rules_dump'
test.c:(.text+0xea): undefined reference to `msc_rules_add_remote'
test.c:(.text+0x143): undefined reference to `msc_rules_dump'
test.c:(.text+0x15b): undefined reference to `msc_new_transaction'
test.c:(.text+0x184): undefined reference to `msc_process_connection'
test.c:(.text+0x1a5): undefined reference to `msc_process_uri'
test.c:(.text+0x1b1): undefined reference to `msc_process_request_headers'
test.c:(.text+0x1bd): undefined reference to `msc_process_request_body'
test.c:(.text+0x1d5): undefined reference to `msc_process_response_headers'
test.c:(.text+0x1e1): undefined reference to `msc_process_response_body'
test.c:(.text+0x1ed): undefined reference to `msc_process_logging'
test.c:(.text+0x1f9): undefined reference to `msc_rules_cleanup'
test.c:(.text+0x205): undefined reference to `msc_cleanup'
collect2: error: ld returned 1 exit status
I verified library is installed, header files are in the specified path.
root@ubuntu:/opt/ModSecurity/examples/simple_example_using_c# ls -al /usr/local/modsecurity/lib
total 174360
drwxr-xr-x 2 root root 4096 Dec 16 09:58 .
drwxr-xr-x 5 root root 4096 Dec 11 16:42 ..
-rw-r--r-- 1 root root 141791210 Dec 16 09:58 libmodsecurity.a
-rwxr-xr-x 1 root root 1094 Dec 16 09:58 libmodsecurity.la
lrwxrwxrwx 1 root root 23 Dec 16 09:58 libmodsecurity.so -> libmodsecurity.so.3.0.0
lrwxrwxrwx 1 root root 23 Dec 16 09:58 libmodsecurity.so.3 -> libmodsecurity.so.3.0.0
-rwxr-xr-x 1 root root 36736752 Dec 16 09:58 libmodsecurity.so.3.0.0
root@ubuntu:/opt/ModSecurity/examples/simple_example_using_c#
root@ubuntu:/opt/ModSecurity/examples/simple_example_using_c# ls -al /opt/ModSecurity/headers/modsecurity/
total 112
drwxr-xr-x 4 root root 4096 Dec 18 01:55 .
drwxr-xr-x 3 root root 4096 Dec 16 10:00 ..
drwxr-xr-x 2 root root 4096 Dec 11 16:28 actions
-rw-r--r-- 1 root root 2622 Dec 11 16:28 anchored_set_variable.h
-rw-r--r-- 1 root root 1802 Dec 11 16:28 anchored_variable.h
-rw-r--r-- 1 root root 5732 Dec 11 16:28 audit_log.h
drwxr-xr-x 2 root root 4096 Dec 11 16:28 collection
-rw-r--r-- 1 root root 1403 Dec 11 16:28 debug_log.h
-rw-r--r-- 1 root root 1649 Dec 11 16:28 intervention.h
-rw-r--r-- 1 root root 8403 Dec 11 16:28 modsecurity.h
-rw-r--r-- 1 root root 3571 Dec 11 16:28 rule.h
-rw-r--r-- 1 root root 3203 Dec 11 16:28 rule_message.h
-rw-r--r-- 1 root root 2493 Dec 11 16:28 rules_exceptions.h
-rw-r--r-- 1 root root 2555 Dec 11 16:28 rules.h
-rw-r--r-- 1 root root 14789 Dec 11 16:28 rules_properties.h
-rw-r--r-- 1 root root 20688 Dec 11 16:28 transaction.h
-rw-r--r-- 1 root root 1220 Dec 11 16:28 variable_origin.h
Then, I tried the installation process again and reviewed the outputs.
Full output is on Gist
https://gist.github.com/jussmen/33cc70b76f21dc4d7a01743a02b15202 <https://gist.github.com/jussmen/33cc70b76f21dc4d7a01743a02b15202>
I noticed that it says I should add LIBDIR into LD_LIBRARY_PATH and LD_RUN_PATH.
So I checked what path is specified in LIBDIR after the installation process, and found it is empty on my Ubuntsu.
root@ubuntu:/opt/ModSecurity# echo $LIBDIR
root@ubuntu:/opt/ModSecurity#
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/modsecurity/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the 'LD_RUN_PATH' environment variable
during linking
- use the '-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to '/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
I guess I should have something with LIBDIR and that is why compelling test.c returns 'undefined reference to’ errors ?
I appreciate any guidance.
Regards,
Kimi. |