'CMake "-Wl,--whole-archive" option for windows

I am trying to build an executable of a program/project. It worked in Linux, but for various reasons I need to run the program in Windows. I do not have any knowledge on CMake or C++.

I am running developer command prompt with mkdir build, cd build, cmake .. and make I am encountering this:

LINK : warning LNK4044: unrecognized option '/Wl,--whole-archive'; ignored 
LINK : warning LNK4044: unrecognized option '/Wl,--no-whole-archive'; ignored

I think the relevant portion of the CMakelists is this:

# This is necessary 
target_link_libraries(projectname
    "-Wl,--whole-archive" Evaluation
    "-Wl,--no-whole-archive")

The projectname is added as executable somewhere earlier in the cmakelists. I did a Google search and found some things, like the windows flag being /WHOLEARCHIVE. I couldn't find a clear explanation on which syntax I should be using, so I tried to change it in 3 different ways:

target_link_libraries(projectname "-Wl,/WHOLEARCHIVE" Evaluation)  

target_link_libraries(projectname "/WHOLEARCHIVE" Evaluation)

target_link_libraries(projectname "/WHOLEARCHIVE:" Evaluation)

None of these worked. They all caused the cmake .. command to not generate a makefile, so I ran cmake --build . instead, but it still resulted in errors like LINK : fatal error LNK1104: cannot open file '\WHOLEARCHIVE.obj' (for the middle one).

I also tried to just link it without the wholearchive flag, like the code above it is doing for some other folders. This also resulted in an error trying to build it (it can't find many functions as it seems the library is not linked or not linked properly).

Does anyone know how I can change this so it will work on windows?

EDIT: I also tried:

target_link_libraries(projectname
    other_lib
    Evaluation)

set_target_properties(projectname PROPERTIES LINK_FLAGS "/WHOLEARCHIVE:Evaluation")

Which compiles without generating a makefile, and cmake --build . ends with error LNK2019: unresolved external symbol for several functions which are in .cpp files in the folder of other_lib



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source