ara*_*guy 2 c++ linux installation ubuntu sfml
我下载了 SFML,然后将其所有标头复制到usr/local/include/中,并将其所有库复制到usr/local/lib/中。
我在桌面中有一个名为main.cpp的文件,我想编译它。
首先我这样做了:-
g++ -c main.cpp
Run Code Online (Sandbox Code Playgroud)
之后,当我尝试这样做时:-
g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
Run Code Online (Sandbox Code Playgroud)
它给了我:-
/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'
Run Code Online (Sandbox Code Playgroud)
我已正确安装所有这些必需的依赖项: https://github.com/SFML/SFML/wiki/Tutorial%3A-Installing-SFML-dependencies
我是否错过了任何必需的步骤?
要首先在 Ubuntu 中安装它,请在终端中运行以下命令 -
sudo apt-get install libsfml-dev
Run Code Online (Sandbox Code Playgroud)
确保您已经有编译器(GCC),如果没有,则使用 make 安装它
sudo apt-get install build-essential
Run Code Online (Sandbox Code Playgroud)
然后为了测试这一点,创建一个像这样的简单 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;
}
Run Code Online (Sandbox Code Playgroud)
现在在存储库中创建一个makefile与main.cpp
compile:./main.cpp
g++ -c ./main.cpp
g++ main.o -o app -lsfml-graphics -lsfml-window -lsfml-system
run:
./app
Run Code Online (Sandbox Code Playgroud)
现在编译它运行以下命令
compile:./main.cpp
g++ -c ./main.cpp
g++ main.o -o app -lsfml-graphics -lsfml-window -lsfml-system
run:
./app
Run Code Online (Sandbox Code Playgroud)
最后运行以下命令
make compile
Run Code Online (Sandbox Code Playgroud)