- Notifications
You must be signed in to change notification settings - Fork2.5k
Nathan Moinvaziri edited this pageJan 19, 2024 ·3 revisions
cmake -S . -B build -D CMAKE_EXE_LINKER_FLAGS=-static -D CMAKE_SHARED_LINKER_FLAGS=-static
Use CMake'sCMAKE_MSVC_RUNTIME_LIBRARY option:
cmake -S . -B build -D CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
export LDFLAGS=-static./configure
If you are building from zlib sources with CMake:
project(myproject)add_subdirectory(zlib zlibEXCLUDE_FROM_ALL)# Use EXCLUDE_FROM_ALL to prevent all targets from being added to the solutionadd_executable(myproject myproject.c)target_link_libraries(myprojectPRIVATE zlibstatic)# Or "zlib" depending on whether or not you want the shared/static library
If you are using system libraries:
project(myproject)find_package(ZLIB REQUIRED)add_executable(myproject myproject.c)target_link_libraries(myprojectPRIVATE ZLIB::ZLIB)