In my quite large CPP project (CMake/ninja) some library (maybe third party) exposes zstd as public or interface. Since I've switched to vcpkg the linker fails since it cant find the library -lzstd. I found all possible places that may expose the zstd library as PUBLIC and switched to PRIVATE, but I still can see the linker tries to link with -lzstd. Is there a way, for example, by analyzing CMake or ninja files to figure out where this -lzstd comes from? Maybe the linker can somehow assist in figuring it out?
            Asked
            
        
        
            Active
            
        
            Viewed 43 times
        
    0
            
            
        
        paleonix
        
- 2,293
 - 1
 - 13
 - 29
 
        kreuzerkrieg
        
- 3,009
 - 3
 - 28
 - 59
 
- 
                    try https://stackoverflow.com/questions/70003456/find-out-why-cmake-adds-specific-link-flags – Alan Birtles Aug 07 '23 at 15:16
 - 
                    Not sure if this'll work, but you can probably recursively go through [INTERFACE_LINK_LIBRARIES](https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_LINK_LIBRARIES.html) and [LINK_LIBRARIES](https://cmake.org/cmake/help/latest/prop_tgt/LINK_LIBRARIES.html#prop_tgt:LINK_LIBRARIES) starting from your main project until you eventually find zstd. – Wutz Aug 07 '23 at 15:29
 - 
                    @AlanBirtles not sure useful, I do see the zstd linked into third party, but this thirdparty uses `target_link_libraries` with PRIVATE to link with zstd, so I guess it cant expose it – kreuzerkrieg Aug 07 '23 at 15:40
 - 
                    1If the third party library isn't a shared library then it'll still pass the link to `zstd` onto targets that link to it even if it's `PRIVATE` – Alan Birtles Aug 07 '23 at 15:49
 - 
                    @AlanBirtles it is static library... wasnt aware it works this way. interesting... any workaround for this problem? Except switching to dynamic library? – kreuzerkrieg Aug 07 '23 at 16:01
 - 
                    1If you link to the third party library and it requires zstd then you'll have to link to it. Why not just install it? – Alan Birtles Aug 07 '23 at 16:16
 - 
                    This is what I did in the end, later on will rework the third party to use `vcpkg` instead of having zillion submodules. Thanks for the clarification! – kreuzerkrieg Aug 08 '23 at 07:48
 - 
                    I wonder if https://stackoverflow.com/a/22035388/11107541 could be of any help. maybe not if zstd isn't a target. – starball Aug 10 '23 at 01:17
 - 
                    Looks like it is the same as @AlanBirtles first comment – kreuzerkrieg Aug 10 '23 at 13:15