简体   繁体   English

如何在 vs code 上安装 C++ 的库,如 Eigen 和 SharkML?

[英]How to install a Library for C++ like Eigen and sharkML at vs code?

I am trying to install libraries like eigen, sharkMl, xtensor, and others in VSCode for C++.我正在尝试在 VSCode 中为 C++ 安装 eigen、sharkMl、xtensor 等库。 Please if anyone can help me to know the right way to do that.请如果有人可以帮助我知道正确的方法。

All of these libraries use CMake for their build system so what I do is use CMake as my build system.所有这些库都使用 CMake 作为他们的构建系统,所以我所做的就是使用 CMake 作为我的构建系统。 My favorite way to do this is to use the libraries build systems to install them and then inlcude them with cmakes find_package function.我最喜欢的方法是使用库构建系统来安装它们,然后使用 cmakes find_package function 包含它们。 This you can do by cloning the git repository for the library then build it and install it with cmake.您可以通过克隆库的 git 存储库然后构建它并使用 cmake 安装它来做到这一点。 On linux you do this by:在 linux 上,您可以通过以下方式执行此操作:

git clone https://gitlab.com/libeigen/eigen.git
cd eigen
mkdir build
cd build
cmake ..
sudo make install

VSCode has good integration for cmake so if you have the C/C++ Extension pack you will be able to build with cmake. VSCode 与 cmake 具有良好的集成,因此如果您有C/C++ 扩展包,您将能够使用 cmake 进行构建。 In your project folder make a CMakeLists.txt file and add the packages you want:在你的项目文件夹中创建一个 CMakeLists.txt 文件并添加你想要的包:

add_executable(main main.cpp)    
find_package(Eigen3 3.4 NO_MODULE)
target_link_libraries(main Eigen3::Eigen)

(This example assumes the main cpp file is main.cpp and creates an executable called main) Then when you press ctr+shift+p and perform CMake: Configure you can select your compiler and build the executable. (此示例假设主 cpp 文件是 main.cpp 并创建一个名为 main 的可执行文件)然后当您按 ctr+shift+p 并执行 CMake:配置时,您可以 select 您的编译器并构建可执行文件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM