简体   繁体   English

如何在 ubuntu 中安装 SFML?

[英]How to install SFML in ubuntu?

I downloaded SFML, then I copied all its headers in usr/local/include/ and copied all its libraries in usr/local/lib/ .我下载了 SFML,然后在usr/local/include/ 中复制了它的所有头文件,并在usr/local/lib/ 中复制了它的所有库。

I have a file named main.cpp in Desktop which I want to compile.我在桌面中有一个名为main.cpp的文件,我想编译它。

First I did this :-首先我这样做了:-

g++ -c main.cpp

After that when I try to do this :-之后,当我尝试这样做时:-

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

It gives me :-它给了我:-

/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'

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

Have I missed any required step ?我错过了任何必需的步骤吗?

To Install it in Ubuntu first you run following command in your terminal -要首先在 Ubuntu 中安装它,请在终端中运行以下命令 -

sudo apt-get install libsfml-dev

make sure you already have compiler (GCC) and make if not then install it using确保你已经有编译器(GCC),如果没有,则使用

sudo apt-get install build-essential

Then to test this out create a simple SFML app like this然后为了测试这一点,创建一个像这样的简单 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;
}

Now create a makefile in the repo same as main.cpp现在在与main.cpp相同的 repo 中创建一个makefile

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

run:
    ./app

now to compile it run the following command现在编译它运行以下命令

make compile

and finally to run this run following command最后运行此运行以下命令

make run

Just because you're got the dependencies installed doesn't mean you're making use of them.仅仅因为您安装了依赖项并不意味着您正在使用它们。

undefined reference to `udev_device_get_action@LIBUDEV_183'

The mention of udev and LIBUDEV suggest to me that you need to link against libudev.提到udevLIBUDEV向我表明您需要链接到 libudev。 Try adding -ludev to your command line.尝试将-ludev添加到您的命令行。

If you pasted all of the link errors, then that might actually take care of it.如果您粘贴了所有链接错误,那么实际上可能会解决它。 If you just pasted the first 20, then there might be other libraries that need to be linked in. Look at the missing symbols, figure out what libraries they're from, and add them.如果您只粘贴前 20 个,那么可能需要链接其他库。查看缺少的符号,找出它们来自哪些库,然后添加它们。

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

Not sure what the deal is there.不知道那里有什么交易。 You might need to link against the C++ libraries?您可能需要链接 C++ 库?

Anyways, you should take a look at the instructions for setting up makefiles for your SFML project: https://github.com/SFML/SFML/wiki/Tutorial%3A-Build-your-SFML-project-with-CMake无论如何,您应该查看为您的 SFML 项目设置 makefile 的说明: https : //github.com/SFML/SFML/wiki/Tutorial%3A-Build-your-SFML-project-with-CMake

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

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