gpt4 book ai didi

visual-studio-code - 在带有 makefile 的 VSCODE 中使用英特尔 Fortran 编译器 - `make: ifort: Command not found`

转载 作者:行者123 更新时间:2023-12-05 05:39:49 25 4
gpt4 key购买 nike

我是 Fortran 的新手,所以请多多包涵。我有一个使用 Intel ifort 编译器运行的 Fortran 文件。我可以从命令行运行命令 ifort -fpp -D IFORT discrete-kb-edits.F -lpgplot,它将文件编译为 a.out 和有效。

现在,我正在尝试在支持 Fortran 的 Ubuntu 20.04LTS 上设置 VSCode 1.68。所以我配置了 C/C++ 插件和 Fortran 断点插件。我还创建了一个 Makefile,如下所示,并设置了一个 tasks.json 文件,以从 VSCode 运行 make 文件。

问题是当 VSCode 运行 make 时,它没有找到 ifort。我得到如下所示的输出:

> 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).

不知何故,我能够从终端编译并从常规终端找到 ifort,但是当从 VSCode 任务编译时,我收到关于未找到 ifort 的错误。

对 Intel 编译器的引用在 .zshrc 文件中。我在该 zsh 配置中运行 source ~/intel/oneapi/setvars.sh。所以看起来在运行 Vscode 任务时,它不会在运行 make 之前加载终端配置。

有没有办法配置 VSCode 以与 ifort 一起工作?

如果有帮助,这里是 make 文件和任务配置。如果需要任何其他信息,请告诉我。

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 文件。

{
"version": "2.0.0",
"tasks": [
{
"label": "make",
"type": "shell",
"command": "make -j4",
"options": {
"cwd": "${workspaceRoot}"
}
}
]
}

最佳答案

我遇到了同样的问题,通过在 tasks.json 中获取 setvars.h 解决了这个问题:

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

--force 仅在可能发生该文件之前已经以某种方式获取的情况下才需要。

关于visual-studio-code - 在带有 makefile 的 VSCODE 中使用英特尔 Fortran 编译器 - `make: ifort: Command not found`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72579755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com