Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Intel Fortran compiler in VSCODE with makefile - `make: ifort: Command not found`

I am new to Fortran, so please bear with me. I have a Fortran file that runs with the Intel ifort compiler. I can run the command ifort -fpp -D IFORT discrete-kb-edits.F -lpgplot from the command line, and it will compile the file to a.out and works.

Now, I am trying to setup VSCode 1.68 on Ubuntu 20.04LTS with Fortran support. So I configured the C/C++ plugin and the Fortran Breakpoints plugin. I also created a Makefile, as below, and I setup a tasks.json file, to run the make file from VSCode.

The problem is that when VSCode runs the make, it is not finding ifort. I am getting an output that looks like this:

> Executing task: make -j4 <

    ifort -fpp -D IFORT discrete-kb-edits.F -lpgplot
    make: ifort: Command not found
    make: *** [Makefile:7: main.o] Error 127
    The terminal process "/usr/bin/zsh '-c', 'make -j4'" failed to launch (exit code: 2).

Somehow I am able to compile from the terminal and find ifort from the regular terminal, but when compiling from VSCode tasks, I get an error about ifort not found.

The reference to the Intel compiler is in the .zshrc file. I run source ~/intel/oneapi/setvars.sh in that zsh config. So it seems like when running the Vscode task, it does not load the terminal config before running make.

Is there a way to configure VSCode to work with ifort?

Here is the make file and task configuration if it helps. Let me know if any additional information is needed.

Makefile:

# variables
FC=ifort
FFLAGS= -fpp -D IFORT

# compiling
main.o: discrete-kb-edits.F
    $(FC) $(FFLAGS) discrete-kb-edits.F -lpgplot

# cleanup
clean:
    rm *.o a.out

# run
run:
    make
    ./a.out

VSCode tasks.json file.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "make",
            "type": "shell",
            "command": "make -j4",
            "options": {
                "cwd": "${workspaceRoot}"
            }
        }
    ]
}
like image 382
krishnab Avatar asked Oct 17 '25 02:10

krishnab


1 Answers

I had the same problem and solved it by sourcing the setvars.h in the tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "make",
            "type": "shell",
            "command": "bash -c 'source /opt/intel/oneapi/setvars.sh --force && make'",
            "args": [],
            "options": {
                "cwd": "${workspaceRoot}"
            }
        }
    ]
}

The --force is only required if it could happen that the file was somehow already sourced before.

like image 63
Til Piffl Avatar answered Oct 18 '25 17:10

Til Piffl