# Problem with .so linking

**URL:** https://discourse.cmake.org/t/problem-with-so-linking/6497
**Category:** Usage
**Tags:** os:linux
**Created:** [September 17, 2022, 5:42am UTC](https://discourse.cmake.org/t/problem-with-so-linking/6497 "2022-09-17T05:42:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![skgoswami](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@skgoswami](https://discourse.cmake.org/u/skgoswami)
#### Post date: [September 17, 2022, 5:42am UTC](https://discourse.cmake.org/t/problem-with-so-linking/6497/1 "2022-09-17T05:42:51Z")

</div>

My application building with .so file is failing in the linking stage. When I make the file name as MySecond\_digital.so it is reporting not able to find the file and when I am naming it libMySecond\_digital.so all the calls used in my application defined in the .so is reporting undefined reference. Pl. see if any of you can help me. I am struggling with it for quite a few days.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 18, 2022, 12:41pm UTC](https://discourse.cmake.org/t/problem-with-so-linking/6497/2 "2022-09-18T12:41:34Z")

</div>

How are the link lines that cannot find `MySecond_digital.so` being told to find it?

As for the undefined references, can you show what compilation flags are being used on one of its sources?

---

<div class="post-metadata">

### Author: ![skgoswami](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@skgoswami](https://discourse.cmake.org/u/skgoswami)
#### Post date: [September 19, 2022, 2:28am UTC](https://discourse.cmake.org/t/problem-with-so-linking/6497/3 "2022-09-19T02:28:40Z")

</div>

Undefined refrence with libMyDigital.so is solved. It was a coding issue. MyDigital.so linking is required to be seen further.

---

<div class="post-metadata">

### Author: ![skgoswami](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@skgoswami](https://discourse.cmake.org/u/skgoswami)
#### Post date: [September 21, 2022, 1:21pm UTC](https://discourse.cmake.org/t/problem-with-so-linking/6497/4 "2022-09-21T13:21:23Z")

</div>

Sorry I was away from my workstation and hence could not response you properly.  
The code in CMakeLists.txt for linking library was as below

find\_library(MyLib NAMES MySecond\_digital.so PATHS /home/skgoswami/Desktop/MySecond.digital/MySecond.digital/binaries/linux64)  
message(${MyLib})  
target\_link\_libraries(MyFMI ${MyLib})

This was not able to locate the .so file despite path copied was perfect. I was advised by one colleague to append ‘lib’ to the .so file name, as gcc linker expects the same for .so. Though it was an unexpected solution but it worked after correcting the main calls defined in .so files. It was a black box FMU and hence I was not fully aware of the calls.  
If you have any further observations pl. share.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 21, 2022, 1:24pm UTC](https://discourse.cmake.org/t/problem-with-so-linking/6497/5 "2022-09-21T13:24:35Z")

</div>

`NAMES` might want to be just `MySecond_digital` here as the search knows to append the “normal” suffix. You can use `--debug-find` to get CMake to output information about its searches; that should help figure out why it doesn’t find the file.

---

<div class="post-metadata">

### Author: ![skgoswami](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@skgoswami](https://discourse.cmake.org/u/skgoswami)
#### Post date: [September 23, 2022, 12:52pm UTC](https://discourse.cmake.org/t/problem-with-so-linking/6497/6 "2022-09-23T12:52:35Z")

</div>

I am in learning phase over cmake and surely will try your debug command. However now my application is getting built without ‘lib’ appending i.e. with MySecond\_digital.so. Things are unexplainable why so. I was somehow not convinced with my colleague’s suggestion but it worked and was failing with my code. If code correction was the reason but then why it was reporting not able to find MySecond\_digital.so, so many doubts. Probably I will have to go back in reverse order to recreate. Let me see if I can and report you back. Thanks for your time trying to help me.
