# I got \`unresolved external symbol\` while using \`ExternalProject\_Add\`, how should I solve this?

**URL:** https://discourse.cmake.org/t/i-got-unresolved-external-symbol-while-using-externalproject-add-how-should-i-solve-this/6469
**Category:** Usage
**Created:** [September 13, 2022, 9:26am UTC](https://discourse.cmake.org/t/i-got-unresolved-external-symbol-while-using-externalproject-add-how-should-i-solve-this/6469 "2022-09-13T09:26:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Kiki](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kiki/32/2767_2.png) [@Kiki](https://discourse.cmake.org/u/Kiki)
#### Post date: [September 13, 2022, 9:26am UTC](https://discourse.cmake.org/t/i-got-unresolved-external-symbol-while-using-externalproject-add-how-should-i-solve-this/6469/1 "2022-09-13T09:26:33Z")

</div>

Here is my CMakeLists.txt:

```auto
ExternalProject_Add(
  subhook
  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"
  CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} -DSUBHOOK_STATIC=ON -DSUBHOOK_TESTS=OFF SUBHOOK_FORCE_32BIT=ON)

include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)

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

```

I will get this error

```auto
t_test.obj : error LNK2019: unresolved external symbol __imp__ subhook_new referenced in function ...

```

I cannot directory add

```auto
target_link_libraries(t_test subhook)

```

which may show this error:

```auto
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.

---

<div class="post-metadata">

### Author: ![vre](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@vre](https://discourse.cmake.org/u/vre)
#### Post date: [September 13, 2022, 9:32am UTC](https://discourse.cmake.org/t/i-got-unresolved-external-symbol-while-using-externalproject-add-how-should-i-solve-this/6469/2 "2022-09-13T09:32:29Z")

</div>

> [@Kiki](#):
>
> ```auto
> include_directories(${EXTERNAL_INSTALL_LOCATION}/include())
> 
> ```

Maybe the superfluous parentheses after the `include` string?

---

<div class="post-metadata">

### Author: ![Kiki](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kiki/32/2767_2.png) [@Kiki](https://discourse.cmake.org/u/Kiki)
#### Post date: [September 13, 2022, 10:22am UTC](https://discourse.cmake.org/t/i-got-unresolved-external-symbol-while-using-externalproject-add-how-should-i-solve-this/6469/3 "2022-09-13T10:22:55Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 17, 2022, 8:55pm UTC](https://discourse.cmake.org/t/i-got-unresolved-external-symbol-while-using-externalproject-add-how-should-i-solve-this/6469/4 "2022-10-17T20:55:06Z")

</div>

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
