2017-02-18 22 views
0

私は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) 

任意の助けが理解されるであろう!

ありがとうございました!

+0

gccの場合、リンカファイル名( 'whatever.lib')をMSDNから取り出し、' .lib'をドロップし、 '-l'を先頭に追加します。たとえば、 'user32.lib'は' -luser32'になります。 – andlabs

答えて

-2

「GetMonitorColorTemperature.h」というエラーメッセージが表示されていますが、これは未定義です。つまり、ヘッダファイルを見つけることができません。 GetMonitorColorTemperature.hファイルをcppファイルと同じディレクトリに置いて、ライブラリを見つけることができるようにしました。

+0

ありがとうございます!実際には、私は、Microsoftのリンクhttps://msdn.microsoft.com/en-us/library/windows/desktop/dd692941(v=vs.85).aspx –

+0

で提案されているように、ヘッダーファイルHighLevelMonitorConfigurationAPI.hのみを追加しました。エラーを完全に誤読しています。これはリンカエラーであり、 'GetMonitorColorTemperature.h'ヘッダファイルはありません。 – andlabs

+0

@andlabs、ありがとうございます!だから、解決策は何ですか? –

関連する問題