简体   繁体   English

如何在 ubuntu 上添加 c++ 库

[英]How to add a c++ library on ubuntu

I have downloaded a repository from github with a library with git clone then I typed in terminal "make" now I have a libmylibrary++.so file in folder mylibrary/src我已经从 github 下载了一个存储库,其中包含一个带有 git 克隆的库,然后我输入了终端“make”,现在我在文件夹 mylibrary/src 中有一个 libmylibrary++.so 文件

Now I want to run a c++ file which uses the library but I can't compile it because of this error: "mylibrary.hpp: No such file or directory"现在我想运行一个使用该库的 c++ 文件,但由于此错误而无法编译它:“mylibrary.hpp:没有这样的文件或目录”

How to add it to PATH?如何将其添加到 PATH? yet I don't understand what exactly I need to add Whether it is folder "/home/mylibrary" or folder with the.so file但我不明白我到底需要添加什么无论是文件夹“/home/mylibrary”还是带有.so文件的文件夹

Your C++ compiler only knows to search for header files and libraries in standard locations and directories.您的 C++ 编译器只知道在标准位置和目录中搜索 header 文件和库。 Just because you downloaded another library in some directory, somewhere, doesn't mean that your C++ compiler will automatically find it.仅仅因为您在某个目录的某个地方下载了另一个库,并不意味着您的 C++ 编译器会自动找到它。

You will need to change your Makefile and compile your program with the additional compilation options that instruct your C++ compiler to search for header files and libraries in other directories -- typically -I and -L option.您将需要更改 Makefile 并使用其他编译选项编译您的程序,这些选项指示您的 C++ 编译器在其他目录中搜索-I文件和库 - 通常是-L选项。

Additionally, you will probably need to use either -R or -Wl,-rpath options in order for the compiled code to load the shared libraries from the non-standard locations.此外,您可能需要使用-R-Wl,-rpath选项,以便编译的代码从非标准位置加载共享库。

You will find additional information in the gcc manual and documentation .您可以在gcc手册和文档中找到更多信息。

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

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