[英]C++ Linux to Windows Cross-compilation error
我正在尝试为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标志。 我不知道我需要的文件名是什么。
我不确定该怎么办。
谢谢你的帮助。
快速查找/ nm(具有识别Windows二进制文件的适当nm)0可以得出:
rich@dev:~/ellcc-release/libecc/mingw/x86_64-w64-mingw32$ find . -name "*.a" | xargs ~/ellcc/bin/ecc-nm -A | grep FOLDERID_Startup
/home/rich/ellcc/bin/ecc-nm: ./sys-root/mingw/lib/libruntimeobject.a: File format not recognized
./sys-root/mingw/lib/libuuid.a:lib64_libuuid_a-uuid.o:0000000000000000 r .rdata$FOLDERID_Startup
./sys-root/mingw/lib/libuuid.a:lib64_libuuid_a-uuid.o:0000000000000000 R FOLDERID_Startup
rich@dev:~/ellcc-release/libecc/mingw/x86_64-w64-mingw32$
看起来-luuid就是您所需要的。
我做了一个小测试程序:
rich@dev:~$ cat win.c
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
#include <shlobj.h>
int WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd){
const char *startupFolder;
//get startup folder
if(SHGetKnownFolderPath(&FOLDERID_Startup, 0, NULL, &startupFolder) != S_OK){
//error in getting startup folder
return -1;
}
/*
...
*/
}
rich@dev:~$ ~/ellcc/bin/ecc -target x86_64-w64-mingw32 win.c -luuid
win.c:7:57: warning: incompatible pointer types passing 'const char **' to
parameter of type 'PWSTR *' (aka 'unsigned short **')
[-Wincompatible-pointer-types]
if(SHGetKnownFolderPath(&FOLDERID_Startup, 0, NULL, &startupFolder) != S...
^~~~~~~~~~~~~~
/home/rich/ellcc/bin/../libecc/mingw/include/shlobj.h:746:92: note: passing
argument to parameter 'ppszPath' here
...(REFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath);
^
1 warning generated.
rich@dev:~$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.