5

I am working with an open source project called snort , which is written in C, under Linux. I opened project in netbeans correctly and now I am going to do some changes in this source code. The src folder of program contains several folders and also each folder has some folders. I heard that netbeans is able to generate make files. I am doing some changes in src files in folder XFolder and want to use a library function in another folder in my project (YFolder). I included .h file and used the function correctly.

#include"../YFolder/lib.h"

Now when I can compile the program, It is Ok, but when I use dynamic libraries ".so (shared object files)" that created in make process; and run program, I see an error that means the function I used from other folder not defined and see this error; (sfxhash_new is the name of external function that I called).

libsf_sip_preproc.so: undefined symbol: sfxhash_new

I also edited Makefile.am and added the sources of that package (../YFolder/lib.c and lib.h); But not effective. Can anyone help me please?

EDIT:

I am in folder src/dynamic-preprocessor/sip I want to use a function in file: src/sfutil/sfxHash.c the function name is sfxhash_new(... ... ...) I included sfxHash.h correctly. I did some changes In my Makefile.am but the main makefile is this.

My Makefile.am file:

## $Id
AUTOMAKE_OPTIONS=foreign no-dependencies

INCLUDES = -I../include -I${srcdir}/../libs -I$(srcdir)/includes

libdir = ${exec_prefix}/lib/snort_dynamicpreprocessor

lib_LTLIBRARIES = libsf_sip_preproc.la

libsf_sip_preproc_la_LDFLAGS = -shared -export-dynamic -module @XCCFLAGS@
if SO_WITH_STATIC_LIB
libsf_sip_preproc_la_LIBADD = ../libsf_dynamic_preproc.la
else
nodist_libsf_sip_preproc_la_SOURCES = \
../include/sf_dynamic_preproc_lib.c \
../include/sf_ip.c \

endif

libsf_sip_preproc_la_SOURCES = \
spp_sip.c \
spp_sip.h \
sip_config.c \
sip_config.h \
sip_parser.c \
sip_parser.h \
sip_dialog.c \
sip_dialog.h \
sip_roptions.c \
sip_roptions.h \
sip_utils.c \
sip_utils.h \
sip_debug.h \
../include/sfxhash.c \   -----------------> I have copied src files in this dictionary
../include/sfxhash.h     ------------------>

EXTRA_DIST = \
sf_sip.dsp

all-local: $(LTLIBRARIES)
    $(MAKE) DESTDIR=`pwd`/../build install-libLTLIBRARIES
sajad
  • 1,895
  • 11
  • 29
  • 49
  • You have to put the '-lnet -lpcre' etc. flags to the very end of LDFLAGS, did you do it? –  May 06 '12 at 04:02
  • 1
    This might help too [here](http://stackoverflow.com/questions/480764/linux-error-while-loading-shared-libraries-cannot-open-shared-object-file-no-s) – ervinbosenbacher May 06 '12 at 04:04
  • 3
    Also note that 'undefined symbol' errors have nothing to do with correct or incorrect header file inclusion; they're linker errors and show that some libraries are missing. –  May 06 '12 at 04:05
  • @H2CO3 there is (-shared -export-dynamic -module @XCCFLAGS@ if SO_WITH_STATIC_LIB) flags after LDFLAGS. I added this in Makefile.am and configured my project again; then I make that package.. But steel I see that error! – sajad May 06 '12 at 04:08
  • Then show us your exact directory layout and the whole makefile. –  May 06 '12 at 04:10
  • How can I link external library function correctly in this part of project? make file contains (AUTOMAKE_OPTIONS=foreign no-dependencies) in first line – sajad May 06 '12 at 04:10
  • @H2CO3: I added my make file If another this is necessary please tell me. – sajad May 06 '12 at 04:17
  • @xebo: Thank you Mr. But the .so file is correctly located and I specified it for my program. I also did some changes successfully in my src files; but when I want to use another part of my program, I have this problem. – sajad May 06 '12 at 04:29
  • [Here](http://stackoverflow.com/questions/34732/how-do-i-list-the-symbols-in-a-so-file) is an earlier post that helps you how to examine the .so file, what symbols it exports. – ervinbosenbacher May 06 '12 at 04:48
  • @xebo: Thank you; Your prior link was useful about Linker and Libraries to me. – sajad May 06 '12 at 04:52
  • @sajad: No problem. :) Keep up. :) – ervinbosenbacher May 06 '12 at 04:59

2 Answers2

2

After making changes in Makefile.am file, the changes are not reflected immediately (i.e. if you run configure & make you will not see the changes). You should generate/update the corresponding Makefile.in file first. For that you need to run automake command in the topmost directory of the source tree (where configure.in or configure.ac resides). To make sure that your Makefile.am changes to include new sources will successfully be reflected in the build, check that libsf_sip_preproc_la_SOURCES is same set of files in Makefile.am as well as Makefile.in. Now, run configure and make commands.
Note that adding a file from one place to another in the source tree may bring in its own set of dependencies i.e. sfxhash source files may include files & link to libraries which are not present as part of Makefile.am in question, in which case you may have to update INCLUDES to include the directory needed by the source and/or add new libraries in libsf_sip_preproc_la_LIBADD. Avoid mixing .la & .a files in libsf_sip_preproc_la_LIBADD.
Hope this helps!

another.anon.coward
  • 10,167
  • 1
  • 28
  • 35
1

As you have written:

libsf_sip_preproc_la_LDFLAGS = -shared -export-dynamic -module @XCCFLAGS@
if SO_WITH_STATIC_LIB
libsf_sip_preproc_la_LIBADD = ../libsf_dynamic_preproc.la
else
nodist_libsf_sip_preproc_la_SOURCES = \
../include/sf_dynamic_preproc_lib.c \
../include/sf_ip.c \

endif

if SO_WITH_STATIC_LIB is true, I think this line:

libsf_sip_preproc_la_LIBADD = ../libsf_dynamic_preproc.la

should be

libsf_sip_preproc_la_LIBADD = ../libsf_dynamic_preproc.a

that is my idea, you can try it.

MYMNeo
  • 770
  • 4
  • 9
  • 1
    That is not correct. `.la` file are libtool archive files, these are used by `libtool` to generate both static & dynamic libraries as per need – another.anon.coward May 07 '12 at 17:52