问题描述
我正在尝试使用mingw工具集将本机Windows API与Qt一起使用.某些功能存在链接问题.怎么了?这是mingw名称修饰的错误吗?
I am trying to use native windows API with Qt using mingw toolset. There are link problems with some functions. What happens? Is this a bug with mingw name mangling?
#ifdef Q_WS_WIN
HWND hwnd = QWidget::winId();
HDC hdcEMF = CreateEnhMetaFile(NULL, NULL, NULL, NULL ) ;
Rectangle(hdcEMF,100,100,200,200);
HENHMETAFILE hemf = CloseEnhMetaFile(hdcEMF);
OpenClipboard(hwnd);
EmptyClipboard();
SetClipboardData(CF_ENHMETAFILE,hemf);
CloseClipboard();
#else
错误:
对"CreateEnhMetaFileW @ 16"的未定义引用
undefined reference to `CreateEnhMetaFileW@16'
对"Rectangle @ 20"的未定义引用
undefined reference to `Rectangle@20'
对"CloseEnhMetaFile @ 4"的未定义引用
undefined reference to `CloseEnhMetaFile@4'
推荐答案
函数CreateEnhMetaFileW()
和CloseEnhMetaFile()
在静态库Gdi32.lib中定义,因此必须确保对此进行链接.尝试在用于编译的命令行末尾添加-lgdi32
.如果这样不起作用,则可能必须通过添加-L/path/to/folder/containing/the/library -lgdi32
来指定Gdi32.lib的完整路径.
The functions CreateEnhMetaFileW()
and CloseEnhMetaFile()
are defined in the static library Gdi32.lib, so you have to make sure to link against that. Try adding -lgdi32
to the end of your command line you're using to compile. If that doesn't work, you might have to specify the full path to Gdi32.lib by adding -L/path/to/folder/containing/the/library -lgdi32
instead.
这篇关于Qt + win32 + mingw上的本机Windows API链接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!