# Linking using GCC goes wrong

**URL:** https://discourse.cmake.org/t/linking-using-gcc-goes-wrong/4698
**Category:** Usage
**Tags:** os:windows
**Created:** [December 17, 2021, 9:57am UTC](https://discourse.cmake.org/t/linking-using-gcc-goes-wrong/4698 "2021-12-17T09:57:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Olivier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.cmake.org/u/Olivier)
#### Post date: [December 17, 2021, 9:57am UTC](https://discourse.cmake.org/t/linking-using-gcc-goes-wrong/4698/1 "2021-12-17T09:57:14Z")

</div>

Hello,

I’m trying to cross compile a project from my windows machine to an ARM Linux one.  
This project already exists, I just set up a CMake structure in order to get the full control of my build system. The compilation steps works quite well, but when I reach the link step, I don’t understand why the command generated by CMake isn’t how I want to.

Here are some technical infos :  
1 - I have a FindMyLib1.cmake which set IMPORTED\_LOCATION\_RELEASE to the relative path of myLib1.a  
1 bis - the same for myLib2 (which is also linked to myLib)  
2 - In my top CMake, I call find\_package(MyLib) which works like a charm (because I can print the path of myLib)  
3 - In my project Cmake, I call the target\_link\_libraries(myProject PRIVATE $\<$\<C\_COMPILER\_ID:GNU\>:MyLib1\>  
$\<$\<C\_COMPILER\_ID:GNU\>:MyLib2\>  
$\<$\<C\_COMPILER\_ID:GNU\>:stdc++\>)

And I hope that the command would be : \>gcc.exe [compiler parameters] @CMakeFiles/MyProject.dir/objects1.rsp -o MyProject.elf -LMyLib1Path -lmyLib1 -LMyLib2Path -lmyLib2 -lstdc++

Instead, the command line generated is : \>gcc.exe [compiler parameters @CMakeFiles/MyProject.dir/objects1.rsp -o MyProject.elf MyLib1Path/myLib1.a MyLib2Path/myLib2.a-lstdc++

And this line doesn’t work I have a lot of linking errors for the methods of myLib2 which uses linked method to myLib1

Do you have any suggestion on what I am doing wrong ?

Thank you.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [December 17, 2021, 10:00am UTC](https://discourse.cmake.org/t/linking-using-gcc-goes-wrong/4698/2 "2021-12-17T10:00:46Z")

</div>

Specify absolute path for `IMPORTED_LOCATION_RELEASE` property.

---

<div class="post-metadata">

### Author: ![Olivier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.cmake.org/u/Olivier)
#### Post date: [December 17, 2021, 10:16am UTC](https://discourse.cmake.org/t/linking-using-gcc-goes-wrong/4698/3 "2021-12-17T10:16:12Z")

</div>

Here is the declaration :

```auto
#Release configurations
set_property(TARGET MyLib1 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(MyLib1 PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
    IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/Application/Library/MyLib1/Delivery/ARM_HF_GCC/MyLib1.a"
)

```

---

<div class="post-metadata">

### Author: ![Olivier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.cmake.org/u/Olivier)
#### Post date: [January 4, 2022, 9:52am UTC](https://discourse.cmake.org/t/linking-using-gcc-goes-wrong/4698/4 "2022-01-04T09:52:04Z")

</div>

Actually, I don’t understand why I can’t link with absolute path: my symbols are not found.  
If I manually launch the command with the -L[lib folder] and -l[lib name] it works like a charm … But I can’t generate it through my CMakeLists…

Any suggestion ?
