tile

User Routines 配置实现demo

[!] 官方明确要求安装顺序是Intel Fortran,然后安装Visual studio,以保证其正确集成到环境中.

1772961119140

[√] 需要的软件版本及环境

1
2
3
simpack:2021X
Fortran:2022(要求2019以下)
visual studio:2022

使用2022版本

C:\Program Files (x86)\Intel\oneAPI\setvars.bat改名为ifortvars.bat的测试效果如下

1772790161845

2013使用显示错误

C:\Program Files (x86)\Intel\Composer XE 2013 SP1\bin\ifortvars.bat

1772794316042

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
** INFO: setting user directory to 'C:/Users/chenl/Desktop/delllll/userRoutines/training'
** INFO: setting default cmake generator to 'NMake Makefiles'
ERROR: Visual Studio 2008, 2010, 2012 or 11 is not found in the system.
SIMPACK_ADD_F_COMPILER_FLAG :
SIMPACK_ADD_C_COMPILER_FLAG :
SIMPACK_ADD_CXX_COMPILER_FLAG :
SIMPACK_ADD_INCLUDE :
SIMPACK_ADD_LINK_FLAG :
SIMPACK_ADD_EXT_OBJ :
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/chenl/Desktop/delllll/userRoutines/training/build/win64/debug
系统找不到指定的文件.
CMake Error: Generator: execution of make failed. Make command was: nmake /nologo &&


2019设置错误

C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.5.281\windows\bin\ifortvars.bat

1772803493118

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
** INFO: setting user directory to 'C:/Users/chenl/Desktop/delllll/userRoutines/training'
** INFO: setting default cmake generator to 'NMake Makefiles'

Intel(R) MPI Library 2019 Update 5 for Windows* Target Build Environment for Intel(R) 64 applications
Copyright 2007-2019 Intel Corporation.


ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
SIMPACK_ADD_F_COMPILER_FLAG :
SIMPACK_ADD_C_COMPILER_FLAG :
SIMPACK_ADD_CXX_COMPILER_FLAG :
SIMPACK_ADD_INCLUDE :
SIMPACK_ADD_LINK_FLAG :
SIMPACK_ADD_EXT_OBJ :
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/chenl/Desktop/delllll/userRoutines/training/build/win64/debug
系统找不到指定的文件.
CMake Error: Generator: execution of make failed. Make command was: nmake /nologo &&

多次尝试之后问题出在fortran无法识别 vs2019 的问题,所以我们显式的指定位置.同时将ifort添加到系统路径

VS2019INSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise

1772879382003

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
** INFO: setting user directory to 'C:/Users/chenl/Desktop/delllll/userRoutines/training'
** INFO: setting default cmake generator to 'NMake Makefiles'

Intel(R) MPI Library 2019 Update 4 for Windows* Target Build Environment for Intel(R) 64 applications
Copyright 2007-2019 Intel Corporation.

Copyright (C) 1985-2019 Intel Corporation. All rights reserved.
Intel(R) Compiler 19.0 Update 4 (package 228)

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.11.53
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
-- The C compiler identification is MSVC 19.29.30159.0
-- The CXX compiler identification is MSVC 19.29.30159.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Fortran compiler identification is Intel 19.0.4.20190417
-- Check for working Fortran compiler: C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.4.228/windows/bin/intel64/ifort.exe
-- Check for working Fortran compiler: C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.4.228/windows/bin/intel64/ifort.exe - works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.4.228/windows/bin/intel64/ifort.exe supports Fortran 90
-- Checking whether C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.4.228/windows/bin/intel64/ifort.exe supports Fortran 90 - yes
SIMPACK_ADD_F_COMPILER_FLAG :
SIMPACK_ADD_C_COMPILER_FLAG :
SIMPACK_ADD_CXX_COMPILER_FLAG :
SIMPACK_ADD_INCLUDE :
SIMPACK_ADD_LINK_FLAG :
SIMPACK_ADD_EXT_OBJ :
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/chenl/Desktop/delllll/userRoutines/training/build/win64/debug
Scanning dependencies of target user
[ 33%] Building Fortran object CMakeFiles/user.dir/simpack.f.obj
[ 66%] Building Fortran object CMakeFiles/user.dir/mbselem/usurface.f.obj
[100%] Linking CXX shared library user.dll
���ڴ����� user.lib �Ͷ��� user.exp
���ڴ����� user.lib �Ͷ��� user.exp
Copying user shared library to C:/Users/chenl/Desktop/delllll/userRoutines/training/lib/win64 ...
[100%] Built target user


使用2022的环境时
VS2019INSTALLDIR=C:\Program Files\Microsoft Visual Studio\2022\Professional

其他设置保持不变

1772880809363

可以正常编译:

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
** INFO: setting user directory to 'C:/Users/chenl/Desktop/delllll/userRoutines'
** INFO: setting default cmake generator to 'NMake Makefiles'

Intel(R) MPI Library 2019 Update 4 for Windows* Target Build Environment for Intel(R) 64 applications
Copyright 2007-2019 Intel Corporation.

Copyright (C) 1985-2019 Intel Corporation. All rights reserved.
Intel(R) Compiler 19.0 Update 4 (package 228)

**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.14.27
** Copyright (c) 2025 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
-- The C compiler identification is MSVC 19.44.35223.0
-- The CXX compiler identification is MSVC 19.44.35223.0
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Fortran compiler identification is Intel 19.0.4.20190417
-- Check for working Fortran compiler: C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.4.228/windows/bin/intel64/ifort.exe
-- Check for working Fortran compiler: C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.4.228/windows/bin/intel64/ifort.exe - works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.4.228/windows/bin/intel64/ifort.exe supports Fortran 90
-- Checking whether C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.4.228/windows/bin/intel64/ifort.exe supports Fortran 90 - yes
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/chenl/Desktop/delllll/userRoutines/build/win64/release
Scanning dependencies of target user
[ 33%] Building Fortran object CMakeFiles/user.dir/simpack.f.obj
[ 66%] Building Fortran object CMakeFiles/user.dir/mbselem/usurface.f.obj
[100%] Linking CXX shared library user.dll
���ڴ����� user.lib �Ͷ��� user.exp
���ڴ����� user.lib �Ͷ��� user.exp
Copying user shared library to C:/Users/chenl/Desktop/delllll/userRoutines/lib/win64 ...
[100%] Built target user

完成之后目录树为

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
userRoutines
├── build
│ └── win64
│ └── release
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ │ ├── 3.17.3
│ │ │ ├── CMakeCCompiler.cmake
│ │ │ ├── CMakeCXXCompiler.cmake
│ │ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ │ ├── CMakeDetermineCompilerABI_Fortran.bin
│ │ │ ├── CMakeFortranCompiler.cmake
│ │ │ ├── CMakeRCCompiler.cmake
│ │ │ ├── CMakeSystem.cmake
│ │ │ ├── CompilerIdC
│ │ │ │ ├── CMakeCCompilerId.c
│ │ │ │ ├── CMakeCCompilerId.exe
│ │ │ │ ├── CMakeCCompilerId.obj
│ │ │ │ └── tmp
│ │ │ ├── CompilerIdCXX
│ │ │ │ ├── CMakeCXXCompilerId.cpp
│ │ │ │ ├── CMakeCXXCompilerId.exe
│ │ │ │ ├── CMakeCXXCompilerId.obj
│ │ │ │ └── tmp
│ │ │ └── CompilerIdFortran
│ │ │ ├── CMakeFortranCompilerId.F
│ │ │ ├── CMakeFortranCompilerId.exe
│ │ │ ├── CMakeFortranCompilerId.obj
│ │ │ └── tmp
│ │ ├── CMakeDirectoryInformation.cmake
│ │ ├── CMakeError.log
│ │ ├── CMakeOutput.log
│ │ ├── CMakeRuleHashes.txt
│ │ ├── CMakeTmp
│ │ ├── Makefile.cmake
│ │ ├── Makefile2
│ │ ├── TargetDirectories.txt
│ │ ├── cmake.check_cache
│ │ ├── progress.marks
│ │ └── user.dir
│ │ ├── DependInfo.cmake
│ │ ├── build.make
│ │ ├── cmake_clean.cmake
│ │ ├── cmake_clean_Fortran.cmake
│ │ ├── depend.internal
│ │ ├── depend.make
│ │ ├── embed.manifest
│ │ ├── flags.make
│ │ ├── fortran.internal
│ │ ├── intermediate.manifest
│ │ ├── manifest.rc
│ │ ├── manifest.res
│ │ ├── mbselem
│ │ │ └── usurface.f.obj
│ │ ├── objects1.rsp
│ │ ├── progress.make
│ │ ├── simpack.f.obj
│ │ ├── simpack.f.obj.provides.build
│ │ └── simpack.mod.stamp
│ ├── Makefile
│ ├── cmake_install.cmake
│ ├── simpack.mod
│ ├── user.dll
│ ├── user.exp
│ ├── user.ilk
│ └── user.lib
├── lib
│ └── win64
│ └── user.dll
└── src
├── CMakeLists.txt
├── ext
├── mbselem
│ └── usurface.f
└── simpack.f

使用2026的环境时
VS2019INSTALLDIR=C:\Program Files\Microsoft Visual Studio\18\Community

其他设置保持不变

1772882228670

正常编译:

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
** INFO: setting user directory to 'C:/Users/chenl/Desktop/delllll/userRoutines'
** INFO: setting default cmake generator to 'NMake Makefiles'

Intel(R) MPI Library 2019 Update 4 for Windows* Target Build Environment for Intel(R) 64 applications
Copyright 2007-2019 Intel Corporation.

Copyright (C) 1985-2019 Intel Corporation. All rights reserved.
Intel(R) Compiler 19.0 Update 4 (package 228)

**********************************************************************
** Visual Studio 2026 Developer Command Prompt v18.3.2
** Copyright (c) 2026 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
-- The C compiler identification is MSVC 19.50.35725.0
-- The CXX compiler identification is MSVC 19.50.35725.0
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/18/Community/VC/Tools/MSVC/14.50.35717/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/18/Community/VC/Tools/MSVC/14.50.35717/bin/Hostx64/x64/cl.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/18/Community/VC/Tools/MSVC/14.50.35717/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/18/Community/VC/Tools/MSVC/14.50.35717/bin/Hostx64/x64/cl.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Fortran compiler identification is Intel 19.0.4.20190417
-- Check for working Fortran compiler: C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.4.228/windows/bin/intel64/ifort.exe
-- Check for working Fortran compiler: C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.4.228/windows/bin/intel64/ifort.exe - works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.4.228/windows/bin/intel64/ifort.exe supports Fortran 90
-- Checking whether C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.4.228/windows/bin/intel64/ifort.exe supports Fortran 90 - yes
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/chenl/Desktop/delllll/userRoutines/build/win64/release
Scanning dependencies of target user
[ 33%] Building Fortran object CMakeFiles/user.dir/simpack.f.obj
[ 66%] Building Fortran object CMakeFiles/user.dir/mbselem/usurface.f.obj
[100%] Linking CXX shared library user.dll
���ڴ����� user.lib �Ͷ��� user.exp
���ڴ����� user.lib �Ͷ��� user.exp
Copying user shared library to C:/Users/chenl/Desktop/delllll/userRoutines/lib/win64 ...
[100%] Built target user


使用2022的环境时,并且设置2022环境变量值

VS2019INSTALLDIR=C:\Program Files\Microsoft Visual Studio\2022\Professional

其他设置保持不变时,系统报错.

1772881159890

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
** INFO: setting user directory to 'C:/Users/chenl/Desktop/delllll/userRoutines'
** INFO: setting default cmake generator to 'NMake Makefiles'

Intel(R) MPI Library 2019 Update 4 for Windows* Target Build Environment for Intel(R) 64 applications
Copyright 2007-2019 Intel Corporation.


ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/chenl/Desktop/delllll/userRoutines/build/win64/release
系统找不到指定的文件.
CMake Error: Generator: execution of make failed. Make command was: nmake /nologo &&


Matlab设置步骤

  • Step 1: Add MatSIM to MATLAB Path
  • Step 2: Specify Desired Compiler
  • Step 3: Set-Up of the Prepared Simulink Model
  • Step 4: Export MATLAB Code
  • Step 5: Copy Exported Model to the Database

MatSIM设置

首先,确认simpack与matlab版本之间的兼容性.

此次版本未按照上面兼容性.

目前版本之间的版本兼容性

1771818154896

为了Simulink能够访问Simpack MatSIM文件,需要将Simpack的安装路径添加到MATLAB中.可以通过一下步骤实现:

主页 -> 环境 -> 设置路径

<Simpack_Installation>/partners/mathworks/matsim/ C:\Program Files\SIMPACK-2021x.6\

1771821108232

指定求解器

通过MATLAB Simulink Coder可以借助编译器将Simulink模型导出成Simulink二进制文件.

在MATLAB的命令行窗口中,通过一下命令可以检查求解器的设定:

1
2
3
4
5
6
7
mex -setup

MEX 配置为使用 'Microsoft Visual C++ 2022 (C)' 以进行 C 语言编译.要选择不同的 C 编译器,请从以下选项中选择一种命令:
MinGW64 Compiler (C) mex -setup:'C:\Program Files\MATLAB\R2025b\bin\win64\mexopts\mingw64.xml' C
Microsoft Visual C++ 2022 (C) mex -setup:C:\Users\chenl\AppData\Roaming\MathWorks\MATLAB\R2025b\mex_C_win64.xml C要选择不同的语言,请从以下选项中选择一种命令:
mex -setup C++
mex -setup FORTRAN
1
2
3
4
5
6
7
mex -setup C++

MEX 配置为使用 'MinGW64 Compiler (C++)' 以进行 C++ 语言编译.

要选择不同的 C++ 编译器,请从以下选项中选择一种命令:
MinGW64 Compiler (C++) mex -setup:C:\Users\chenl\AppData\Roaming\MathWorks\MATLAB\R2025b\mex_C++_win64.xml C++
Microsoft Visual C++ 2022 mex -setup:'C:\Program Files\MATLAB\R2025b\bin\win64\mexopts\msvcpp2022.xml' C++

Simulink模型设置

自带模型的目录树如下:

1
2
3
4
5
6
7
8
tutorial_matsim_I
├── database
│ └── 3DS_SIMULIA_Logotype.png
├── main_model
│ ├── tutorial_matsim_start_01.spck
│ └── tutorial_matsim_start_01.spf
└── simulink_model
└── tutorial_matsim_start_spr_dmp_01.mdl