GCC可以在Windows上找到标题
我是Winapi的新手,并且正在学习如何使用一些特殊功能的代码程序等,因此我下载了Windows的SDK。
问题是,海湾合作委员会决定放上盲眼镜说:
Documents_path.c:6:25: fatal error: KnownFolders.h: No such file or directory
#include<KnownFolders.h>
^
compilation terminated.
“好吧,下一个然后有一个问题。
thread.c:3:30: fatal error: processthreadsapi.h: No such file or directory
#include<processthreadsapi.h>
^
compilation terminated.
我说: ,当我尝试使用基本功能时,它正在起作用。
我搜索了这个问题的答案,但没有找到任何东西,要么是外部\二进制库问题,是本地还是不是宏修复(它无效)。
如何解决问题?
编辑: 我正在使用VS代码
edit2:
这是“ documents_path.c”示例的代码:
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
#include<ShlObj.h>
#include<initguid.h>
#include<KnownFolders.h>
#pragma comment(lib, "user32.lib")
int main(){
int a;
PWSTR path = NULL;
HRESULT hr = SHGetKnownFolderPath(&FOLDERID_Documents, 0, NULL, &path);
if(SUCCEEDED(hr)){
printf("path for Documents is: %ls", path);
}
scanf("%d",&a);
CoTaskMemFree(path);
return 0;
}
我正在从本网站阅读Winapi的基础: https://zetcode.com/gui/gui/winapi/
关于Project Folder的结构: C:\ users \%用户%\ documents \ c \ dawd
I'm new in winAPI and I was learning how code programs with some special functions and such, so I downloaded the Windows's SDK.
Problem is, GCC decided to put the blind glasses and say:
Documents_path.c:6:25: fatal error: KnownFolders.h: No such file or directory
#include<KnownFolders.h>
^
compilation terminated.
I said "OK, next one then" and there's another header with the same problem:
thread.c:3:30: fatal error: processthreadsapi.h: No such file or directory
#include<processthreadsapi.h>
^
compilation terminated.
I checked if these headers are even in my PC and here they are setting with windows.h, which it was working when I tried basic functions with it.
I searched an answer for this problem but didn't find any, either it was a external\binary libraries problem, is it local or not or a macro fix (which it didn't work).
How can I fix the problem?
EDIT:
I'm using VS Code
EDIT2:
This is the code of "Documents_path.c" example:
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
#include<ShlObj.h>
#include<initguid.h>
#include<KnownFolders.h>
#pragma comment(lib, "user32.lib")
int main(){
int a;
PWSTR path = NULL;
HRESULT hr = SHGetKnownFolderPath(&FOLDERID_Documents, 0, NULL, &path);
if(SUCCEEDED(hr)){
printf("path for Documents is: %ls", path);
}
scanf("%d",&a);
CoTaskMemFree(path);
return 0;
}
And I'm reading the basics of winAPI from this website:
https://zetcode.com/gui/winapi/
as for structure of project folder:
C:\Users\ %USER%\Documents\C\dawd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MSVC使用Windows SDK,而GCC则使用。
在Windows GCC上,使用Mingw或Mingw-W64作为标准库,这是Windows API的开源实现。
因此,GCC+Mingw将使用自己的标题,并且不会寻找任何Windows SDK。因此,Windows上的GCC+Mingw根本没有安装任何Microsoft开发人员工具。
Mingw-w64-比Mingw更新,它支持Windows 32位和64位 - 存在于独立软件包中,可以从 https://winlibs.com/ 。但是您仍然可以从IDE中使用它,例如 vscode 或 code :: blocks 。
mingw-w64具有
nownfolders.h
和processThreadSapi.h
之类的文件。但是请注意,
#pragma评论(lib,“ user32.lib”)
是MSVC特定的,并且在GCC等其他编译器中不起作用。相反,您必须使用Linker Flag-luser32
。因为您调用cotaskMemFree()
您还需要添加-lole32
。我在系统上尝试了您的代码,它可以编译和链接:
MSVC uses Windows SDK while GCC does not.
On Windows GCC uses MinGW or MinGW-w64 as standard library, which is an open source implementation of Windows API.
So GCC+MinGW will use its own headers and will not look for any Windows SDK. So GCC+MinGW on Windows works without having any Microsoft developer tools installed at all.
MinGW-w64 - which is more recent than MinGW and which supports both Windows 32-bit and 64-bit - exists in a standalone package that can be downloaded from https://winlibs.com/. But you can still use it from an IDE like VSCode or Code::Blocks.
MinGW-w64 has the files like
knownfolders.h
andprocessthreadsapi.h
which you had issues with.But be aware that
#pragma comment(lib, "user32.lib")
is MSVC-specific and will not work in other compilers like GCC. Instead you must use linker flag-luser32
. Because you callCoTaskMemFree()
you will also need to add-lole32
.I tried your code on my system and it compiles and links fine with: