gpt4 book ai didi

c++ - MS VC++ 9 pcrecpp.lib 链接错误

转载 作者:太空宇宙 更新时间:2023-11-04 13:55:39 25 4
gpt4 key购买 nike

刚刚建成pcre-8.34对于 Windows x86 下的 MS VC++,将库(pcrecpp.lib)和 header (pcrecpp.h、pcrecpparg.h、pcre_stringpiece.h)复制到它们的位置,并想测试一个简单的代码(在 GNU Linux C++ 下工作)但是我遇到了一些链接错误:

#define PCRE_STATIC 1

#include <pcrecpp.h>
#include <iostream>

#pragma comment(lib,"pcrecpp.lib")

using namespace std;

int main(void)
{
pcrecpp::RE regex("(hello)");
std::string strBase = "hello hello hello";

pcrecpp::StringPiece input(strBase);

std::string match;

int count = 0;
while (regex.FindAndConsume(&input, &match)) {
count++;
std::cout << count << " " << match << std::endl;
}
}

构建输出:

C:\Documents and Settings\Administrator\Desktop\Coding\pcre>cl.exe /MD /EHsc /O2 pc.cpp Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved.

pc.cpp Microsoft (R) Incremental Linker Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved.

/out:pc.exe pc.obj pcrecpp.lib(pcrecpp.obj) : error LNK2019: unresolved external symbol _pcre_compi le referenced in function "private: struct real_pcre * __thiscall pcrecpp::RE::C ompile(enum pcrecpp::RE::Anchor)" (?Compile@RE@pcrecpp@@AAEPAUreal_pcre@@W4Ancho r@12@@Z) pcrecpp.lib(pcrecpp.obj) : error LNK2019: unresolved external symbol _pcre_confi g referenced in function "int __cdecl pcrecpp::NewlineMode(int)" (?NewlineMode@p crecpp@@YAHH@Z) pcrecpp.lib(pcrecpp.obj) : error LNK2019: unresolved external symbol _pcre_exec referenced in function "private: int __thiscall pcrecpp::RE::TryMatch(class pcre cpp::StringPiece const &,int,enum pcrecpp::RE::Anchor,bool,int *,int)const " (?T ryMatch@RE@pcrecpp@@ABEHABVStringPiece@2@HW4Anchor@12@_NPAHH@Z) pcrecpp.lib(pcrecpp.obj) : error LNK2019: unresolved external symbol _pcre_fulli nfo referenced in function "public: int __thiscall pcrecpp::RE::NumberOfCapturin gGroups(void)const " (?NumberOfCapturingGroups@RE@pcrecpp@@QBEHXZ) pcrecpp.lib(pcrecpp.obj) : error LNK2019: unresolved external symbol _pcre_free referenced in function "private: void __thiscall pcrecpp::RE::Cleanup(void)" (?C leanup@RE@pcrecpp@@AAEXXZ) pc.exe : fatal error LNK1120: 5 unresolved externals

知道我做错了什么吗?在 VC++ 10 下也试过,同样的错误。我应该包括 <pcre.h>#pragma comment(lib,"pcre.lib")因为如果我这样做,链接会毫无错误地发生,但在 C++ 代码中使用 C 头文件和库似乎很奇怪?

更新:

我这样做了,现在可以工作了,唯一的问题是:这对 C++ 可行吗?

#define PCRE_STATIC 1

#include <pcrecpp.h>
#include <iostream>

#pragma comment(lib,"pcrecpp.lib")
#pragma comment(lib,"pcre.lib")

using namespace std;

int main(void)
{
pcrecpp::RE regex("(hello)");
std::string strBase = "hello hello hello";

pcrecpp::StringPiece input(strBase);

std::string match;

int count = 0;
while (regex.FindAndConsume(&input, &match)) {
count++;
std::cout << count << " " << match << std::endl;
}
}

输出:

C:\Documents and Settings\Administrator\coding\pcre>cl.exe /O2 /MD /EHsc pcc.cpp /link /SUBSYSTEM:CONSOLE Kernel32.Lib User32.lib Wininet.lib pcre.lib Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved.

pc.cpp Microsoft (R) Incremental Linker Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved.

/out:pc.exe /SUBSYSTEM:CONSOLE Kernel32.Lib User32.lib Wininet.lib pcre.lib get_all_proc.obj

最佳答案

您还需要链接到“pcre.lib”。如果您查看“pcrecpp.h”源代码,您会发现它包含“pcre.h”,因此它也使用了库的“c 部分”。

关于c++ - MS VC++ 9 pcrecpp.lib 链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21598715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com