5

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

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

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

libsf_sip_preproc.so:未定义符号:sfxhash_new

我还编辑了 Makefile.am 并添加了该包的源代码(../YFolder/lib.c and lib.h);但没有效果。任何人都可以帮助我吗?

编辑:

我在文件夹 src/dynamic-preprocessor/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 @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
4

2 回答 2

2

Makefile.am文件中进行更改后,更改不会立即反映(即,如果您运行并且configuremake将看不到更改)。您应该首先生成/更新相应的Makefile.in文件。为此,您需要automake在源树的最顶层目录中运行命令(其中configure.inconfigure.ac驻留)。为确保Makefile.am包含新源的更改将成功反映在构建中,libsf_sip_preproc_la_SOURCESMakefile.am检查Makefile.in. 现在,运行configuremake命令。
请注意,将文件从源树中的一个位置添加到另一个位置可能会带来其自己的一组依赖项,即sfxhash源文件可能包含文件和链接到不作为Makefile.am问题的一部分的库,在这种情况下,您可能必须更新INCLUDES以包含源所需的目录和/或在libsf_sip_preproc_la_LIBADD. 避免在. .la_ 希望这可以帮助!.alibsf_sip_preproc_la_LIBADD

于 2012-05-07T18:00:21.633 回答
1

正如你所写:

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

如果 SO_WITH_STATIC_LIB 为真,我认为这一行:

libsf_sip_preproc_la_LIBADD = ../libsf_dynamic_preproc.la

应该

libsf_sip_preproc_la_LIBADD = ../libsf_dynamic_preproc.a

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

于 2012-05-07T16:08:56.533 回答