I am trying to use vscode to connect to wsl to compile my Fortran code with cmake. When I tried to configure my project, cmake report error says ifort is not able to compile a simple test program.The full cmake output is here:
[main] Building folder: program
[main] Configuring folder: program
[proc] Executing command: /usr/local/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_Fortran_COMPILER:FILEPATH=/opt/intel/oneapi/compiler/2021.3.0/linux/bin/intel64/ifort -DCMAKE_C_COMPILER:FILEPATH=/opt/intel/oneapi/compiler/2021.3.0/linux/bin/intel64/icc -H/home/user/program -B/home/user/program/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The Fortran compiler identification is Intel 2021.3.0.20210609
[cmake] -- Detecting Fortran compiler ABI info
[cmake] -- Detecting Fortran compiler ABI info - failed
[cmake] -- Check for working Fortran compiler: /opt/intel/oneapi/compiler/2021.3.0/linux/bin/intel64/ifort
[cmake] -- Check for working Fortran compiler: /opt/intel/oneapi/compiler/2021.3.0/linux/bin/intel64/ifort - broken
[cmake] CMake Error at /usr/local/lib/python3.8/dist-packages/cmake/data/share/cmake-3.21/Modules/CMakeTestFortranCompiler.cmake:54 (message):
[cmake] The Fortran compiler
[cmake]
[cmake] "/opt/intel/oneapi/compiler/2021.3.0/linux/bin/intel64/ifort"
[cmake]
[cmake] is not able to compile a simple test program.
[cmake]
[cmake] It fails with the following output:
[cmake]
[cmake] Change Dir: /home/user/program/build/CMakeFiles/CMakeTmp
[cmake]
[cmake] Run Build Command(s):/usr/bin/make -f Makefile cmTC_36220/fast && /usr/bin/make -f CMakeFiles/cmTC_36220.dir/build.make CMakeFiles/cmTC_36220.dir/build
[cmake] make[1]: Entering directory '/home/user/program/build/CMakeFiles/CMakeTmp'
[cmake] Building Fortran object CMakeFiles/cmTC_36220.dir/testFortranCompiler.f.o
[cmake] /opt/intel/oneapi/compiler/2021.3.0/linux/bin/intel64/ifort -c /home/user/program/build/CMakeFiles/CMakeTmp/testFortranCompiler.f -o CMakeFiles/cmTC_36220.dir/testFortranCompiler.f.o
[cmake] Linking Fortran executable cmTC_36220
[cmake] /usr/local/lib/python3.8/dist-packages/cmake/data/bin/cmake -E cmake_link_script CMakeFiles/cmTC_36220.dir/link.txt --verbose=1
[cmake] /opt/intel/oneapi/compiler/2021.3.0/linux/bin/intel64/ifort CMakeFiles/cmTC_36220.dir/testFortranCompiler.f.o -o cmTC_36220
[cmake] ld: /opt/intel/oneapi/compiler/2021.3.0/linux/bin/intel64/../../bin/intel64/../../lib/icx-lto.so: error loading plugin: libimf.so: cannot open shared object file: No such file or directory
[cmake] make[1]: *** [CMakeFiles/cmTC_36220.dir/build.make:99: cmTC_36220] Error 1
[cmake] make[1]: Leaving directory '/home/user/program/build/CMakeFiles/CMakeTmp'
[cmake] make: *** [Makefile:127: cmTC_36220/fast] Error 2
[cmake]
[cmake]
[cmake]
[cmake]
[cmake]
[cmake] CMake will not be able to correctly generate this project.
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:2 (project)
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "/home/user/program/build/CMakeFiles/CMakeOutput.log".
[cmake] See also "/home/user/program/build/CMakeFiles/CMakeError.log".
[cmake]
My compiler is ifort version 2021.3.0.20210609, cmake is 3.21.1 and wsl1 is Ubuntu20.04.
This problem looks exactly the same as some previous ones like CMake configuring fails. “cl.exe is not able to compile a simple test program” and CMake: The C Compiler is not able to compile a simple test program, but I found something weird:
I tried not to use the cmake plugin of vscode, but directly use cmake and make commands in the vscode built-in terminal and wsl terminal, everything is working fine. And the error only occurs when I start vscode through windows, all things work well when start vscode in wsl through
code .
There are also two other clues that make me very concerned. First, oneAPI needs users to add
source /opt/intel/oneapi/setvars.sh
in .bashrc to initialize oneAPI environment. So each time open the wsl terminal, it will first display:
:: initializing oneAPI environment ...
-bash: BASH_VERSION = 5.0.17(1)-release
:: advisor -- latest
:: ccl -- latest
:: clck -- latest
:: compiler -- latest
:: dal -- latest
:: debugger -- latest
:: dev-utilities -- latest
:: dnnl -- latest
:: dpcpp-ct -- latest
:: dpl -- latest
:: inspector -- latest
:: intelpython -- latest
:: ipp -- latest
:: ippcp -- latest
:: itac -- latest
:: mkl -- latest
:: mpi -- latest
:: tbb -- latest
:: vpl -- latest
:: vtune -- latest
:: oneAPI environment initialized ::
before user@host. On the computer which vscode and wsl working properly, when I open vscode and start a new terminal, it shows
:: WARNING: setvars.sh has already been run. Skipping re-execution.
To force a re-execution of setvars.sh, use the '--force' option.
Using '--force' can result in excessive use of your environment variables.
This seems to imply that when open vscode and connect to wsl but not explicitly start the vscode terminal, .bashrc has already been read correctly. However, on the computer where the problem occurs, start new vscode terminal shows "initializing oneAPI environment..." which as mentioned before, seems that even if connected to wsl, .bashrc is not automatically loaded.
The second clue is a line in the error message that says
ld: /opt/intel/oneapi/compiler/2021.3.0/linux/bin/intel64/../../bin/intel64/../../lib/icx-lto.so: error loading plugin: libimf.so: cannot open shared object file: No such file or directory
According to what I have searched: icc compiled code unable to load shared object (libimf.so), it means that some critical paths have not been added to environment variables, usually it is because the "source /opt/intel/oneapi/setvars.sh" line is not added in .bashrc to start the oneapi environment, and I obviously have already added it.
In short, all this makes me suspect that the connection between vscode and wsl is not set up correctly, but I don't know whether this conjecture is correct and how to solve it. I have tried a solution from here, but it didn't work. I am also very confused that the same configuration process will not cause any problems on other computers.
I apologize for such length of my description, any help would be much appreciated.