# Using CMake to build the IMGUI Demo program

**URL:** https://discourse.cmake.org/t/using-cmake-to-build-the-imgui-demo-program/7038
**Category:** Usage
**Tags:** os:linux
**Created:** [December 8, 2022, 11:50pm UTC](https://discourse.cmake.org/t/using-cmake-to-build-the-imgui-demo-program/7038 "2022-12-08T23:50:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jochoalions](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/c57346/32.png) [@jochoalions](https://discourse.cmake.org/u/jochoalions)
#### Post date: [December 8, 2022, 11:50pm UTC](https://discourse.cmake.org/t/using-cmake-to-build-the-imgui-demo-program/7038/1 "2022-12-08T23:50:08Z")

</div>

CMake newbie here. Learning how to use CMake to compile the **Dear Imgui** demo program. The Library _libimgui.a_ seems to compile correctly without errors by running _make_ in its own directory. But the _imgui\_demo_ program does not compile correctly because the _libimgui.a_ is not being seen.

Any pointers are appreciated.

This is the CMakeLists.txt in the project directory (imgui-demo):

```auto
# 
# CMakeLists for building imgui_demo
# 

# Required Statement -- Always the first statement
cmake_minimum_required(VERSION 3.22.1)

# Set the Name of the name of the Project, becomes the value of PROJECT_NAME variable
project(imgui_demo)

# list of Source files that will be compiled into Object files
# The locations of these files are specified with the -S and -B options
# in the command line:
# cmake -S (where the sources are) -B (where the object files will be placed)
# cmake -S . -B ./build/ (example)
add_executable(${PROJECT_NAME}.out imgui_demo.cpp)

# Add path to subdirectory where CMakeLists.txt resides for IMGUI
add_subdirectory(/home/jorge/code-new/imgui-demo/external/imgui/)

target_include_directories(${PROJECT_NAME}.out
    PRIVATE /home/jorge/code-new/include/imgui
    )

# Add the subdirectory path in which a Library is located
# path can be relative or absolute
target_link_directories(${PROJECT_NAME}.out BEFORE
    PUBLIC /home/jorge/code-new/imgui-demo/external/imgui/
    )

# find_library(name CreateNewWindow path /home/jorge/code-new/include/imgui REQUIRED)

# Specify the Libraries to be linked with the Project (these are Library file names)
target_link_libraries(${PROJECT_NAME}.out imgui)

```

This is the CMakeLists.txt file for build the library in a subdirectory (external/imgui).

```auto
cmake_minimum_required(VERSION 3.22.1)

# CMake file for compiling the imgui library
project(imgui)

# Add THIS Directory in the top level CMakeLists.txt file using
# add_subdirectory(/home/jorge/code-new/imgui-demo/external/imgui/)

# Add the library that is built on this subdirectory.
add_library(imgui SHARED imgui.cpp imgui.h imgui_internal.h)

# target_include_directories(${PROJECT_NAME}.out PRIVATE Adder)
target_include_directories(imgui PRIVATE /home/jorge/code-new/include/imgui)

```

---

<div class="post-metadata">

### Author: ![markdewit\_ies](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/e95f7d/32.png) [@markdewit\_ies](https://discourse.cmake.org/u/markdewit_ies)
#### Post date: [December 14, 2022, 10:09am UTC](https://discourse.cmake.org/t/using-cmake-to-build-the-imgui-demo-program/7038/2 "2022-12-14T10:09:59Z")

</div>

your imgui library is declared as SHARED (ie, imgui.so) but you say your actual libimgui file is .a. So if you change it to a STATIC library, does that fix it?
