Last active
January 24, 2024 21:30
-
-
Save scivision/8eba39796a21e179bde90b8622604143 to your computer and use it in GitHub Desktop.
GCC static exe linking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.14) | |
project(demo Fortran) | |
# --- static flags avoid users needing libgfortran etc. on their Windows system | |
# MacOS and Linux needs more caution as true static linking is an advanced topic. | |
# this does not guarantee a portable executable, careful testing is needed and possibly further options | |
set(static_link_flags) | |
if(MINGW AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") | |
set(static_link_flags -static -static-libgfortran) | |
# MinGW / MSYS2 special considerations: https://www.msys2.org/news/#2021-01-31-aslr-enabled-by-default | |
list(APPEND static_link_flags -Wl,--default-image-base-low) | |
endif() | |
# example | |
add_exectuable(main main.f90) | |
target_link_options(main PRIVATE ${static_link_flags}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment