0

I have cloned a C++ library repo called 'mlpack'. I built the library using cmake and now I want to include it to my C++ file. I am using ubuntu 19.04. I tried to run the command:

g++ -std=c++11 test.cpp -I/home/koushik/Documents/'Git Repo'/mlpack/build/lib -lmlpack -larmadillo -lboost_serialization -fopenmp

Here /home/koushik/Documents/'Git Repo'/mlpack/build/lib is the build directory of the library. I tried this command thinking it would look for includes in that build directory. But I get the error:

test.cpp:1:10: fatal error: mlpack/core.hpp: No such file or directory
 #include <mlpack/core.hpp>
          ^~~~~~~~~~~~~~~~~
compilation terminated.

when I try to include the library and compile code.

Apart from the above coommand I also tried

$ export LD_LIBRARY_PATH='/home/koushik/Documents/Git Repo/mlpack/build/lib'
$ g++ -std=c++11 test.cpp -lmlpack -larmadillo -lboost_serialization -fopenmp

This failed as well giving the same error as above.

I would like to clarify that I have all the other linked libraries installed via apt and they work fine when linked in other C++ files. Only mlpack is built from source and I am trying to include.

4

1 回答 1

0

使用其 cmake 二进制目录中的库通常是一个坏主意,而且通常直接不起作用。

你要做的是在你的机器上选择一个你想安装库及其头文件的位置。然后你做:

mkdir lib_build
cd lib_build
cmake -DCMAKE_INSTALL_PREFIX=/path/to/install/dir path/to/lib/source
make && make install

这通常会在包含项目的面向公众的构建的指定位置创建includelib目录(有时会更多,例如bin或)。share

当您对库进行更改时,您可以重新运行make && make install以更新安装。

然后,在构建依赖于库的东西时,您通常会这样做:

g++ -I/path/to/install/dir/include -L/path/to/install/dir/lib ...
于 2020-05-05T17:16:55.017 回答