简体   繁体   English

为什么我得到一个未定义的引用,尽管一切看起来都很好? (C++ 明格)

[英]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.dllpe-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.

相关问题 尽管似乎一切就绪,但ifstream文件无法打开(C ++) - Ifstream file does not open although everything seems in place (c++) c++,MingW,未定义对“libiconv”的引用 - c++, MingW, undefined reference to `libiconv' 对 WinMain (C++ MinGW) 的未定义引用 - Undefined reference to WinMain (C++ MinGW) 为什么在编译 c++ 程序时出现“未定义的引用”错误? - Why am I get getting "undefined reference to" error when compiling a c++ program? 无法在 linux (i686-w64-mingw32-g++) 上交叉编译包含 sqlite 的 C++ 类(未定义的引用) - Can't cross compile c++ class with sqlite included (undefined reference) on linux (i686-w64-mingw32-g++) 在C ++中,为什么使用引用或不引用作为结果值会得到不同的结果? - In C++, why do I get different results using or not reference as result value? 为什么我使用相同的链接线获得未定义的引用? - Why do I get undefined reference with the same link line? 将 Winsock2 添加到我的 MinGW-w64 C/C++ 会导致:未定义对“InitializeConditionVariable”的引用 - Adding Winsock2 to my MinGW-w64 C/C++ causes: undefined reference to `InitializeConditionVariable' 使用 MinGW 使用网络代码编译简单的 C++ SFML 文件会引发错误“对 IpAddress 的未定义引用” - Compiling simple C++ SFML file with network code using MinGW throws error “undefined reference to IpAddress” Mingw / Boost / C++ - 使用 Boost Locale 时出现链接错误(对 __imp_GetACP 的未定义引用) - Mingw / Boost / C++ - link error (undefined reference to __imp_GetACP) when using Boost Locale
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM