我正在学习LibTorch 这里的教程。
作以下修改:
example-app => Ceresexample-app.cpp => main.cxx在CMake命令cmake --build . --config Release之前,一切都正常工作。
它产生了下列错误:
main.obj : error LNK2001: unresolved external symbol __imp___tls_index_?init@?1??lazy_init_num_threads@internal@at@@YAXXZ@4_NA [D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\src\Ceres\build\Ceres.vcxproj]
main.obj : error LNK2001: unresolved external symbol __imp___tls_offset_?init@?1??lazy_init_num_threads@internal@at@@YAXXZ@4_NA [D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\src\Ceres\build\Ceres.vcxproj]
D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\src\Ceres\build\Release\Ceres.exe : fatal error LNK1120: 2 unresolved externals [D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\src\Ceres\build\Ceres.vcxproj]我不相信这些是我所做的改变,因为问题在于链接。
我还试图将其直接复制到Visual中。我使用的是LibTorch扩展尚未兼容的Visual 17 2022 (Visual 16 2019不再可从网站安装)。
复制通过一个空白的C++模板(没有启动文件)。我设置了以下宏:
LibTorchTarget = CPU指定要使用CPU的lib手电筒(对其他宏有用)LibTorchDir = C:/libtorch/目录,在该目录中可以找到安装(用于多个安装)LibTorchInstall = $(LibTorchDir)libtorch_$(LibTorchTarget)/表示为C:/libtorch/libtorch_CPU/LibTorchInclude = $(LibTorchInstall)include/表示为C:/libtorch/libtorch_CPU/include/LibTorchLib = $(LibTorchInstall)lib/表示为C:/libtorch/libtorch_CPU/lib/并将Include和Lib宏放在各自的VC++ Directories位置。以及$(LibTorchLib)*.lib (C:/libtorch/libtorch_CPU/lib/*.lib)在Linker > Input > Additional Dependencies中指定用于链接的所有.lib(防止大量LNK2009错误)。
最后,我将start xcopy /s "$(LibTorchLib)*.dll" "$(OutDir)" /Y /E /D /R命令放在Build Events > Pre-Link Event > Command Line中,以在教程中的CMakeLists.txt中复制if子句(显然是为了避免内存错误)。
结果与最终的LNK1120错误相同:
Error LNK2001 unresolved external symbol __imp___tls_index_?init@?1??lazy_init_num_threads@internal@at@@YAXXZ@4_NA Ceres D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\src\Ceres\main.obj 1
Error LNK2001 unresolved external symbol __imp___tls_offset_?init@?1??lazy_init_num_threads@internal@at@@YAXXZ@4_NA Ceres D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\src\Ceres\main.obj 1
Error LNK1120 2 unresolved externals Ceres D:\Silverous Black\CPE42S2-CPE42S2\CPE 406\ProjectDumagan\out\Debug_64\Ceres\Ceres.exe 1 我不太明白LNK错误的原因,所以如果有人能帮忙的话,那就太好了。提前谢谢你。
发布于 2022-11-19 17:09:57
查看:更新到VisualStudio17.4.0会产生与TLS相关的链接器错误
您很可能需要在MSVC更新后重新构建PyTorch。
https://stackoverflow.com/questions/74501884
复制相似问题