2012-05-06 37 views
5

我正在开发一个名为snort的开源项目,它是用C语言编写的,在Linux下。我正确地在netbeans中打开了项目,现在我将对此源代码进行一些更改。程序的src文件夹包含多个文件夹,每个文件夹也有一些文件夹。我听说netbeans能够生成make文件。我正在对文件夹XFolder中的src文件进行一些更改,并希望在我的项目(YFolder)中的另一个文件夹中使用库函数。我包含了.h文件并正确使用了该功能。在C中包含头文件并编译

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

现在,当我可以编译该程序,这是好的,但是,当我使用动态库“所以(共享对象文件)”,在化妆过程创建的;并运行程序,我看到一个错误,这意味着我从其他文件夹中使用的功能未定义,看到这个错误; (sfxhash_new是我调用的外部函数的名称)。

libsf_sip_preproc.so:未定义符号:sfxhash_new

我还编辑Makefile.am并补充说封装(../YFolder/lib.c and lib.h)的来源;但没有效果。任何人都可以帮助我吗?

编辑:

我在文件夹中的src /动态预处理器/ SIP 我想用在文件中的函数:SRC/sfutil/sfxHash.c 函数名sfxhash_new(... .. ...) 我正确包含了sfxHash.h。 我做了一些更改在我的Makefile.am中,但主makefile是这样的。

我的Makefile.am文件:

## $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 @[email protected] 
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 
+0

你必须把'-lnet -lpcre'等标​​志放在LDFLAGS的最后,你做了吗? – 2012-05-06 04:02:10

+1

这可能也有帮助[here](http://stackoverflow.com/questions/480764/linux-error-while-loading-shared-libraries-cannot-open-shared-object-file-no-s) – ervinbosenbacher

+3

另请注意'未定义符号'错误与正确或不正确的头文件包含无关;他们是链接器错误,并显示一些库缺失。 – 2012-05-06 04:05:30

回答

1

当你写:

libsf_sip_preproc_la_LDFLAGS = -shared -export-dynamic -module @[email protected] 
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 

如果SO_WITH_STATIC_LIB是真的,我觉得这条线:

libsf_sip_preproc_la_LIBADD = ../libsf_dynamic_preproc.la 

应该

libsf_sip_preproc_la_LIBADD = ../libsf_dynamic_preproc.a 

这是我的想法,你可以试试看。

+1

这是不正确的。 '.la'文件是libtool档案文件,'libtool'用来根据需要生成静态和动态库 –

2

在对Makefile.am文件进行更改后,更改不会立即反映出来(即,如果您运行的是configure & make则不会看到更改)。您应该首先生成/更新相应的Makefile.in文件。为此,您需要在源树的最顶层目录(其中configure.inconfigure.ac所在的位置)运行automake命令。为确保您的Makefile.am更改为包含新源,将成功反映在构建中,请检查libsf_sip_preproc_la_SOURCESMakefile.am以及Makefile.in中的同一组文件。现在运行configuremake命令。
请注意,将源文件从一个地方添加到另一个地方可能会引入其自己的一组依赖关系,即sfxhash源文件可能包含文件&链接到不存在作为Makefile.am问题的一部分的库,在这种情况下,您可能必须更新INCLUDES以包含源所需的目录和/或在libsf_sip_preproc_la_LIBADD中添加新库。避免混合.la & .a文件在libsf_sip_preproc_la_LIBADD
希望这有助于!