Tag Archives: collect2: error: ld returned 1 exit status

[Solved] Nvml compilation official use case error: collect2: error: ld returned 1 exit status

Question

When running the example of nvml, an error is reported:

/tmp/tmpxft_00001d31_00000000-4_gpu_monitor.o: In the function ‘main’:
gpu_monitor.c:(.text+0x77): undefined reference to ‘nvmlInit_v2’
gpu_monitor.c:(.text+0x93): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0xcd): undefined reference to ‘nvmlDeviceGetCount_v2’
gpu_monitor.c:(.text+0xe9): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x15e): Undefined reference to ‘nvmlDeviceGetHandleByIndex_v2’
gpu_monitor.c:(.text+0x17a): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x1b4): undefined reference to ‘nvmlDeviceGetName’
gpu_monitor.c:(.text+0x1d0): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x208): Undefined reference to ‘nvmlDeviceGetPciInfo_v3’
gpu_monitor.c:(.text+0x224): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x282): undefined reference to ‘nvmlDeviceGetComputeMode’
gpu_monitor.c:(.text+0x2b6): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x318): undefined reference to ‘nvmlDeviceSetComputeMode’
gpu_monitor.c:(.text+0x334): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x379): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x3ce): undefined reference to ‘nvmlDeviceSetComputeMode’
gpu_monitor.c:(.text+0x3ea): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x423): Undefined reference to ‘nvmlDeviceGetPowerUsage’
gpu_monitor.c:(.text+0x43f): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x4a4): undefined reference to ‘nvmlShutdown’
gpu_monitor.c:(.text+0x4c0): undefined reference to ‘nvmlErrorString’
collect2: error: ld returned 1 exit status

Solution:

At the beginning, the above error occurs when compiling with the command nvcc – O example.C example.
compile successfully with the command nvcc – I – L/usr/lib – lnvidia ml example.C – O example