【发布时间】:2016-10-21 19:46:51
【问题描述】:
我正在尝试为 linux 中的 windows 编译一个 C++ 程序。该程序使用 SHGetKnownFolderPath 函数。每当我尝试编译它时,都会出现以下错误:
$ x86_64-w64-mingw32-g++ main.cpp main.h -mwindows -o main.exe
/tmp/cc7yIaVK.o:main.cpp:(.text+0x11c): undefined reference to `SHGetKnownFolderPath'
/tmp/cc7yIaVK.o:main.cpp:(.rdata$.refptr.FOLDERID_Startup[.refptr.FOLDERID_Startup]+0x0): undefined reference to `FOLDERID_Startup'
collect2: error: ld returned 1 exit status
这是我写的代码:
int WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd){
//get startup folder
if(SHGetKnownFolderPath(FOLDERID_Startup, 0, NULL, &startupFolder) != S_OK){
//error in getting startup folder
return -1;
}
/*
...
*/
}
我包含了正确的头文件并定义了 windows 版本:
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
#include <shlobj.h>
编辑:根据 mingw.org 文档,我了解到我必须在编译中链接一个 lib 文件,大概是在源文件名之后使用 -l 标志。我不知道我需要的文件的名称是什么。
我不知道还能做什么。
【问题讨论】:
-
#includes 和#defines 仅对编译时间感兴趣。您没有编译错误,但有链接器错误。所以你需要弄清楚你必须与你的东西链接什么,以便为链接器提供它需要的东西。 github.com/HandBrake/HandBrake/issues/112 有帮助吗? -
@Alfe 我也在 google 上看到了该链接,但它不起作用。显然,这些网站现在受到 DDoS 攻击:pcworld.com/article/3133847/internet/…
-
@krOoze 该帖子谈到了 Qt(我没有使用)和 Windows(我没有使用)(从答案中的 DOS 样式路径猜测)。该帖子提供的解决方案不适用于此处。
-
@Yapoz 很好。不过,该功能似乎在
shell32中,需要以某种方式链接。
标签: c++ linux windows cross-compiling