包含的库仍会导致"undefined reference"错误

Included libraries still cause "undefined reference" error

本文关键字:undefined reference 错误 包含      更新时间:2023-10-16

我已经在我的 Ubuntu 系统上安装了这个 http://www.sfml-dev.org/index.php 库。这些文件存储在/usr/local/include 中。

我的Eclipse确实在"包含GNU C++"下包含这些文件>>但是如果我构建程序,编译器会抱怨未定义的引用。

#include <SFML/System.hpp>
#include <iostream>
int main()
{
  sf::Clock Clock;
  return 0;
}

原因:

undefined reference to `sf::Clock::Clock()' main.cpp

猜我错过了什么?

我的第一个建议是对的。

这里记录了,你必须像这样编译:

g++ -c clock.cpp
g++ -o clock clock.o -lsfml-system

所以请将 -lsfml 系统添加到库中。

根据 SFML 教程,您需要使用 "-l" 指令链接到库。因此,请确保 eclipse 代表您执行此操作,如果没有,请尝试覆盖标志。