C++:如何添加外部库

发布于 2024-09-06 11:49:07 字数 139 浏览 6 评论 0原文

我正在尝试将 SVL 添加到我的项目中。

如果没有它,我会收到数百个错误(未定义的参考...)。添加 -lSVL 后,所有错误都消失了,但 gcc 说:“找不到 -lSVL”。其他一切(SDL、SDL_TTF、SDL_Mixer...)都工作正常。

I'm trying to add SVL to my project.

Without it I'm getting hundreds of errors (undefined reference...). After adding -lSVL all errors are gone, but gcc says: "cannot find -lSVL". Everything else (SDL, SDL_TTF, SDL_Mixer...) works fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

司马昭之心 2024-09-13 11:49:07

您应该告知 gcc libsvl.a 的安装路径,例如:

gcc -lsvl -L/my/path/

另外,如果您在 Linux 下工作,请注意大小写(“SVL”与“svl”不同)。

You should inform gcc of the path where libsvl.a is installed, for example:

gcc -lsvl -L/my/path/

Also, pay attention to the case if you work under Linux ("SVL" is different from "svl").

谜泪 2024-09-13 11:49:07

添加外部库分为两个部分;您需要告诉编译器[1]在哪里可以找到API的描述(即头文件)并且您需要告诉链接器 在哪里可以找到 API 的实现(即库文件)。

标头的可能位置列表由包含路径给出,对于传统编译器,该路径是通过 -I 选项添加的。它需要一个目录名称来添加;该目录是编译器查找头文件的额外位置。

库的可能位置列表由链接路径给出。它就像包含路径一样,但使用 -L 添加到其中。请注意,您还可以(至少通常)直接在命令行上提供库的完整路径,但并不特别推荐这样做,因为它往往会在可执行文件中嵌入比实际需要更多的信息。

MSVC 的语法与 IIRC 非常相似。

如果您使用的是 IDE,您可能必须在项目选项中设置这些内容,但只要您记住需要设置包含路径和库路径,您就能够找到解决方法。

[1]严格来说,您是在告诉预处理器,但预处理器的输出实际上总是直接直接进入编译器。

There are two parts to adding an external library; you need to tell the compiler[1] where to find the description of the API (i.e., the header files) and you need to tell the linker where to find the implementation of the API (i.e., the library file(s)).

The list of possible locations of the headers is given by the include path, which with a traditional compiler is added to with the -I option. It takes a directory name to add; the directory is one extra place the compiler will look for header files.

The list of possible locations of the library is given by the link path. It's just like the include path, but is added to with -L. Note that you can also (at least normally) give the full path to the library directly on the command line, but this isn't particularly recommended because it tends to embed more information in the executable than is really needed.

The syntax for MSVC is recognizably similar IIRC.

If you're using an IDE, you'll probably have to set these things in the project options, but as long as you remember that you need to set both include and library paths, you'll be able to find your way through.

[1]Strictly, you're telling the preprocessor, but the preprocessor's output is virtually always directed straight into the compiler proper.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文