# failed to link the ".a" library into the project

**URL:** https://discourse.cmake.org/t/failed-to-link-the-a-library-into-the-project/10812
**Category:** Code
**Tags:** os:windows, gen:makefiles, gen:vs, tool:cmake
**Created:** [May 7, 2024, 11:43am UTC](https://discourse.cmake.org/t/failed-to-link-the-a-library-into-the-project/10812 "2024-05-07T11:43:13Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Vinay\_hs](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vinay_hs/32/4568_2.png) [@Vinay\_hs](https://discourse.cmake.org/u/Vinay_hs)
#### Post date: [May 7, 2024, 11:43am UTC](https://discourse.cmake.org/t/failed-to-link-the-a-library-into-the-project/10812/1 "2024-05-07T11:43:13Z")

</div>

HI,  
I created a static library named “libadd.a” using e2 Studio IDE. Later, I initiated a Renesas microcontroller project in Visual Studio Code utilizing the Renesas Build Utilities extension. Unfortunately, I faced challenges in linking the library file to my project. Could someone kindly provide a solution or suggest changes to integrate the static library into my project?

For reference, I have attached the link to the project file: [Microsoft OneDrive](https://1drv.ms/f/s!AtpJeB_KPU0lhxafcoVB4Qf5vNfh?e=h3ZVcQ)

---

<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: [May 7, 2024, 11:46am UTC](https://discourse.cmake.org/t/failed-to-link-the-a-library-into-the-project/10812/2 "2024-05-07T11:46:01Z")

</div>

What are the error messages, or how do those challenges manifest themselves?

---

<div class="post-metadata">

### Author: ![Vinay\_hs](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vinay_hs/32/4568_2.png) [@Vinay\_hs](https://discourse.cmake.org/u/Vinay_hs)
#### Post date: [May 7, 2024, 11:55am UTC](https://discourse.cmake.org/t/failed-to-link-the-a-library-into-the-project/10812/3 "2024-05-07T11:55:13Z")

</div>

I call a simple ‘add’ function to get the sum of 2 numbers. The library file contains this definition. When I build the project, I get the below-mentioned error:  
[build] D:\NexiGo\Code\VisualStudioCode\_Project\_Workspace\addition\src/hal\_entry.c:16: undefined reference to ‘add’.

---

<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: [May 7, 2024, 12:34pm UTC](https://discourse.cmake.org/t/failed-to-link-the-a-library-into-the-project/10812/4 "2024-05-07T12:34:01Z")

</div>

You are probably missing the actual linking to the library with [target\_link\_libraries()](https://cmake.org/cmake/help/latest/command/target_link_libraries.html).

---

<div class="post-metadata">

### Author: ![Vinay\_hs](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vinay_hs/32/4568_2.png) [@Vinay\_hs](https://discourse.cmake.org/u/Vinay_hs)
#### Post date: [May 8, 2024, 7:02am UTC](https://discourse.cmake.org/t/failed-to-link-the-a-library-into-the-project/10812/5 "2024-05-08T07:02:19Z")

</div>

I included the below-mentioned commands in the CMakeLists.txt

# Project minimum required CMake version

cmake\_minimum\_required(VERSION 3.16.4)

# Project configuration

project(addition  
VERSION 1.0.0  
LANGUAGES C CXX ASM)

include(${CMAKE\_CURRENT\_LIST\_DIR}/cmake/GeneratedSrc.cmake)

# Link the library to the executable

target\_link\_libraries(${PROJECT\_NAME}.elf src/libadd.a)
