帮助在 C++ 中使用 PCRE

发布于 2024-10-11 16:55:30 字数 2059 浏览 5 评论 0原文

这是我第一次尝试构建 C++ 应用程序,所以我有点迷失。我看过一些例子,但我仍然不知道出了什么问题。

#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <pcrecpp.h>
#include <string>
#include <cstring>

using namespace std;

int main()
{
    char title[256];
    char url[256];
    string song, diff;
    HWND hwnd = FindWindow("WindowsForms10.Window.8.app.0.33c0d9d", NULL);
    GetWindowTextA(hwnd, title, 255);
    pcrecpp::RE re("^osu!  - (.*) \\[(.*)\\] \\[[|-]{21}\\]$");
    re.FullMatch(title, &song, &diff);
    sprintf(url, "xfire:game_stats?game=%s&%s=%s&%s=%s", "osu", "Playing", song.c_str(), "Difficulty", diff.c_str());
    ShellExecute(NULL, NULL, url, NULL, NULL, SW_SHOWDEFAULT);
    return 0;
}

当我尝试编译时,出现以下编译器错误

obj\Debug\main.o||In function 'main':| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|对“_imp___ZN7pcrecpp2RE6no_argE”的未定义引用| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|对“_imp___ZN7pcrecpp2RE6no_argE”的未定义引用| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|对“_imp___ZN7pcrecpp2RE6no_argE”的未定义引用| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|对“_imp___ZN7pcrecpp2RE6no_argE”的未定义引用| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|对“_imp___ZN7pcrecpp2RE6no_argE”的未定义引用| obj\Debug\main.o:C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|更多对“_imp___ZN7pcrecpp2RE6no_argE”的未定义引用如下| obj\Debug\main.o||在函数“main”中:| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|对'_imp___ZNK7pcrecpp2RE9FullMatchERKNS_11StringPieceERKNS_3ArgES6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_'的未定义引用| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|17|对“_imp___ZN7pcrecpp2RED1Ev”的未定义引用| C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|17|对“_imp___ZN7pcrecpp2RED1Ev”的未定义引用| obj\Debug\main.o||在函数“Arg”中:| C:\MinGW\msys\1.0\local\include\pcrecpparg.h|89|对“_imp___ZN7pcrecpp3Arg12parse_stringEPKciPv”的未定义引用| obj\Debug\main.o||在函数“RE”中:| C:\MinGW\msys\1.0\local\include\pcrecpp.h|493|对“_imp___ZN7pcrecpp2RE4InitERKSsPKNS_10RE_OptionsE”的未定义引用| ||=== 构建完成:11 个错误,0 个警告 ===|

this is my first time trying to build a C++ application, so I'm kind of lost. I've looked at some examples but I still dont really know what's wrong.

#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <pcrecpp.h>
#include <string>
#include <cstring>

using namespace std;

int main()
{
    char title[256];
    char url[256];
    string song, diff;
    HWND hwnd = FindWindow("WindowsForms10.Window.8.app.0.33c0d9d", NULL);
    GetWindowTextA(hwnd, title, 255);
    pcrecpp::RE re("^osu!  - (.*) \\[(.*)\\] \\[[|-]{21}\\]$");
    re.FullMatch(title, &song, &diff);
    sprintf(url, "xfire:game_stats?game=%s&%s=%s&%s=%s", "osu", "Playing", song.c_str(), "Difficulty", diff.c_str());
    ShellExecute(NULL, NULL, url, NULL, NULL, SW_SHOWDEFAULT);
    return 0;
}

When I try to compile, I get the following compiler errors

obj\Debug\main.o||In function 'main':|
C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|undefined reference to '_imp___ZN7pcrecpp2RE6no_argE'|
C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|undefined reference to '_imp___ZN7pcrecpp2RE6no_argE'|
C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|undefined reference to '_imp___ZN7pcrecpp2RE6no_argE'|
C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|undefined reference to '_imp___ZN7pcrecpp2RE6no_argE'|
C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|undefined reference to '_imp___ZN7pcrecpp2RE6no_argE'|
obj\Debug\main.o:C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|more undefined references to '_imp___ZN7pcrecpp2RE6no_argE' follow|
obj\Debug\main.o||In function 'main':|
C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|18|undefined reference to '_imp___ZNK7pcrecpp2RE9FullMatchERKNS_11StringPieceERKNS_3ArgES6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_S6_'|
C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|17|undefined reference to '_imp___ZN7pcrecpp2RED1Ev'|
C:\Users\Zeffy\Desktop\osu-gamestats\main.cpp|17|undefined reference to '_imp___ZN7pcrecpp2RED1Ev'|
obj\Debug\main.o||In function 'Arg':|
C:\MinGW\msys\1.0\local\include\pcrecpparg.h|89|undefined reference to '_imp___ZN7pcrecpp3Arg12parse_stringEPKciPv'|
obj\Debug\main.o||In function 'RE':|
C:\MinGW\msys\1.0\local\include\pcrecpp.h|493|undefined reference to '_imp___ZN7pcrecpp2RE4InitERKSsPKNS_10RE_OptionsE'|
||=== Build finished: 11 errors, 0 warnings ===|

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柏拉图鍀咏恒 2024-10-18 16:55:30

_imp___ZN7pcrecpp2RE6no_argE 是一个损坏的名称。由于它包含 pcrecppno_arg 部分,我怀疑问题在于您无法链接到 Pcrecpp。因此,没有定义 no_arg 符号。

_imp___ZN7pcrecpp2RE6no_argE is a mangled name. Since it contains the parts pcrecpp and no_arg, I suspect that the problem is that you fail to link against Pcrecpp. Therefore, the no_arg symbol is not defined.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文