VsCode Fortran开发环境配置

VsCode Fortran Settings

Modern Fortran [Miguel Carvajal]

Fortran highlight plugin.

C/C++ for Visual Studio Code [Microsoft]

C/C++ debug plugin also supports fortran.

Toggle debug and modify the example launch.json and tasks.json files.

Makefile Tools [Microsoft, optional]

You can set make command in tasks.json or use this plugin to compile make project.

// vscode settings
{
	"makefile.launchConfigurations": [
		{
			"cwd": "/home/user/project",
			"binaryPath": "/home/user/project/bin/program",
			"binaryArgs": []
		}
	]
}

Here is a example for C/C++ make project.

Directory tree

- bin
-- main
- src
-- main.cpp
-- module.cpp
-- header.h
- Makefile

Makefile

LINK    = @echo linking $@ && g++
GCC     = @echo compiling $@ && g++
GC      = @echo compiling $@ && gcc
AR      = @echo generating static library $@ && ar crv
FLAGS   = -g -DDEBUG -W -Wall -fPIC
GCCFLAGS =
DEFINES =
HEADER  = -I./
LIBS    =
LINKFLAGS =

BIN_PATH = bin
SRC = $(wildcard src/*.cpp)
INCLUDES = include
TARGET = main
OBJECT = $(SRC:%.cpp=%.o)

.SUFFIXES: .cpp .c
.cpp.o:
	$(GCC) -c $(HEADER) $(FLAGS) $(GCCFLAGS) -fpermissive -o $@ $<

.c.o:
	$(GC) -c $(HEADER) $(FLAGS) -fpermissive -o $@ $<

$(TARGET) : $(OBJECT)
	@echo "============开始编译============"
	$(LINK) $(FLAGS) $(LINKFLAGS) -o $@ $^ $(LIBS)
	mv $(TARGET) $(BIN_PATH)
	@echo "============编译结束============"

clean:
	rm -rf $(OBJECT) $(TARGET)

FORTRAN IntelliSense (Chris Hansen)

Install fortran-language-server and create .fortls file if you need to modify the default configuration.

pip install fortran-language-server

An example of .fortls to add external source of hdf5 libs.

{
	"ext_source_dirs": ["/home/user/hdf5/fortran/src"],
	"debug_log": true
}

fprettify (Blamsoft)

Fortran code formatter.

pip install --upgrade fprettify

Integrating with VsCode, modify in your need:

// VsCode settings
{
	"fprettify.arguments": "-i 4 --case 1 1 1 2"
}

作者:PorYoung
原文地址:https://blog.poryoung.cn/?p=1190
发布时间:2021年3月22

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在VSCode中配置Fortran环境,您可以按照以下步骤进行操作: 1. 安装VSCode:首先,请确保您已经安装了最新版本的VSCode编辑器。您可以从VSCode官方网站(https://code.visualstudio.com/)下载并安装它。 2. 安装Fortran扩展:在VSCode中,您需要安装Fortran扩展以获得Fortran语言支持。打开VSCode并点击左侧的扩展图标(或使用快捷键Ctrl+Shift+X),然后搜索并安装“Fortran”扩展。 3. 配置Fortran编译器:在VSCode中,按下Ctrl+Shift+P打开命令面板,然后输入“Fortran: Select a Fortran compiler”,选择一个Fortran编译器。如果您已经在系统中安装了编译器,它们将显示在列表中。如果没有安装编译器,您可以从gfortran(https://gcc.gnu.org/wiki/GFortranBinaries)或Intel Parallel Studio(https://software.intel.com/content/www/us/en/develop/tools/parallel-studio-xe.html)等来源下载并安装一个。 4. 创建Fortran项目:在VSCode中,按下Ctrl+Shift+P打开命令面板,然后输入“Fortran: New Project”,选择一个位置并输入项目名称。这将创建一个包含默认文件和文件夹结构的新的Fortran项目。 5. 编写和运行代码:在VSCode中,您可以使用内置的代码编辑器编写Fortran代码。要运行代码,您可以按下F5键或使用菜单栏中的“调试”选项。您还可以使用终端来手动编译和运行代码。 这些步骤应该能帮助您在VSCode中配置和使用Fortran环境。祝您编程愉快!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值