# Undefined Reference - C GCC

**URL:** <https://discourse.cmake.org/t/undefined-reference-c-gcc/8481>\
**Category:** Code\
**Tags:** gen:ninja\
**Created:** [July 10, 2023, 6:16am UTC](https://discourse.cmake.org/t/undefined-reference-c-gcc/8481 "2023-07-10T06:16:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akash\_01](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/b38774/32.png) [@Akash\_01](https://discourse.cmake.org/u/Akash_01)\
**Post date:** [July 10, 2023, 6:16am UTC](https://discourse.cmake.org/t/undefined-reference-c-gcc/8481/1 "2023-07-10T06:16:02Z")

</div>

Hai,  
I was facing Undefined reference when doing the compilation. I could see no error during the project file compilation in linking stage the error occurred as undefined reference

```auto
cmd.exe /C "cd . && C:\Programfiles\gcc\5.1.0\bin\gcc.exe -shared -o Sample_project\Source_Files\Project.dll -Wl,--out-implib,Sample_project\Source_Files\Project.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\SAE_Proj.rsp && cd ."
  Sample_project/Source_Files/CMakeFiles/Sampleproject.dir/Load_dll.c.obj:Load_dll.c:(.text+0x166): undefined reference to `__imp_PathRemoveFileSpecA'

```

My cmakelist.txt

```auto
file(GLOB SIL_SOURCES "*.c")
set (SourceFiles ${Sample_sources})

add_library(Sample_project SHARED ${SourceFiles})

target_include_directories (Sample_project PUBLIC $ENV{WINDOWSSDKDIR}/Include)
target_include_directories (Sample_project PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../External_Dependencies)

```

I am not sure why this error occurred during the linking no in the compilation and the error is related to some windows include file.

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [July 10, 2023, 9:43am UTC](https://discourse.cmake.org/t/undefined-reference-c-gcc/8481/2 "2023-07-10T09:43:43Z")

</div>

> **[PathRemoveFileSpecA function (shlwapi.h) - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-pathremovefilespeca)**
>
> Removes the trailing file name and backslash from a path, if they are present. (ANSI)

You need to link the mentioned library.
