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