Enforce C linking language when using LLVMFortran on Darwin #123
Enforce C linking language when using LLVMFortran on Darwin #123piotrows wants to merge 1 commit intoecmwf:developfrom
Conversation
|
Hi @kynan, @wdeconinck, @marcosbento, would you care to look at it or suggest someone else? |
|
From my side, the proposed changes look OK, so I've approved the entire CI build. |
|
Really this is an issue with upstream CMake and not ecbuild. After investigation, this can be solved by a file set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "--shared")
set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG "-Wl,-install_name -Wl,")
set(CMAKE_Fortran_CREATE_SHARED_LIBRARY
"<CMAKE_Fortran_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS> <LINK_FLAGS> -o <TARGET> <SONAME_FLAG><TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")I have a small reproducer CMake project that I managed to get working, placing this file in a cmake subdirectory. cmake_minimum_required(VERSION 3.31)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
project(test_flag LANGUAGES Fortran)
add_library(mylib SHARED mylib.F90)
add_executable(main main.F90)
target_link_libraries(main mylib)The content of module mylib
contains
subroutine hello_world
write(0,*) "hello world"
end subroutine
end moduleprogram main
use mylib
call hello_world()
end programI did not investigate further if the file |
Description
Flang compiler doesn't recognize macOS-specific linker flags used by CMake:
e.g. when compiling Fiat:
flang-21: error: unknown argument: '-dynamiclib'
flang-21: error: unknown argument: '-install_name'
Following the hint from:
HDFGroup/hdf5#5662
it seems that the fix is to simply enforce C as a linker language for LLVMFortran.
This indeed seems to enable Fiat compilation with flang-21.
Contributor Declaration
By opening this pull request, I affirm the following: