Friday, November 12, 2021

[SOLVED] How to link with ntdll.lib using CMake?

Issue

I am using ntdll.lib functions in my code to set the system timer to a higher resolution.

But when I build my project I get this error:

...
.../bin/ld.exe: ... undefined reference to `__imp_NtSetTimerResolution'
collect2.exe: error: ld returned 1 exit status
...

How do I tell the linker to link with ntdll.lib in my CMake?


Solution

This worked for me:

if (WIN32)
    target_link_libraries(executable ntdll)
endif()


Answered By - a_girl