Abaqus UMAT:msvcrt.lib(utility.obj)LNK2019 错误

问题描述 投票:0回答:1

我在链接用 C++ 编写的

umat()
程序时遇到问题。我正在使用 Windows 10、Abaqus 2022 和 Microsoft Visual Studio 2022 Community(编译器 cl 版本 19.36.32537 for x64)。编译顺利完成,但链接器中止并显示以下错误消息。

msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __vcrt_initialize referenced in function __scrt_initialize_crt
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __vcrt_uninitialize referenced in function __scrt_initialize_crt
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __vcrt_uninitialize_critical referenced in function __scrt_dllmain_uninitialize_critical
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __vcrt_thread_attach referenced in function __scrt_dllmain_crt_thread_attach
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __vcrt_thread_detach referenced in function __scrt_dllmain_crt_thread_attach
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol _is_c_termination_complete referenced in function __scrt_dllmain_uninitialize_c
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_initialize referenced in function __scrt_initialize_crt
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_uninitialize referenced in function __scrt_uninitialize_crt
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_uninitialize_critical referenced in function __scrt_dllmain_uninitialize_critical
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_thread_attach referenced in function __scrt_dllmain_crt_thread_attach
msvcrt.lib(utility.obj) : error LNK2019: unresolved external symbol __acrt_thread_detach referenced in function __scrt_dllmain_crt_thread_detach
standardU.dll : fatal error LNK1120: 11 unresolved externals
Abaqus Error: Problem during linking - Abaqus/Standard User Subroutines.
  This error may be due to a mismatch in the Abaqus user subroutine arguments.
  These arguments sometimes change from release to release, so user subroutines
  used with a previous release of Abaqus may need to be adjusted.
Abaqus/Analysis exited with errors

将 /verbose:lib 传递到链接器的选项中会报告提到的 msvcrt.lib 取自 “E:\Microsoft Visual Studio�2\Community\VC\Tools\MSVC .36.32532\lib\x64\msvcrt.lib” 。这条路对我来说看起来不错。

通过 Abaqus Commands 的终端使用以下选项调用编译器和链接器(在 "E:\SIMULIA\EstProducts�2\win_b64\SMA\site\win86_64.env" 中指定)。

compile_cpp=['cl', '/c', '/W0', '/MD', '/TP',
             '/EHsc', '/DNDEBUG', '/DWIN32', '/DTP_IP', '/D_CONSOLE',
             '/DNTI', '/DFLT_LIC', '/DOL_DOC', '/D__LIB__', '/DHKS_NT',
             '/D_WINDOWS_SOURCE', '/DFAR=', '/D_WINDOWS', '/DABQ_WIN86_64', '/std:c++20', '%P',
             '/O1', # <-- Optimization
             # '/Zi', # <-- Debug symbols
             '/I%I', '/I'+abaHomeInc]
...
link_sl=['LINK',
         '/verbose:lib',
         '/nologo', '/NOENTRY', '/INCREMENTAL:NO', '/subsystem:console', '/machine:AMD64',
         '/NODEFAULTLIB:LIBC.LIB', '/NODEFAULTLIB:LIBCMT.LIB',
         '/DEFAULTLIB:OLDNAMES.LIB', '/DEFAULTLIB:LIBIFCOREMD.LIB', '/DEFAULTLIB:LIBIFPORTMD.LIB', '/DEFAULTLIB:LIBMMD.LIB',
         '/DEFAULTLIB:kernel32.lib', '/DEFAULTLIB:user32.lib', '/DEFAULTLIB:advapi32.lib',
         '/FIXED:NO', '/dll',
         #'/debug', # <-- Debugging
         '/def:%E', '/out:%U', '%F', '%A', '%L', '%B',
         'oldnames.lib', 'user32.lib', 'ws2_32.lib', 'netapi32.lib',
         'advapi32.lib', 'msvcrt.lib', 'vcruntime.lib', 'ucrt.lib']

有没有办法解决上述问题(或者,也许我误解了什么)?我希望得到你的帮助。

当我尝试在

umat()
体内构建一个静态对象时,尤其会发生错误。初始化静态基元类型或非静态对象就不存在这样的问题;在他们的情况下,作业运行和完成几乎都很好(
warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
除外)。

更新。我创建了一个简约的 main.cpp 文件,以在 Abaqus 上独立重现相同的错误。

class C {
 public:
  C() {};
  ~C() {};
  
  int i = 0;
};

int main() {
  static C c; // removing "static" produces no errors

  return 0;
}

我还准备了一个 .bat 文件来编译并链接 main.cpp 以及上面指定的所需选项:

call "e:\Intel\OneAPI\setvars.bat"
call "e:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64\cl.exe" /c /W0 /MD /TP /EHsc /DNDEBUG /DWIN32 /DTP_IP /D_CONSOLE /DNTI /DFLT_LIC /DOL_DOC /D__LIB__ /DHKS_NT /D_WINDOWS_SOURCE /DFAR= /D_WINDOWS /DABQ_WIN86_64 /std:c++20 main.cpp /O1
call "e:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64\link.exe" /verbose:lib /nologo /NOENTRY /INCREMENTAL:NO /subsystem:console /machine:AMD64 /NODEFAULTLIB:LIBC.LIB /NODEFAULTLIB:LIBCMT.LIB /DEFAULTLIB:OLDNAMES.LIB /DEFAULTLIB:LIBIFCOREMD.LIB /DEFAULTLIB:LIBIFPORTMD.LIB /DEFAULTLIB:LIBMMD.LIB /DEFAULTLIB:kernel32.lib /DEFAULTLIB:user32.lib /DEFAULTLIB:advapi32.lib /FIXED:NO /dll /out:test.dll main.obj oldnames.lib user32.lib ws2_32.lib netapi32.lib advapi32.lib msvcrt.lib vcruntime.lib ucrt.lib

执行它会导致相同的 LNK2019 错误。我还发现从链接器选项中删除 /NOENTRY 可以使其顺利完成。但是,在 Abaqus 提供的 .env 文件中执行此操作会导致生成的 .dll 中出现错误:

standardU.dll : fatal error LNK1169: one or more multiply defined symbols found
。我不知道如何修复它并感谢任何提示。

c++ linker abaqus msvcrt
1个回答
0
投票

与 msvcrt.lib (utility.obj) 相关的 LNK2019 错误通常是由于无法在 Abaqus UMAT 的输出代码中找到所需的函数而发生的。这些错误通常源于编译器和链接器设置的问题。我相信我共享的链接中提供的培训包可以帮助解决这个问题。 https://caeassistant.com/product/advanced-umat-subroutine/

© www.soinside.com 2019 - 2024. All rights reserved.