无法在Eclipse中链接CUDA库

时间:2019-05-14 11:53:42

标签: c++ eclipse cuda linker libtorch

我正在尝试将libtorch用于我的项目,并已从源代码进行编译。我已经完成了编译,并在文档中使用了示例代码(使用CMake),发现工作正常。现在,我已经将其扩展到eclipse工作区以提供ide支持,但是在这里我遇到了gpu cuda库的一个奇怪的链接问题。

我已链接所有库进行编译,如下所示fig1

但是如果没有,则这些库未链接到可执行文件,如下所示fig2

使用CMake编译时,我得到的cuda库链接如下所示fig3 这是在eclipse fig4上编译期间cuda库链接的证明 这是我使用的测试代码

#include <torch/torch.h>
#include <iostream>

int main() {
        torch::DeviceType device_type;

        if (torch::cuda::is_available()) {
             std::cout << "CUDA available! Training on GPU" << std::endl;
             device_type = torch::kCUDA;
        } else {
          std::cout << "Training on CPU" << std::endl;
           device_type = torch::kCPU;
        }

        torch::Device device(device_type);

        torch::Tensor tensor = torch::rand( { 2, 3 }).to(device);
        std::cout << tensor << std::endl;

        return 0;
 }

预期的响应是,当在eclipse生成的可执行文件上加注时,该列表应具有在eclipse中链接的所有库。如第一张图片所示。

0 个答案:

没有答案
相关问题