# Not understanding why CMakeLists.txt is not finding my dependency.

**URL:** <https://discourse.cmake.org/t/not-understanding-why-cmakelists-txt-is-not-finding-my-dependency/11429>\
**Category:** Code\
**Created:** [August 12, 2024, 11:58am UTC](https://discourse.cmake.org/t/not-understanding-why-cmakelists-txt-is-not-finding-my-dependency/11429 "2024-08-12T11:58:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![djryanash](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@djryanash](https://discourse.cmake.org/u/djryanash)\
**Post date:** [August 12, 2024, 11:58am UTC](https://discourse.cmake.org/t/not-understanding-why-cmakelists-txt-is-not-finding-my-dependency/11429/1 "2024-08-12T11:58:55Z")

</div>

I’m new to C++ and CMake and trying to get started on a WASM audio synth project but having trouble linking the dependencies.

```auto
└── 📁cpp-wasm-audio-synth
    └── 📁build
        └── cmake_install.cmake
        └── Makefile
    └── click_sound.wav
    └── CMakeLists.txt
    └── main.cpp

```

CMakeLists.txt:

```auto
cmake_minimum_required(VERSION 3.22)

# Set the project name and version
project(RedButtonApp VERSION 1.0 LANGUAGES CXX)

# Find SDL2_mixer package
find_package(PkgConfig REQUIRED)
find_package(SDL2 REQUIRED)

set(SDL_MIXER_INCLUDE_DIRS /usr/local/Cellar/sdl2_mixer/2.8.0/include)
set(SDL_MIXER_LIBRARIES /usr/local/Cellar/sdl2_mixer/2.8.0/lib/libSDL2_mixer-2.0.0.dylib)

set(SDL_INCLUDE_DIRS /usr/local/Cellar/sdl2/2.30.6/include/SDL2)
set(SDL_LIBRARIES /usr/local/Cellar/sdl2/2.30.6/lib/libSDL2-2.0.0.dylib)
# Add executable
add_executable(RedButtonApp main.cpp)

# Link libraries
target_link_libraries(RedButtonApp ${SDL2_MIXER_LIBRARIES})

# Include directories for SDL2_mixer
include_directories(${SDL2_MIXER_INCLUDE_DIRS})
include_directories(${SDL_INCLUDE_DIRS})
link_directories(${SDL_MIXER_LIBRARIES})
link_directories(${SDL_LIBRARIES})

```

From Terminal, if I go `brew list sdl2` I get:

```auto
>> brew list sdl2                                                               
/usr/local/Cellar/sdl2/2.30.6/bin/sdl2-config
/usr/local/Cellar/sdl2/2.30.6/include/SDL2/ (78 files)
/usr/local/Cellar/sdl2/2.30.6/lib/libSDL2-2.0.0.dylib
/usr/local/Cellar/sdl2/2.30.6/lib/cmake/ (2 files)
/usr/local/Cellar/sdl2/2.30.6/lib/pkgconfig/sdl2.pc
/usr/local/Cellar/sdl2/2.30.6/lib/ (4 other files)
/usr/local/Cellar/sdl2/2.30.6/sbom.spdx.json
/usr/local/Cellar/sdl2/2.30.6/share/aclocal/sdl2.m4
…/visual-studio-projects/cpp-wasm-audio-synth/build took 3s 
>> 

```

But if I run:

```auto
>> rm -rf CMakeFiles CMakeCache.txt
cmake ..
make

```

I get:

```auto
-- The CXX compiler identification is AppleClang 15.0.0.15000309
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2")
-- Configuring done (0.5s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/<username>/Documents/visual-studio-projects/cpp-wasm-audio-synth/build
[50%] Building CXX object CMakeFiles/RedButtonApp.dir/main.cpp.o
/Users/<username>/Documents/visual-studio-projects/cpp-wasm-audio-synth/main.cpp:2:10: fatal error: 'SDL2/SDL.h' file not found
#include <SDL2/SDL.h>
         ^ ~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/RedButtonApp.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/RedButtonApp.dir/all] Error 2
make: *** [all] Error 2
…/visual-studio-projects/cpp-wasm-audio-synth/build via △ v3.30.2 
>> 

```

Don’t know why it doesn’t find my dependencies and not sure how to resolve it.

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [August 12, 2024, 12:42pm UTC](https://discourse.cmake.org/t/not-understanding-why-cmakelists-txt-is-not-finding-my-dependency/11429/2 "2024-08-12T12:42:00Z")

</div>

Looks like you are missing linking to `SDL2::SDL2` target. So instead of:

```cmake
target_link_libraries(RedButtonApp ${SDL2_MIXER_LIBRARIES})

```

there should be:

```cmake
target_link_libraries(RedButtonApp
    PRIVATE
        SDL2::SDL2
        #SDL2::SDL2main
        ${SDL2_MIXER_LIBRARIES} # is this one needed?
)

```

or whichever other targets you have in the `/path/to/homebrew/Cellar/sdl2/2.30.6/lib/cmake/SDL2/sdl2-config.cmake` in your system.

I would also recommend to use `find_package()` with `CONFIG`, since this SDL version/package seems to provide a CMake config.
