2

I'm trying to write a simple code for getting some information from my GPU (NVidia Geforce 760 GTX) such as temperature using NVAPI.
I started with CUDA sample codes. Maybe you see these sample codes provided by NVidia. I copied one of the sample codes ('CUDA Samples\v6.5\0_Simple\vectorAdd') to write in this sample. I copied all of '.h' files of NVAPI to 'CUDA Samples\v6.5\common\inc' and copied 'nvapi.lib' to 'CUDA Samples\v6.5\common\lib\Win32' and copied 'nvapi64.lib' to 'CUDA Samples\v6.5\common\lib\x64'.
I preformed these copies to 'C:\Program Files\CUDA\v6.5\include' and 'C:\Program Files\CUDA\v6.5\lib'.
This is the code I wrote:

int _txmain() {

NvAPI_Status ret = NVAPI_OK;
int i=0;

NvDisplayHandle hDisplay_a[NVAPI_MAX_PHYSICAL_GPUS*2] = {0};

ret = NvAPI_Initialize();

if (!ret == NVAPI_OK){
    NvAPI_ShortString string;
    NvAPI_GetErrorMessage(ret, string);
    printf("NVAPI NvAPI_Initialize: %s\n", string);
}

NvAPI_ShortString ver;

NvAPI_GetInterfaceVersionString(ver);
printf("NVAPI Version: %s\n", ver);

NvU32 cnt;

NvPhysicalGpuHandle phys;

ret = NvAPI_EnumPhysicalGPUs(&phys, &cnt);

if (!ret == NVAPI_OK){
    NvAPI_ShortString string;
    NvAPI_GetErrorMessage(ret, string);
    printf("NVAPI NvAPI_EnumPhysicalGPUs: %s\n", string);
}

NvAPI_ShortString name;

NV_GPU_THERMAL_SETTINGS thermal;

ret = NvAPI_GPU_GetFullName(phys, name);
if (!ret == NVAPI_OK){
    NvAPI_ShortString string;
    NvAPI_GetErrorMessage(ret, string);
    printf("NVAPI NvAPI_GPU_GetFullName: %s\n", string);
}

printf("Name: %s\n", name);
thermal.version =NV_GPU_THERMAL_SETTINGS_VER;
ret = NvAPI_GPU_GetThermalSettings(phys,0, &thermal);

if (!ret == NVAPI_OK){
    NvAPI_ShortString string;
    NvAPI_GetErrorMessage(ret, string);
    printf("NVAPI NvAPI_GPU_GetThermalSettings: %s\n", string);
}

printf("Temp: %l C\n", thermal.sensor[0].currentTemp);

return 0;

}

But when I build my code I received these errors:

Error 28 error LNK2019: unresolved external symbol NvAPI_GPU_GetThermalSettings referenced in function...
Error 29 error LNK2019: unresolved external symbol NvAPI_GPU_GetFullName referenced in function...
and some similar errors.

Robert Crovella
  • 143,785
  • 11
  • 213
  • 257
  • 1
    It's a linker error, you missed to add some NVidia library – usr1234567 Dec 14 '14 at 17:49
  • 1
    In spite of the fact that you used a CUDA sample code, the question has nothing to do with CUDA. NVAPI is not a CUDA API, and all the problems you're reporting are related to NVAPI, not CUDA. – Robert Crovella Dec 14 '14 at 21:32
  • As I mentioned before, I copied all of .h files to include directory of cuda. So if a .h file is needed it should be found in those directories. – Kazem Shekofteh Dec 15 '14 at 20:13
  • Your problem has nothing to do with .h files. It is a **linker** problem. You need to link the nvapi.lib or nvapi64.lib into your project correctly. And it's not just about copying files from one place to another. Study [how to add a library](http://stackoverflow.com/questions/10571472/adding-a-library-to-visual-studio-2010-express) to the linker specification in visual studio. – Robert Crovella Dec 28 '14 at 17:40

1 Answers1

3

You need to goto your Project properties and expand Linker option -> Input and add the required nvapi*.lib file in Additional dependencies option.