I got `unresolved external symbol` while using `ExternalProject_Add`, how should I solve this?

Here is my CMakeLists.txt:

  GIT_REPOSITORY https://github.com/Zeex/subhook.git
  GIT_TAG v0.8.2
  SOURCE_DIR        "${CMAKE_CURRENT_BINARY_DIR}/subhook-src"
  BINARY_DIR        "${CMAKE_CURRENT_BINARY_DIR}/subhook-build"


add_executable(t_test ${_testfile})
add_dependencies(t_test subhook)

I will get this error

t_test.obj : error LNK2019: unresolved external symbol __imp__subhook_new referenced in function ...

I cannot directory add

target_link_libraries(t_test subhook)

which may show this error:

CMake Error at test/base/CMakeLists.txt:24 (target_link_libraries):
  Target "subhook" of type UTILITY may not be linked into another target.
  One may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

I’m on windows.
How can I fix this one?
Thanks everyone for reading.

Maybe the superfluous parentheses after the include string?

Hi Volker, I fixed the typo but I still got the same error.

You need to link to the library that will be built. ExternalProject_add doesn’t mix well with add_library. I think you might want FetchContent here.

Cc: @craig.scott