- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个使用 PCRE 库的简单代码。我只是想知道有关 pcre 的 c 代码,因此从 http://www.mitchr.me/SS/exampleCode/AUPG/pcre_example.c.html 复制了代码
#include <pcre.h> /* PCRE lib NONE */
#include <stdio.h> /* I/O lib C89 */
#include <stdlib.h> /* Standard Lib C89 */
#include <string.h> /* Strings C89 */
/**********************************************************************************************************************************/
int main(int argc, char *argv[]) {
pcre *reCompiled;
pcre_extra *pcreExtra;
int pcreExecRet;
int subStrVec[30];
const char *pcreErrorStr;
int pcreErrorOffset;
char *aStrRegex;
char **aLineToMatch;
const char *psubStrMatchStr;
int j;
char *testStrings[] = { "This should match... hello",
"This could match... hello!",
"More than one hello.. hello",
"No chance of a match...",
NULL};
aStrRegex = "(.*)(hello)+";
printf("Regex to use: %s\n", aStrRegex);
// First, the regex string must be compiled.
reCompiled = pcre_compile(aStrRegex, 0, &pcreErrorStr, &pcreErrorOffset, NULL);
/* OPTIONS (second argument) (||'ed together) can be:
PCRE_ANCHORED -- Like adding ^ at start of pattern.
PCRE_CASELESS -- Like m//i
PCRE_DOLLAR_ENDONLY -- Make $ match end of string regardless of \n's
No Perl equivalent.
PCRE_DOTALL -- Makes . match newlins too. Like m//s
PCRE_EXTENDED -- Like m//x
PCRE_EXTRA --
PCRE_MULTILINE -- Like m//m
PCRE_UNGREEDY -- Set quantifiers to be ungreedy. Individual quantifiers
may be set to be greedy if they are followed by "?".
PCRE_UTF8 -- Work with UTF8 strings.
*/
// pcre_compile returns NULL on error, and sets pcreErrorOffset & pcreErrorStr
if(reCompiled == NULL) {
printf("ERROR: Could not compile '%s': %s\n", aStrRegex, pcreErrorStr);
exit(1);
} /* end if */
// Optimize the regex
pcreExtra = pcre_study(reCompiled, 0, &pcreErrorStr);
/* pcre_study() returns NULL for both errors and when it can not optimize the regex. The last argument is how one checks for
errors (it is NULL if everything works, and points to an error string otherwise. */
if(pcreErrorStr != NULL) {
printf("ERROR: Could not study '%s': %s\n", aStrRegex, pcreErrorStr);
exit(1);
} /* end if */
for(aLineToMatch=testStrings; *aLineToMatch != NULL; aLineToMatch++) {
printf("String: %s\n", *aLineToMatch);
printf(" %s\n", "0123456789012345678901234567890123456789");
printf(" %s\n", "0 1 2 3");
/* Try to find the regex in aLineToMatch, and report results. */
pcreExecRet = pcre_exec(reCompiled,
pcreExtra,
*aLineToMatch,
strlen(*aLineToMatch), // length of string
0, // Start looking at this point
0, // OPTIONS
subStrVec,
30); // Length of subStrVec
/* pcre_exec OPTIONS (||'ed together) can be:
PCRE_ANCHORED -- can be turned on at this time.
PCRE_NOTBOL
PCRE_NOTEOL
PCRE_NOTEMPTY */
// Report what happened in the pcre_exec call..
//printf("pcre_exec return: %d\n", pcreExecRet);
if(pcreExecRet < 0) { // Something bad happened..
switch(pcreExecRet) {
case PCRE_ERROR_NOMATCH : printf("String did not match the pattern\n"); break;
case PCRE_ERROR_NULL : printf("Something was null\n"); break;
case PCRE_ERROR_BADOPTION : printf("A bad option was passed\n"); break;
case PCRE_ERROR_BADMAGIC : printf("Magic number bad (compiled re corrupt?)\n"); break;
case PCRE_ERROR_UNKNOWN_NODE : printf("Something kooky in the compiled re\n"); break;
case PCRE_ERROR_NOMEMORY : printf("Ran out of memory\n"); break;
default : printf("Unknown error\n"); break;
} /* end switch */
} else {
printf("Result: We have a match!\n");
// At this point, rc contains the number of substring matches found...
if(pcreExecRet == 0) {
printf("But too many substrings were found to fit in subStrVec!\n");
// Set rc to the max number of substring matches possible.
pcreExecRet = 30 / 3;
} /* end if */
// Do it yourself way to get the first substring match (whole pattern):
// char subStrMatchStr[1024];
// int i, j
// for(j=0,i=subStrVec[0];i<subStrVec[1];i++,j++)
// subStrMatchStr[j] = (*aLineToMatch)[i];
// subStrMatchStr[subStrVec[1]-subStrVec[0]] = 0;
//printf("MATCHED SUBSTRING: '%s'\n", subStrMatchStr);
// PCRE contains a handy function to do the above for you:
for(j=0; j<pcreExecRet; j++) {
pcre_get_substring(*aLineToMatch, subStrVec, pcreExecRet, j, &(psubStrMatchStr));
printf("Match(%2d/%2d): (%2d,%2d): '%s'\n", j, pcreExecRet-1, subStrVec[j*2], subStrVec[j*2+1], psubStrMatchStr);
} /* end for */
// Free up the substring
pcre_free_substring(psubStrMatchStr);
} /* end if/else */
printf("\n");
} /* end for */
// Free up the regular expression.
pcre_free(reCompiled);
// Free up the EXTRA PCRE value (may be NULL at this point)
if(pcreExtra != NULL)
pcre_free(pcreExtra);
// We are all done..
return 0;
} /* end func main */
运行程序时
gcc -o test -I/usr/local/Cellar/pcre/8.35/include -L/usr/local/Cellar/pcre/8.35/lib simple_pcre.c
给出错误为
Undefined symbols for architecture x86_64:
"_pcre_compile", referenced from:
_main in ccn0k76z.o
"_pcre_exec", referenced from:
_main in ccn0k76z.o
"_pcre_free", referenced from:
_main in ccn0k76z.o
"_pcre_free_substring", referenced from:
_main in ccn0k76z.o
"_pcre_get_substring", referenced from:
_main in ccn0k76z.o
"_pcre_study", referenced from:
_main in ccn0k76z.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
我应该如何使用 Pcre 库编译 C 代码?
最佳答案
您正在使用 -L 标志进行编译,该标志告诉链接器在哪里可以找到库,但我没有看到带有要链接的实际库的 -l 标志。
关于c - compilint PCRE c 代码中体系结构 x86_64 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30378177/
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我遇到了这两个文档(它们是用意大利语写的,尽管代码注释是英文的): http://home.deib.polimi.it/brandole/acsocr/L13%20-%20Generic%20Ass
我的主要目标是提供一个用 jquery 编写的基于 solr 的搜索应用程序。 (不熟悉solr的,就假设它是一个可以返回搜索结果的rest api。)为了这个目标,我编写了许多小型应用程序和 ser
这个问题是关于选择“正确”类型的NoSQL数据库的,我希望甚至可以根据我将在下面列出的一些需求/用例以及当前正在使用的传统RDBMS解决方案,讨论特定的数据库以及它们为什么适用。地点。时间长了一点,但
在 Java 中我运行: System.out.println(Math.log(249.0/251.0)); Output: -0.008000042667076265 在 C# 中我运行:<- 已
我目前正在考虑通过 Redux 将 Context 实现到我们的一个应用程序中,但是,我似乎找不到任何关于什么是大型应用程序的最佳结构的信息? Redux 有一个定义的方法来创建 reducer、ac
我正在使用 mailcore 框架,但收到错误消息“archtecture x86 的重复符号”以及“找不到选项的目录” 下面是错误日志。 Ld /Users/user/Library/Develop
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 11 个月前关闭。 Improve t
假设我正在从 C++ 移植代码并需要在 C# 中模拟相同的位移技术: 每当我执行位移时,我是否必须考虑架构的 Endain-ness? 最佳答案 没有。位移是一种纯粹的代数运算。它不比乘以二更依赖于平
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
关于架构 XXX 的重复符号有很多问题,但我没有得到我的问题的答案。在我的场景中,我使用 Cocoapod,并导入 FMDB,但是当我集成另一个第三方 SDK 时,当我构建项目时,出现如下错误: 是否
我无法编译我的 Xcode 项目,它有重复的 ParseFacebookUtilsV4 问题 这是我的苹果 Mach-O 链接器错误: duplicate symbol _llvm.cmdline i
我对使用 MFC 的内置文档 View 体系结构的必要性有疑问。我得到了一个基于对话框的旧项目,我必须在其中用框架替换主对话框并添加功能区。它有一种文档 View 架构,创建时没有内置类,我更愿意在新
我正在构建一个协作创作工具,该工具允许用户共同编辑信息空间,该信息空间是节点和链接的可视化。一个客户端应用程序中所做的更改需要反映到所有其他客户端中。由于它是可视化的,因此可能需要经常更新潜在的大数据
如果我在 Windows(x86 和 x64)下的 .NET 上运行涉及 System.Double 的复杂计算,然后在 Mono(Linux、Unix 等)上运行,绝对有保证 以在所有情况下得到完全
当我使用 Xcode 4.6 编译我的 iPhone 应用程序时,我看到一个奇怪的错误代码: "duplicate symbols for architecture i386". 我知道这个关于文件名
我最近询问了 System.Double,并被告知计算可能因平台/架构而异。不幸的是,我找不到任何信息来告诉我这是否适用于 System.Decimal。 对于任何特定的 decimal 计算,无论平
我有一些实体,例如:Customers、Orders、Invoices。 对于它们中的每一个,我都将它们的CRUD 操作 和一些其他界面分组为:ISvcCustomerMgmt、ISvcOrderMg
这个问题有点像一个池。我们正在尝试在使用 LINQ to SQL 之类的 ORM 时确定最佳架构。我们正在定义的架构是用于其他应用程序将通过直接引用 DLL 或通过 Web 服务访问的框架。我们有 .
请就如何为 Java web 应用程序做“插件”架构提出建议。 目前我们在 Tomcat servlet 容器中使用非常简单和标准的 Spring+Hibernate+Struts 2。 (使用 ma
我是一名优秀的程序员,十分优秀!