【问题标题】:How to install SFML in ubuntu?如何在 ubuntu 中安装 SFML?
【发布时间】:2015-08-22 03:36:29
【问题描述】:

我下载了 SFML,然后将其所有标头复制到 usr/local/include/ 中,并将其所有库复制到 usr/local/lib/ 中。

我在 Desktop 中有一个名为 ma​​in.cpp 的文件,我想编译它。

首先我是这样做的:-

g++ -c main.cpp

之后,当我尝试这样做时:-

g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system

它给了我:-

/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_get_action@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_list_entry_get_next@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_unref@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_list_entry_get_name@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_enumerate_unref@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_monitor_unref@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_new@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_monitor_receive_device@LIBUDEV_183'
/usr/local/lib/libsfml-graphics.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_get_devnode@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_monitor_enable_receiving@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_enumerate_new@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_monitor_get_fd@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_unref@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_get_property_value@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_monitor_filter_add_match_subsystem_devtype@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_enumerate_get_list_entry@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_enumerate_scan_devices@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_enumerate_add_match_subsystem@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_get_syspath@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_get_sysattr_value@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_monitor_new_from_netlink@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_new_from_syspath@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_get_parent_with_subsystem_devtype@LIBUDEV_183'

我已经正确安装了所有这些必需的依赖项: https://github.com/SFML/SFML/wiki/Tutorial%3A-Installing-SFML-dependencies

我是否错过了任何必需的步骤?

【问题讨论】:

  • main.o更改为main.cpp
  • en.sfml-dev.org/forums/index.php?topic=18187.0 了解 std::__throw_out_of_range_fmt。
  • 你正在编译 C++ 代码,所以应该使用g++ 而不是gcc。这将为您链接到 C++ 标准库。
  • @liya Popov 我都试过了。他们都显示了这些错误。

标签: c++ linux ubuntu installation sfml


【解决方案1】:

要在 Ubuntu 中安装它,首先在终端中运行以下命令 -

sudo apt-get install libsfml-dev

确保您已经拥有编译器 (GCC),如果没有,则使用 make 安装它

sudo apt-get install build-essential

然后创建一个像这样的简单 SFML 应用程序来测试它

#include <SFML/Graphics.hpp>

int main(int argc, char const *argv[])
{
    sf::RenderWindow window(sf::VideoMode(200,200), "Hello From SFML");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Magenta);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed){
                window.close();
            }
        }
        window.clear();
        window.draw(shape);
        window.display();
        
    }

    return 0;
}

现在在 repo 中创建一个 makefilemain.cpp 相同

compile:./main.cpp
    g++ -c ./main.cpp
    g++ main.o -o app -lsfml-graphics -lsfml-window -lsfml-system

run:
    ./app

现在编译它运行以下命令

make compile

最后运行下面的命令

make run

【讨论】:

    【解决方案2】:

    仅仅因为您安装了依赖项并不意味着您正在使用它们。

    undefined reference to `udev_device_get_action@LIBUDEV_183'
    

    提到udevLIBUDEV 向我表明您需要链接到libudev。尝试将-ludev 添加到您的命令行。

    如果您粘贴了所有链接错误,那么实际上可能会解决它。如果您只是粘贴了前 20 个,那么可能还有其他库需要链接。查看缺少的符号,找出它们来自哪些库,然后添加它们。

    /usr/local/lib/libsfml-graphics.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'
    

    不知道有什么交易。您可能需要链接 C++ 库?

    无论如何,您应该看看为您的 SFML 项目设置 makefile 的说明:https://github.com/SFML/SFML/wiki/Tutorial%3A-Build-your-SFML-project-with-CMake

    【讨论】:

      猜你喜欢
      • 2011-06-18
      • 2020-08-16
      • 2016-03-31
      • 2018-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多