# Remove the inner dependency when linked into the final target.

**URL:** <https://discourse.cmake.org/t/remove-the-inner-dependency-when-linked-into-the-final-target/13857>\
**Category:** Code\
**Created:** [March 31, 2025, 3:56am UTC](https://discourse.cmake.org/t/remove-the-inner-dependency-when-linked-into-the-final-target/13857 "2025-03-31T03:56:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![co-neco](https://discourse.cmake.org/user_avatar/discourse.cmake.org/co-neco/32/5452_2.png) [@co-neco](https://discourse.cmake.org/u/co-neco)\
**Post date:** [March 31, 2025, 3:56am UTC](https://discourse.cmake.org/t/remove-the-inner-dependency-when-linked-into-the-final-target/13857/1 "2025-03-31T03:56:42Z")

</div>

Hello, I want to build a shared library as follow on windows with VS generator:

```auto
add_library(A STATIC a.cpp)
add_library(B STATIC b.cpp)
target_link_libraries(B PRIVATE A)

add_library(Dyn SHARED 
    xx
    $<TARGET_OBJECTS:A>)

target_link_libraries(Dyn PRIVATE B)

```

when building Dyn library, there is a error that said a duplicate function(such as FuncA) in both a.obj and a.lib, the link was ‘lld-link … a.obj a.lib’.  
Because Dyn needs to export the functions in A, so I added $\<TARGET\_OBJECTS:A\>, and some other libaries need to link A, so I build A as a static library.

I modify the interface\_link\_libraries option of target B, and the error was gone, but other errors occurred, which said FuncA is not difined in other libraries that links to B, because other libraries did not link to A.

Therefore, I thought the only way to solve this problem is modify the options in target Dyn. Then I modified the interface\_link\_libraries option of target B before `target_link_libraries(Dyn PRIVATE B)` and restore B’s interface\_link\_libraries option after call `target_link_libraries(Dyn PRIVATE B)`, but it did not work, because cmake generated the VS project after these operations.

So is there any option to directly change Dyn target’s option so that the link line of Dyn target do not include a.lib? Thanks
