尽管一切似乎还好,但为什么我会得到不确定的参考? (c++ mingw)

发布于 2025-02-07 21:00:46 字数 1459 浏览 1 评论 0原文

我的问题相当简单,很简单,我正在尝试编写一个包装器,因此我需要解析PE文件,因此我尝试使用 c ++ pe-parse库

我按照说明构建了它,现在我试图将其链接到我的简单main.cpp文件:

#include <pe-parse/parse.h>

int main(int ac, char **av)
{
    peparse::parsed_pe *p = peparse::ParsePEFromFile(av[0]);
    return 0;
}

这是我的文件结构:

.
├── src
│      main.cpp
├── lib
│      pe-parse.lib
├── bin
│      pe-parse.dll
└── include
    └ pe-parse
         nt-headers.h
         parse.h
         to_string.h

mingw确实是x64(x86_64-w64-w64-mingw32 < /code>)和我的库(pei-x86-64均用于pe-parse.dllpe-parse.lib

)我从root运行

g++ -Wall -Wextra .\src\main.cpp -I.\include\ -L.\bin\ -lpe-parse

,得到以下链接错误:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
C:\Users\gz\AppData\Local\Temp\ccxml3rK.o:packer.cpp:(.text+0x1f): undefined reference to `peparse::ParsePEFromFile(char const*)'
collect2.exe: error: ld returned 1 exit status

当我在nm上运行pe-parse.lib时,我可以找到符号。 pe-parse.dll不包含任何内容,我试图用-l。\ bin \-L。\ lib \ lib \

有什么想法吗?我相信.lib是一个导入库,必须与.dll链接在一起,但我找不到方法。

谢谢。

My problem is fairly trivial and simple, I am trying to write a packer and to do so I need to parse PE files, so I'm trying to use the C++ pe-parse library.

I built it following the instructions and I'm now trying to link it to my simple main.cpp file:

#include <pe-parse/parse.h>

int main(int ac, char **av)
{
    peparse::parsed_pe *p = peparse::ParsePEFromFile(av[0]);
    return 0;
}

Here is my file structure:

.
├── src
│      main.cpp
├── lib
│      pe-parse.lib
├── bin
│      pe-parse.dll
└── include
    └ pe-parse
         nt-headers.h
         parse.h
         to_string.h

MinGW is indeed x64 (x86_64-w64-mingw32) and my libraries also (pei-x86-64 for both pe-parse.dll and pe-parse.lib)

When I run

g++ -Wall -Wextra .\src\main.cpp -I.\include\ -L.\bin\ -lpe-parse

from root, I get the following linking error:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
C:\Users\gz\AppData\Local\Temp\ccxml3rK.o:packer.cpp:(.text+0x1f): undefined reference to `peparse::ParsePEFromFile(char const*)'
collect2.exe: error: ld returned 1 exit status

When I run nm on pe-parse.lib I am able to find the symbol. pe-parse.dll does not contain any, and I tried to to replace -L.\bin\ with -L.\lib\

Any ideas ? I believe the .lib is an import library that has to be linked with the .dll, but I can't find a way to.

Thank you.

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

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

发布评论

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

评论(1

若水微香 2025-02-14 21:00:46

您有一个由MSVC生产的库,您正在尝试使用G ++与之链接。

Microsoft C ++编译器与G ++不兼容。其中一个产生的对象不能使用另一个编译的对象。他们使用截然不同的ABI和不同的标准库实现。

您唯一的选择是用一个编译器重新编译所有内容。

You have a library produced by MSVC and you are trying to use g++ to link with it.

Microsoft C++ compiler is not compatible with g++. Objects produced by one of them cannot use objects compiled by the other. They use vastly different ABIs and different standard library implementations.

Your only option is to recompile everything with one compiler.

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