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.

1
2
3
4
5
6
7
8
9
10
// 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

1
2
3
4
5
6
7
- bin
-- main
- src
-- main.cpp
-- module.cpp
-- header.h
- Makefile

Makefile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 $@ #html#lt;

.c.o:
$(GC) -c $(HEADER) $(FLAGS) -fpermissive -o $@ #html#lt;

$(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.

1
pip install fortran-language-server

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

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

fprettify (Blamsoft)

Fortran code formatter.

1
pip install --upgrade fprettify

Integrating with VsCode, modify in your need:

1
2
3
4
// VsCode settings
{
"fprettify.arguments": "-i 4 --case 1 1 1 2"
}
上一篇
下一篇