GetMonitorColorTemperature的未定义引用

时间:2017-02-18 04:54:33

标签: c++ eclipse winapi cygwin

我是C ++的新手,我想编写一个简单的程序,将监视器的色温输出到控制台。这就是我所拥有的:

  #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)

任何帮助将不胜感激!

谢谢!

1 个答案:

答案 0 :(得分:-2)

读取错误消息“GetMonitorColorTemperature.h”未定义。这意味着它找不到头文件。您是否将GetMonitorColorTemperature.h文件放在与cpp文件相同的目录中,这样就可以找到该库。