简体   繁体   English

libtorch c++ 未定义参考:命令行中缺少 DSO

[英]libtorch c++ undefined reference: DSO missing from command line

I'm trying to include libtorch in a c++ project to use a neural.network I previously trained in python. But when I try to compile and link I get an error with an undefined reference issue and also 'DSO missing from command line' but I am not sure what this means.我正在尝试将 libtorch 包含在 c++ 项目中以使用我之前在 python 中训练过的 neural.network。但是当我尝试编译和链接时,我收到一个错误,其中包含未定义的引用问题以及“命令行中缺少 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

I am using premake5 to generate my makefiles, as below:我正在使用 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"

After adding LDFLAGS="-Wl,--copy-dt-needed-entries" to my make command, this issue seems solved but another appears, I now get a whole bunch (below is only a small sample) of undefined reference errors but no more DSO missing from command line.在我的 make 命令中添加 LDFLAGS="-Wl,--copy-dt-needed-entries" 之后,这个问题似乎解决了,但又出现了另一个问题,我现在得到了一大堆(下面只是一小部分)未定义的引用错误但是命令行中不再缺少 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)'

You are not linking with a required library.您没有链接到所需的库。 I do not know pytorch very well, but from your output, it seems that you are missing OpenCV.我不太了解pytorch,但是从你的output来看,你好像少了OpenCV。

You need to add it to the links section.您需要将其添加到links部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在shm_open上的C ++ Boost库未定义参考:命令行缺少DSO - C++ Boost Library Undefined Reference On shm_open: DSO Missing From Command Line 未定义的符号引用,命令行中缺少 DSO - Undefined reference to symbol, DSO missing from command line GLEW + cmake链接失败“未定义引用符号glDrawElements”+“DSO从命令行中丢失” - GLEW + cmake linking fails “undefined reference to symbol glDrawElements” + “DSO missing from command line” 错误:cv :: VideoCapture :: ~~ VideoCapture()的未定义引用符号,命令行中缺少DSO - Error: Undefined reference symbol to cv::VideoCapture::~VideoCapture(), DSO missing from command line 未定义的符号引用 '<symbol> '...添加符号时出错:命令行中缺少 DSO(使用 CMake)</symbol> - Undefined Reference to Symbol '<Symbol>' ... Error Adding Symbols: DSO Missing From Command Line (With CMake) C ++实现CNN错误添加符号:命令行缺少DSO - C++ implementing CNN Error adding symbols: DSO missing from command line 命令行QT中缺少DSO - DSO missing from command line QT libstdc++:命令行中缺少 DSO - libstdc++: DSO missing from command line Lib Poco:命令行缺少DSO - Lib Poco: DSO missing from command line 命令行中缺少 DSO(使用 CMake) - DSO missing from command line (With CMake)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM