[英]Why do I get an undefined reference although everything seems alright ? (C++ Mingw)
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 .我的问题相当琐碎和简单,我正在尝试编写一个加壳程序,为此我需要解析 PE 文件,所以我正在尝试使用C++ pe-parse 库。
I built it following the instructions and I'm now trying to link it to my simple main.cpp
file:我按照说明构建了它,现在我正在尝试将它链接到我的简单
main.cpp
文件:
#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
) MinGW 确实是 x64 (
x86_64-w64-mingw32
) 我的库也是 ( pei-x86-64
用于pe-parse.dll
和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:从 root 开始,我收到以下链接错误:
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.lib
上运行nm
时,我能够找到该符号。 pe-parse.dll
does not contain any, and I tried to to replace -L.\bin\
with -L.\lib\
pe-parse.dll
不包含任何内容,我试图用-L.\lib\
替换-L.\bin\
\
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.我相信
.lib
是一个必须与.dll
链接的导入库,但我找不到办法。
Thank you.谢谢你。
You have a library produced by MSVC and you are trying to use g++ to link with it.您有一个由 MSVC 生成的库,您正在尝试使用 g++ 与其链接。
Microsoft C++ compiler is not compatible with g++. Objects produced by one of them cannot use objects compiled by the other. Microsoft C++ 编译器与 g++ 不兼容。其中一个生成的对象不能使用另一个编译的对象。 They use vastly different ABIs and different standard library implementations.
他们使用截然不同的 ABI 和不同的标准库实现。
Your only option is to recompile everything with one compiler.您唯一的选择是使用一个编译器重新编译所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.