我正在尝试将PCRE库编译为测试可执行文件。

文档指出,运行Make然后进行配置应生成该库。

在PCRE源目录中:

Make
./configure
gcc -o test test.c -L . -lpcre


但是,以下错误返回:

/usr/bin/ld: cannot find -pcre
collect2: error: ld returned 1 exit status


注意:我也尝试过标记-libpcre。我能够在MacOS上成功运行它(分别编译,但相同的库源代码和相同的验证源代码)。

目录内容:



132html                            pcre16_globals.c
aclocal.m4                         pcre16_jit_compile.c
AUTHORS                            pcre16_maketables.c
ChangeLog                          pcre16_newline.c
CheckMan                           pcre16_ord2utf16.c
CleanTxt                           pcre16_printint.c
cmake                              pcre16_refcount.c
CMakeLists.txt                     pcre16_string_utils.c
compile                            pcre16_study.c
config-cmake.h.in                  pcre16_tables.c
config.guess                       pcre16_ucd.c
config.h                           pcre16_utf16_utils.c
config.h.generic                   pcre16_valid_utf16.c
config.h.in                        pcre16_version.c
config.log                         pcre16_xclass.c
config.status                      pcre32_byte_order.c
config.sub                         pcre32_chartables.c
configure                          pcre32_compile.c
configure.ac                       pcre32_config.c
COPYING                            pcre32_dfa_exec.c
depcomp                            pcre32_exec.c
Detrail                            pcre32_fullinfo.c
dftables.c                         pcre32_get.c
doc                                pcre32_globals.c
HACKING                            pcre32_jit_compile.c
INSTALL                            pcre32_maketables.c
install-sh                         pcre32_newline.c
libpcre16.pc                       pcre32_ord2utf32.c
libpcre16.pc.in                    pcre32_printint.c
libpcre32.pc                       pcre32_refcount.c
libpcre32.pc.in                    pcre32_string_utils.c
libpcrecpp.la                      pcre32_study.c
libpcrecpp_la-pcrecpp.lo           pcre32_tables.c
libpcrecpp_la-pcrecpp.o            pcre32_ucd.c
libpcrecpp_la-pcre_scanner.lo      pcre32_utf32_utils.c
libpcrecpp_la-pcre_scanner.o       pcre32_valid_utf32.c
libpcrecpp_la-pcre_stringpiece.lo  pcre32_version.c
libpcrecpp_la-pcre_stringpiece.o   pcre32_xclass.c
libpcrecpp.pc                      pcre_byte_order.c
libpcrecpp.pc.in                   pcre_chartables.c
libpcre.la                         pcre_chartables.c.dist
libpcre_la-pcre_byte_order.lo      pcre_compile.c
libpcre_la-pcre_byte_order.o       pcre-config
libpcre_la-pcre_chartables.lo      pcre_config.c
libpcre_la-pcre_chartables.o       pcre-config.in
libpcre_la-pcre_compile.lo         pcrecpparg.h
libpcre_la-pcre_compile.o          pcrecpparg.h.in
libpcre_la-pcre_config.lo          pcrecpp.cc
libpcre_la-pcre_config.o           pcrecpp.h
libpcre_la-pcre_dfa_exec.lo        pcrecpp_internal.h
libpcre_la-pcre_dfa_exec.o         pcrecpp_unittest
libpcre_la-pcre_exec.lo            pcrecpp_unittest.cc
libpcre_la-pcre_exec.o             pcrecpp_unittest-pcrecpp_unittest.o
libpcre_la-pcre_fullinfo.lo        pcredemo
libpcre_la-pcre_fullinfo.o         pcredemo.c
libpcre_la-pcre_get.lo             pcre_dfa_exec.c
libpcre_la-pcre_get.o              pcre_exec.c
libpcre_la-pcre_globals.lo         pcre_fullinfo.c
libpcre_la-pcre_globals.o          pcre_get.c
libpcre_la-pcre_jit_compile.lo     pcregexp.pas
libpcre_la-pcre_jit_compile.o      pcre_globals.c
libpcre_la-pcre_maketables.lo      pcregrep
libpcre_la-pcre_maketables.o       pcregrep.c
libpcre_la-pcre_newline.lo         pcregrep-pcregrep.o
libpcre_la-pcre_newline.o          pcre.h
libpcre_la-pcre_ord2utf8.lo        pcre.h.generic
libpcre_la-pcre_ord2utf8.o         pcre.h.in
libpcre_la-pcre_refcount.lo        pcre_internal.h
libpcre_la-pcre_refcount.o         pcre_jit_compile.c
libpcre_la-pcre_string_utils.lo    pcre_jit_test.c
libpcre_la-pcre_string_utils.o     pcre_maketables.c
libpcre_la-pcre_study.lo           pcre_newline.c
libpcre_la-pcre_study.o            pcre_ord2utf8.c
libpcre_la-pcre_tables.lo          pcreposix.c
libpcre_la-pcre_tables.o           pcreposix.h
libpcre_la-pcre_ucd.lo             pcre_printint.c
libpcre_la-pcre_ucd.o              pcre_refcount.c
libpcre_la-pcre_valid_utf8.lo      pcre_scanner.cc
libpcre_la-pcre_valid_utf8.o       pcre_scanner.h
libpcre_la-pcre_version.lo         pcre_scanner_unittest
libpcre_la-pcre_version.o          pcre_scanner_unittest.cc
libpcre_la-pcre_xclass.lo          pcre_scanner_unittest-pcre_scanner_unittest.o
libpcre_la-pcre_xclass.o           pcre_stringpiece.cc
libpcre.pc                         pcre_stringpiece.h
libpcre.pc.in                      pcre_stringpiece.h.in
libpcreposix.la                    pcre_stringpiece_unittest
libpcreposix_la-pcreposix.lo       pcre_stringpiece_unittest.cc
libpcreposix_la-pcreposix.o        pcre_stringpiece_unittest-pcre_stringpiece_unittest.o
libpcreposix.pc                    pcre_string_utils.c
libpcreposix.pc.in                 pcre_study.c
libtool                            pcre_tables.c
LICENCE                            pcretest
ltmain.sh                          pcre_test.c
m4                                 pcretest.c
Makefile                           pcretest-pcre_printint.o
Makefile.am                        pcretest-pcretest.o
Makefile.in                        pcre_ucd.c
makevp.bat                         pcre_valid_utf8.c
makevp_c.txt                       pcre_version.c
makevp_l.txt                       pcre_xclass.c
missing                            perltest.pl
NEWS                               PrepareRelease
NON-AUTOTOOLS-BUILD                README
NON-UNIX-USE                       RunGrepTest
pcre16_byte_order.c                RunTest
pcre16_chartables.c                RunTest.bat
pcre16_compile.c                   sljit
pcre16_config.c                    stamp-h1
pcre16_dfa_exec.c                  test.c
pcre16_exec.c                      testdata
pcre16_fullinfo.c                  ucp.h
pcre16_get.c

最佳答案

链接时,请尝试-lpcre而不是-libpcre。 -l假定使用lib前缀并使用lib的名称,因此-lpcre查找libpcre

关于c - GCC链接器找不到库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42447163/

10-11 21:04