libtorch c++未定义的引用:命令行中缺少DSO



我正试图在c++项目中包含libtorch,以使用我以前在python中训练过的神经网络。但当我试图编译和链接时,我会遇到一个未定义的引用问题和"命令行中缺少DSO"的错误,但我不确定这意味着什么。

/usr/bin/ld: ../vendor/libtorch/lib/libtorch_cpu.so: undefined reference to symbol '_ZN3c106detail23torchInternalAssertFailEPKcS2_jS2_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
/usr/bin/ld: /home/joren/Coding/Waffle-empire/crypto-prediction/src/../vendor/libtorch/lib/libc10.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

我正在使用premake5生成我的makefile,如下所示:

workspace "CryptoPredict"
architecture "x64"
startproject "CryptoPredict"
configurations
{
"Debug",
"Release"
}
outputdir = "%{cfg.buildcfg}"
IncludeDir = {}
IncludeDir["crypto_com"] = "vendor/crypto_com/include"
IncludeDir["libtorch"] = "vendor/libtorch"
IncludeDir["json"] = "vendor/json/single_include"
IncludeDir["boost"] = "/usr/include/boost"
IncludeDir["websocketpp"] = "/usr/include/websocketpp"
CppVersion = "C++17"
-- crypto.com wrapper --
project "crypto_com"
location "vendor/%{prj.name}"
kind "StaticLib"
language "C++"
IncludeDir["cryptlite"] = "vendor/crypto_com/vendor/cpp-cryptlite/include"
includedirs {
"%{IncludeDir.boost}",
"%{IncludeDir.cryptlite}",
"%{IncludeDir.http_request}",
-- "%{IncludeDir.json}",
"%{IncludeDir.websocketpp}",
"include"
}

files {
"vendor/%{prj.name}/include/**.hpp",
"vendor/%{prj.name}/include/**.cpp"
}

-- prediction bot --
project "CryptoPredict"
location "src"
kind "ConsoleApp"
language "C++"
targetdir ("bin/" .. outputdir)
objdir ("bin/int/" .. outputdir  .. "%{prj.name}")
PrecompiledHeaderInclude = "common.hpp"
PrecompiledHeaderSource = "%{prj.name}/src/common.cpp"
includedirs
{
"%{IncludeDir.crypto_com}",
"%{IncludeDir.json}",
"%{IncludeDir.libtorch}/include",
"%{IncludeDir.libtorch}/include/torch/csrc/api/include",
"src"
}
files
{
"src/**.asm",
"src/**.hpp",
"src/**.cpp",
"src/**.h"
}
libdirs
{
"bin/lib",
"%{IncludeDir.libtorch}/lib"
}
links
{
"crypto",
"pthread",
"ssl",
"crypto_com",
"torch",
"torch_cpu"
}
pchheader "%{PrecompiledHeaderInclude}"
pchsource "%{PrecompiledHeaderSource}"
forceincludes
{
"%{PrecompiledHeaderInclude}"
}
flags
{
"LinkTimeOptimization",
"NoImportLib",
"Maps",
"MultiProcessorCompile"
}
filter "configurations:Debug"
flags {  }
defines { "DEBUG", "CHANGE_G3LOG_DEBUG_TO_DBUG" }
symbols "On"
filter "configurations:Release"
flags { "NoManifest" }
defines { "RELEASE", "NDEBUG" }
optimize "speed"

在添加LDFLAGS="0"之后-Wl,--复制dt需要的条目";对于我的make命令,这个问题似乎已经解决,但另一个问题出现了,我现在得到了一大堆(下面只是一个小样本(未定义的引用错误,但命令行中没有更多的DSO丢失。

/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::native::sqrt_sparse_(at::Tensor&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::native::signbit_sparse_csr(at::Tensor const&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::meta::structured_baddbmm::meta(at::Tensor const&, at::Tensor const&, at::Tensor const&, c10::Scalar const&, c10::Scalar const&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `fLB::FLAGS_caffe2_workspace_stack_debug'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::meta::structured_smooth_l1_loss::meta(at::Tensor const&, at::Tensor const&, long, double)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `torch::jit::tensorexpr::kQUInt8'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::native::squeeze_quantized(at::Tensor const&, long)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::native::atanh_sparse_csr(at::Tensor const&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `c10::IValue::isDoubleList() const'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::native::floor_sparse_csr(at::Tensor const&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::native::structured_lerp_Scalar::impl(at::Tensor const&, at::Tensor const&, c10::Scalar const&, at::Tensor const&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `typeinfo for torch::profiler::impl::CUDAStubs'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::_ops::index_add_::call(at::Tensor&, long, at::Tensor const&, at::Tensor const&, c10::Scalar const&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::native::trunc_sparse_(at::Tensor&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::meta::structured__log_softmax_backward_data::meta(at::Tensor const&, at::Tensor const&, long, c10::ScalarType)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::_ops::_upsample_nearest_exact1d_backward::call(at::Tensor const&, c10::ArrayRef<long>, c10::ArrayRef<long>, c10::optional<double>)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::native::abs_sparse_csr_out(at::Tensor const&, at::Tensor&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `cv::Mat::Mat()'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::native::tanh_sparse_csr_out(at::Tensor const&, at::Tensor&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::has_internal_overlap(at::TensorBase const&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::native::linalg_cross_out(at::Tensor const&, at::Tensor const&, long, at::Tensor&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::meta::structured__upsample_nearest_exact3d::meta(at::Tensor const&, c10::ArrayRef<long>, c10::optional<double>, c10::optional<double>, c10::optional<double>)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `cv::Mat::operator=(cv::Mat&&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::meta::structured_triangular_solve::meta(at::Tensor const&, at::Tensor const&, bool, bool, bool)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::native::atan_sparse_(at::Tensor&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `cv::Mat::~Mat()'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `at::native::structured_lerp_Tensor::impl(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&)'
/usr/bin/ld: /usr/lib/libtorch_cuda.so: undefined reference to `caffe2::TensorProtos::TensorProtos(google::protobuf::Arena*, bool)'

您没有链接到所需的库。我不太了解pytorch,但从你的输出来看,你似乎错过了OpenCV。

您需要将其添加到links部分。

最新更新