0
votes

I am generating a VisualStudio project for Windows with cmake and the provided linking functions don't appear to work on the generated VisualStudio project.

The generated project is a library and it relies on another library as a dependency.

Generation of the project works fine but nothing appears under "Additional Dependencies" entry whatever i try.

I tried using both "link_libraries" and "target_link_libraries", both before and after stating "add_library( MyLib )" I tried this for instance:

project( MyLib )
...
add_library( MyLib ${source_list} )
...
target_link_libraries ( MyLib ${SOME_LIB_PATH} )
target_link_libraries ( MyLib "${SOME_LIB_PATH}" )
target_link_libraries ( MyLib W:/work/Project/MyLib/ )
target_link_libraries ( MyLib "W:/work/Project/MyLib/" )
target_link_libraries ( MyLib W:/work/Project/MyLib/MyLib.lib )
target_link_libraries ( MyLib "W:/work/Project/MyLib/MyLib.lib" )
target_link_libraries ( MyLib banane )
target_link_libraries ( MyLib whatever )
target_link_libraries ( MyLib "test" )
...
include_directories(
    "Include/"
    ${SOME_LIB_INCLUDE_PATH}
)

Include directories appear correctly in the project properties though. So is that a bug or am i missing something :) ?

1
Actually, your code looks not that bad. However, please, be aware (static) libs are not linked against each other. (Instead, the executable is linked against these libs.) DLLs are. Is MyLib dedicated to become a static library or a DLL? (There should be another setting in CMake to determine this but it's not exposed and I don't remember if there are defaults and which.) - Scheff's Cat
Found it in doc.: BUILD_SHARED_LIBS. - Scheff's Cat
That's funny: I looked into one of my recent CMake projects which I made from scratch (instead of re-using an older/working). I searched for define/assignment of BUILD_SHARED_LIBS and couldn't find any. Oops. (Conditions using it, but no definition.) Then I looked into the VS project of a lib and, really, it's built as static lib. That was not intended (though it doesn't bother - code is written to work in both cases). Btw. I looked into the dependencies (of that lib depending on Qt) and yes, I can confirm, no additional dependencies (as they are not needed - as I explained above). - Scheff's Cat
I guess it was a big misunderstanding from my part then, see i was not aware that libs were not actually linking against each other and i was very confused when i saw the build was succeeding although the .lib was not linked ... - Layl

1 Answers

0
votes

Scheff pointed me in the right direction by recalling that a static library is not actually linked against other potential static libraries.

Even though VisualStudio allow to specify a static library dependancy in its UI, it is actually not happening and CMake shows this by actually not adding it in the generated project; that was the confusing part.

A static library can compile fine without being explicitely link to another static library dependancy, even if it uses code from it, as long as the final executable links with the said library AND its library dependancies, if i am not mistaken.

So thank you @Scheff for his comment !