错误:“未定义的引用`__imp_getopenfilenamea;'虽然我使用GCC -LCOMDLG32
我创建了一个名为“ demo.c”的文件。 这是代码:
#include <Windows.h>
#include <commdlg.h>
#include <stdio.h>
int FileDialog(char *path)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = path;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
return GetOpenFileName(&ofn);
}
int main(char argc, char *argv[])
{
char szFile[MAX_PATH] = {0};
if (FileDialog(szFile))
{
puts(szFile);
}
return 0;
}
然后我在CMD中输入“ GCC -LCOMDLG32 DEMO.C -O演示”。 但是结果是错误:
D:\MyProject\C_Programming\WindowsApiTest>gcc -lcomdlg32 demo1.c -o demo
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\c\AppData\Local\Temp\ccqGNley.o:demo1.c:(.text+0x64): undefined reference to `__imp_GetOpenFileNameA'
collect2.exe: error: ld returned 1 exit status
那么为什么它报告错误?
我的操作系统是Win11,而我的GCC是TDM-GCC-64。
I creat a file named "demo.c".
Here is the code:
#include <Windows.h>
#include <commdlg.h>
#include <stdio.h>
int FileDialog(char *path)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = path;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
return GetOpenFileName(&ofn);
}
int main(char argc, char *argv[])
{
char szFile[MAX_PATH] = {0};
if (FileDialog(szFile))
{
puts(szFile);
}
return 0;
}
Then I enter "gcc -lcomdlg32 demo.c -o demo" in cmd.
But the result is error:
D:\MyProject\C_Programming\WindowsApiTest>gcc -lcomdlg32 demo1.c -o demo
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\c\AppData\Local\Temp\ccqGNley.o:demo1.c:(.text+0x64): undefined reference to `__imp_GetOpenFileNameA'
collect2.exe: error: ld returned 1 exit status
So why do it report an error?
My operating system is win11, and my GCC is tdm-gcc-64.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢Yano,解决了问题!
只需使用
GCC Demo1.c -lcomdlg32 -o demo
Thank yano, the question was solved!
just use
gcc demo1.c -lcomdlg32 -o demo