Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28952 Discussions

Compilation fails when using intel compilers for Fortran ctest example

qqqqq
Beginner
257 Views

On the HPC system I'm using, I'm trying out the ctest example for Fortran from https://github.com/dryman/fortran_unit_test/tree/main.

As in the repository README example, I have a file `my_tests.f90` that looks like
```
! my_tests.f90
module my_tests_mod
use iso_fortran_env
use iso_c_binding
implicit none
contains

integer function my_test_success() result(ret) bind(C)
ret = 0
end function my_test_success

integer function my_test_fail() result(ret) bind(C)
ret = 1
end function my_test_fail

end module my_tests_mod

```

and the `CMakeLists.txt` is
```
cmake_minimum_required(VERSION 3.18)

project(cmake_test)
enable_language(Fortran)

enable_testing()

set(TEST_LIST
my_test_success
my_test_fail
)
create_test_sourcelist(_ my_tests_main.c ${TEST_LIST})
add_executable(my_tests my_tests_main.c my_tests.f90)

foreach (test ${TEST_LIST})
add_test(NAME ${test} COMMAND my_tests ${test})
endforeach ()

```

Running `cmake -B build` and `cmake --build build` successfully compiles the project when using gfortran. However, when I use the intel compilers that are installed on my HPC system, it doesn't work. This is the output and error that I'm getting:


$ cmake -B build

-- The C compiler identification is IntelLLVM 2023.2.0
-- The CXX compiler identification is IntelLLVM 2023.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler:PATH_TO_INTEL_ONEAPI/intel-oneapi-compilers-2023.2.1-qlb6hkr3iyhanhvq4oycb562sskibrff/compiler/2023.2.1/linux/bin/icx - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler:PATH_TO_INTEL_ONEAPI/intel-oneapi-compilers-2023.2.1-qlb6hkr3iyhanhvq4oycb562sskibrff/compiler/2023.2.1/linux/bin/icpx - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Fortran compiler identification is IntelLLVM 2023.2.0
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Check for working Fortran compiler:PATH_TO_INTEL_ONEAPI/intel-oneapi-compilers-2023.2.1-qlb6hkr3iyhanhvq4oycb562sskibrff/compiler/2023.2.1/linux/bin/ifx - skipped
-- Checking whetherPATH_TO_INTEL_ONEAPI/intel-oneapi-compilers-2023.2.1-qlb6hkr3iyhanhvq4oycb562sskibrff/compiler/2023.2.1/linux/bin/ifx supports Fortran 90
-- Checking whetherPATH_TO_INTEL_ONEAPI/intel-oneapi-compilers-2023.2.1-qlb6hkr3iyhanhvq4oycb562sskibrff/compiler/2023.2.1/linux/bin/ifx supports Fortran 90 - yes
-- Configuring done
-- Generating done
-- Build files have been written to: PATH_TO_INTEL_ONEAPI/cmake_test/build

$ cmake --build build
Scanning dependencies of target my_tests
[ 33%] Building Fortran object CMakeFiles/my_tests.dir/my_tests.f90.o
[ 66%] Building C object CMakeFiles/my_tests.dir/my_tests_main.c.o
[100%] Linking Fortran executable my_tests
ld: CMakeFiles/my_tests.dir/my_tests_main.c.o: in function `main':
my_tests_main.c:(.text+0x0): multiple definition of `main'; PATH_TO_INTEL_ONEAPI/intel-oneapi-compilers-2023.2.1-qlb6hkr3iyhanhvq4oycb562sskibrff/compiler/2023.2.1/linux/compiler/lib/intel64_lin/for_main.o:for_main.c:(.text+0x0): first defined here
ld: PATH_TO_INTEL_ONEAPI/intel-oneapi-compilers-2023.2.1-qlb6hkr3iyhanhvq4oycb562sskibrff/compiler/2023.2.1/linux/compiler/lib/intel64_lin/for_main.o: in function `main':
for_main.c:(.text+0x19): undefined reference to `MAIN__'
gmake[2]: *** [CMakeFiles/my_tests.dir/build.make:112: my_tests] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/my_tests.dir/all] Error 2
gmake: *** [Makefile:101: all] Error 2

Labels (1)
0 Kudos
1 Reply
TobiasK
Moderator
138 Views

@qqqqq

Please give more details on how you set the compiler to ifx/icx. This looks wrong: (note the PATH_TO_INTEL_ONEAPI)


-- Check for working C compiler:PATH_TO_INTEL_ONEAPI/intel-oneapi-compilers-2023.2.1-qlb6hkr3iyhanhvq4oycb562sskibrff/compiler/2023.2.1/linux/bin/icx - skipped


second, please use cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON to see what is actually happening


third, please use the latest icx/ifx compiler 2025.0.4. 




0 Kudos
Reply