This commit is contained in:
tp 2025-05-12 10:35:35 +08:00
parent 3d379b79c7
commit 2183b81a0f
4 changed files with 15 additions and 10 deletions

View File

@ -1,6 +1,10 @@
# ===== 第一阶段:构建阶段 =====
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
# 配置 NuGet 使用国内镜像源
RUN dotnet nuget add source https://mirrors.cloud.tencent.com/nuget/ \
&& dotnet nuget disable source nuget.org
# 配置 apt-get 使用 apt-cacher-ng 作为代理
RUN echo 'Acquire::http::Proxy "http://192.168.1.140:3142";' > /etc/apt/apt.conf.d/01proxy
@ -28,7 +32,7 @@ WORKDIR /src/Fortran
RUN for file in *.f90; do gfortran -fPIC -c "$file" -o "${file%.f90}.o"; done
# 链接所有 .o 文件为共享库
RUN gfortran -shared *.o -o libMSJGMX.so
RUN gfortran -shared *.o -o libfortran_function.so
# 回到主工作目录
WORKDIR /src
@ -45,7 +49,7 @@ RUN dotnet publish -c Release -o /app/publish
# 复制编译好的 .so 文件到发布目录
RUN mkdir -p /app/publish && \
cp /src/Fortran/libMSJGMX.so /app/publish/
cp /src/Fortran/libfortran_function.so /app/publish/
# ===== 第二阶段:运行阶段 =====
FROM mcr.microsoft.com/dotnet/aspnet:8.0
@ -72,7 +76,7 @@ WORKDIR /app
COPY --from=build /app/publish .
# 确保 .so 文件的权限正确
RUN chmod 755 /app/libMSJGMX.so
RUN chmod 755 /app/libfortran_function.so
# 设置 LD_LIBRARY_PATH
ENV LD_LIBRARY_PATH=/app

View File

@ -1,8 +1,9 @@
{
"fortranSourceFile": "D:\\\u5DE5\u4F5C2025\\\u7B97\u6CD5\u5E73\u53F0\\dll\\\u9A6C\u65AF\u4EAC\u8DDF\u6A21\u578B\\MSJGMX\\MSJGMX\\MSJGMX - \u526F\u672C.f90",
"fortranFunctionName": "MSJGMX",
"fortranFunctionName": "fortran_function",
"projectName": "FortranWebApi",
"outputDirectory": "D:\\\u5DE5\u4F5C2025\\\u7B97\u6CD5\u5E73\u53F0\\\u8F93\u51FA\u5E93\\\u9A6C\u65AF\u4EAC\u8DDF\u6A21\u578B",
"cmbLanguage": "",
"parameters": [
{
"name": "FILELEN",
@ -71,7 +72,7 @@
{
"name": "P",
"dataType": "Float",
"arrayType": "OneDimensional",
"arrayType": "TwoDimensional",
"direction": "Input",
"description": "",
"isSelected": true

Binary file not shown.

View File

@ -14,11 +14,11 @@ namespace FortranWebApi.Services
// 添加当前目录到库搜索路径
NativeLibrary.SetDllImportResolver(typeof(FortranInteropService).Assembly, (name, assembly, path) =>
{
if (name == "libMSJGMX.so")
if (name == "libfortran_function.so")
{
// 尝试从当前目录加载
string currentDir = Directory.GetCurrentDirectory();
string libraryPath = Path.Combine(currentDir, "libMSJGMX.so");
string libraryPath = Path.Combine(currentDir, "libfortran_function.so");
if (File.Exists(libraryPath))
{
@ -32,8 +32,8 @@ namespace FortranWebApi.Services
}
// DllImport声明
[DllImport("libMSJGMX.so", CallingConvention = CallingConvention.Cdecl, EntryPoint = "MSJGMX")]
private static extern void MSJGMX(
[DllImport("libfortran_function.so", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fortran_function")]
private static extern void fortran_function(
ref int FILELEN,
ref int NODE,
ref int M,
@ -111,7 +111,7 @@ namespace FortranWebApi.Services
// 调用Fortran函数
MSJGMX(
fortran_function(
ref FILELEN,
ref NODE,
ref M,