# How can I include a external dependency source c file

**URL:** <https://discourse.cmake.org/t/how-can-i-include-a-external-dependency-source-c-file/3122>\
**Category:** Usage\
**Created:** [April 12, 2021, 1:27pm UTC](https://discourse.cmake.org/t/how-can-i-include-a-external-dependency-source-c-file/3122 "2021-04-12T13:27:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![longjiang321](https://discourse.cmake.org/user_avatar/discourse.cmake.org/longjiang321/32/1358_2.png) [@longjiang321](https://discourse.cmake.org/u/longjiang321)\
**Post date:** [April 12, 2021, 1:27pm UTC](https://discourse.cmake.org/t/how-can-i-include-a-external-dependency-source-c-file/3122/1 "2021-04-12T13:27:55Z")

</div>

I am trying to start opengl develop with cMake on Qt, the base informations are as below:  
glad: version4.6; glfw: version3.3.4, QT: version5.12.  
the file tree as below:

 ![image](https://discourse.cmake.org/uploads/default/original/2X/4/41feef920924d67abf25395915746360894b9ca2.png)

my cmake are as below:  
cmake\_minimum\_required(VERSION 3.5)

```
project(opengl1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(GLFW_3P ${PROJECT_ROOT_DIR}/3rdpart/glfw)
set(GLAD_3P ${PROJECT_ROOT_DIR}/3rdpart/glad)
set(GLAD_FILE ${GLAD_3P}/src/glad.c)

add_executable(opengl1
    main.cpp
    ${GLAD_FILE}) # **acttually, this file add failed**

target_include_directories(opengl1
    PUBLIC ${GLFW_3P}/include
    PUBLIC ${GLAD_3P}/include
    )
find_library(GLFW_LIB glfw3 HINTS {GLFW_3P}/lib)

target_link_libraries(opengl1 ${GLFW_LIB})

```

but when compile, all the functions located in glad.c are “undefined reference to”, the file glad.c not invove compile:  
`cmd.exe /C "cd . && C:\Qt\Tools\mingw810_64\bin\g++.exe -g src/CMakeFiles/opengl1.dir/main.cpp.obj -o src\opengl1.exe -Wl,--out-implib,src\libopengl1.dll.a -Wl,--major-image-version,0,--minor-image-version,0 C:/openGl/glfw/lib/libglfw3.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."`

**Q: how can I include a external c file successfully?** (thank you so much if get you response)

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [April 12, 2021, 1:38pm UTC](https://discourse.cmake.org/t/how-can-i-include-a-external-dependency-source-c-file/3122/2 "2021-04-12T13:38:06Z")

</div>

Is it possible that your \*.c files are simply getting ignored because you only have enabled CXX language?

---

<div class="post-metadata">

**Author:** ![longjiang321](https://discourse.cmake.org/user_avatar/discourse.cmake.org/longjiang321/32/1358_2.png) [@longjiang321](https://discourse.cmake.org/u/longjiang321)\
**Post date:** [April 12, 2021, 1:47pm UTC](https://discourse.cmake.org/t/how-can-i-include-a-external-dependency-source-c-file/3122/3 "2021-04-12T13:47:39Z")

</div>

hi my friends, thank you so much for your big help, this fucking issue had takes me three days, your advice is useful. When you come to Beijing, I’ll treat you to dinner!!!, thank you again

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [April 12, 2021, 2:15pm UTC](https://discourse.cmake.org/t/how-can-i-include-a-external-dependency-source-c-file/3122/4 "2021-04-12T14:15:33Z")

</div>

Sometimes you just need a fresh eye.

Glad I could help.
