我是C++的新手,我想编写一个简单的程序,将监视器色温输出到控制台。这里是我有:未定义的引用GetMonitorColorTemperature
#include <iostream>
#include <HighLevelMonitorConfigurationAPI.h>
using namespace std;
int main() {
HMONITOR hMonitor = NULL;
// Get the monitor handle.
hMonitor = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTOPRIMARY);
MC_COLOR_TEMPERATURE *colTemp;
BOOL bSuccess = FALSE;
bSuccess = GetMonitorColorTemperature(hMonitor, colTemp);
if (bSuccess){
cout << colTemp << endl;
}
return 0;
}
然而,编译我的项目收益率:
Building target: FirstC++Project.exe
Invoking: Cygwin C++ Linker
g++ -o "FirstC++Project.exe" ./src/FirstC++Project.o
./src/FirstC++Project.o: In function `main':
/cygdrive/c/Users/User/workspace/FirstC++Project/Debug/../src/FirstC++Project.cpp:35: undefined reference to `GetMonitorColorTemperature'
/cygdrive/c/Users/User/workspace/FirstC++Project/Debug/../src/FirstC++Project.cpp:35:(.text+0x68): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `GetMonitorColorTemperature'
collect2: error: ld returned 1 exit status
make: *** [makefile:47: FirstC++Project.exe] Error 1
05:42:02 Build Finished (took 5s.242ms)
任何帮助将不胜感激!
谢谢!
对于gcc,从MSDN获取链接器文件名('whatever.lib'),放下'.lib',并在开头添加'-l'。例如,'user32.lib'变为'-luser32'。 – andlabs