【发布时间】:2021-11-05 05:34:07
【问题描述】:
我正在尝试用 MinGW 编译一个 Win32 应用程序,其代码可以在 here 找到。源代码编译成一个对象就好了,但是当我尝试链接它时,会发生这种情况:
> gcc -o bin\updown.exe obj\updown.o -s -lcomctl32 -Wl,--subsystem,windows
obj\updown.o:updown.c:(.text+0x3ac): undefined reference to `StringCbPrintfW'
collect2.exe: error: ld returned 1 exit status
这个函数出现的唯一一次是在下面的sn-p中:
#include <windows.h>
#include <commctrl.h>
#include <strsafe.h>
...
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam) {
LPNMUPDOWN lpnmud;
UINT code;
switch(msg) {
...
case WM_NOTIFY:
...
const int asize = 4;
wchar_t buf[asize];
size_t cbDest = asize * sizeof(wchar_t);
StringCbPrintf(buf, cbDest, L"%d", value);
SetWindowText(hStatic, buf);
}
break;
...
}
...
}
【问题讨论】:
-
StringCbPrintf可能是 MSVC 特有的函数,在其他编译器中不可用。 -
StringCbPrintfW的定义由 strsafe.h 提供,除非定义了STRSAFE_NO_CB_FUNCTIONS。 -
@IInspectable 已定义还是已声明?
-
“已定义”,如所写。