【问题标题】:unresolved external symbol on pcre visual studiopcre Visual Studio 上未解析的外部符号
【发布时间】:2016-04-17 17:49:30
【问题描述】:

你好,我想在我的 Visual Studio 2015 上使用 pcre。我得到了所有 pcre 库(我编译了它),我在 Linker/General/Additional library Dir 上设置了 pcre lib dir 这是我的来源

#include <iostream>
#include <string>
#include <stdlib.h>
#include <map>
#include "pcrecpp.h"

using namespace std;
using namespace pcrecpp;

void main()
{


    RE_Options Regex_Options;

    // Set options
    Regex_Options.set_caseless(true);
    Regex_Options.set_multiline(true);
    Regex_Options.set_dotall(true);

    RE Regex("h.*o", Regex_Options);

    Regex.FullMatch("hello");


    system("pause");
}

当我想编译这个项目时,我得到了这个错误

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "public: bool __thiscall pcrecpp::RE::FullMatch(class pcrecpp::StringPiece const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &)const " (?FullMatch@RE@pcrecpp@@QBE_NABVStringPiece@2@ABVArg@2@111111111111111@Z) referenced in function _main    TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK2019 unresolved external symbol "public: __thiscall pcrecpp::RE::~RE(void)" (??1RE@pcrecpp@@QAE@XZ) referenced in function _main TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK2019 unresolved external symbol "private: void __thiscall pcrecpp::RE::Init(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class pcrecpp::RE_Options const *)" (?Init@RE@pcrecpp@@AAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PBVRE_Options@2@@Z) referenced in function "public: __thiscall pcrecpp::RE::RE(char const *,class pcrecpp::RE_Options const &)" (??0RE@pcrecpp@@QAE@PBDABVRE_Options@1@@Z)    TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK2001 unresolved external symbol "public: static class pcrecpp::Arg pcrecpp::RE::no_arg" (?no_arg@RE@pcrecpp@@2VArg@2@A)  TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK1120 4 unresolved externals  TestProg    D:\Visual Studio Projects\TestProg\Debug\TestProg.exe   1   

有什么问题!!! ??

我将所有库放入链接/输入/附加... 这是新的错误

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall pcrecpp::RE::RE(char const *,class pcrecpp::RE_Options const &)" (__imp_??0RE@pcrecpp@@QAE@PBDABVRE_Options@1@@Z) referenced in function _main TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall pcrecpp::StringPiece::StringPiece(char const *)" (__imp_??0StringPiece@pcrecpp@@QAE@PBD@Z) referenced in function _main    TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall pcrecpp::RE_Options::RE_Options(void)" (__imp_??0RE_Options@pcrecpp@@QAE@XZ) referenced in function _main  TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class pcrecpp::RE_Options & __thiscall pcrecpp::RE_Options::set_caseless(bool)" (__imp_?set_caseless@RE_Options@pcrecpp@@QAEAAV12@_N@Z) referenced in function _main  TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class pcrecpp::RE_Options & __thiscall pcrecpp::RE_Options::set_multiline(bool)" (__imp_?set_multiline@RE_Options@pcrecpp@@QAEAAV12@_N@Z) referenced in function _main    TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class pcrecpp::RE_Options & __thiscall pcrecpp::RE_Options::set_dotall(bool)" (__imp_?set_dotall@RE_Options@pcrecpp@@QAEAAV12@_N@Z) referenced in function _main  TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall pcrecpp::RE::~RE(void)" (__imp_??1RE@pcrecpp@@QAE@XZ) referenced in function _main TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: bool __thiscall pcrecpp::RE::FullMatch(class pcrecpp::StringPiece const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &,class pcrecpp::Arg const &)const " (__imp_?FullMatch@RE@pcrecpp@@QBE_NABVStringPiece@2@ABVArg@2@111111111111111@Z) referenced in function _main    TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK2001 unresolved external symbol "__declspec(dllimport) public: static class pcrecpp::Arg pcrecpp::RE::no_arg" (__imp_?no_arg@RE@pcrecpp@@2VArg@2@A)  TestProg    D:\Visual Studio Projects\TestProg\TestProg\Source.obj  1   
Error   LNK1120 9 unresolved externals  TestProg    D:\Visual Studio Projects\TestProg\Debug\TestProg.exe   1   

【问题讨论】:

  • 您可能还需要在 Linker->Input->Additional dependencies 处设置您正在使用的特定库名称
  • 我做到了.. 10 个错误!!!!!!!!!!!!严重性代码 描述 项目文件行抑制状态错误 LNK2019 无法解析的外部符号“_declspec(dllimport) public: __thiscall pcrecpp::RE::RE(char const *,class pcrecpp::RE_Options const &)” (__imp??0RE@pcrecpp@@QAE@PBDABVRE_Options@1@@Z) 在函数_main TestProg D:\Visual Studio Projects\TestProg\TestProg\Source.obj 1中引用

标签: c++ visual-studio-2015 pcre


【解决方案1】:

所以,我假设您默认使用BUILD_SHARED_LIBS=OFF 选项编译它。然后,您需要将 PCRE_STATIC 添加到应用程序的预处理器定义中。使用此定义 pcrecpp::RE 类前面不会有 __declspec(dllimport),因此不会尝试找到您没有的导入库,因为所有代码都在静态库中。

【讨论】:

  • 恕我直言,这是 pcre CMAKE 配置中的一个错误,当 CMAKE 构建 Visual Studio 项目文件时,它应该在它为构建生成的 vcxproj 文件中生成此令牌定义。我有同样的问题,正在研究它。我记得我破解了它来构建 x64 版本,现在我正在为 win32 再次这样做。就我而言,我有 5 个项目正在建设中,5 个失败了。 5 个中有 2 个是单元测试,所以我假设它们的构建配置中缺少 PCRE_STATIC。
【解决方案2】:

您应该从ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载 pcre-8.43-1 版本 这是它实现的cc或cpp。

【讨论】:

    猜你喜欢
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-28
    • 2011-10-02
    • 2015-10-30
    • 1970-01-01
    • 2023-03-28
    相关资源
    最近更新 更多