SFML 库未定义引用

问题描述 投票:0回答:0

我一直在尝试使用 CMake 在 vscode 上运行 sfml。在让 cmake 构建一个工作的可执行文件之后。我写了一个简单的程序来制作一个窗口并画一个圆圈。 Hoverver 当我构建程序时出现未定义的引用错误。

f:/program files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: F:/projects/game engine/lib/libsfml-system-s-d.a(Err.cpp.obj):Err.cpp:(.rdata+0x40): undefined reference to `std::basic_streambuf<char, std::char_traits<char> >::seekpos(std::fpos<int>, std::_Ios_Openmode)'
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    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;
}

这是我的main.cpp

cmake_minimum_required(VERSION 3.0.0)
project(game_engine VERSION 0.1.0)
SET(SFML_STATIC_LIBRARIES TRUE)
include_directories(${CMAKE_SOURCE_DIR}/include)
SET(SFML_DIR ${CMAKE_SOURCE_DIR}/lib/cmake/SFML)
find_package(SFML COMPONENTS graphics system window REQUIRED)

include(CTest)
enable_testing()

add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} sfml-graphics sfml-window)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

这是我的 cmake 列表

我正在使用 vscode 并使用 cmake 工具扩展

我决定制作一个 makefile 来检查是否有任何变化,这是我的代码:

make:
    g++ -g src/main.cpp -Iinclude -Llib -lopenal32 -lsfml-main -lsfml-system -l sfml-window -lsfml-graphics -lsfml-network -lsfml-audio -o main

当我运行可执行文件时出现以下错误

  1. sfml-graphics-2.dll 未找到
  2. sfml-window-2.dll 找不到
  3. sfml-system-2.dll 找不到

文件夹组织如下

Project
|-bin(all DLL files)
|-build(Cmake build files)
|-include(headers and other cpp files)
|-lib(all static libraries)
|  |-cmake
|  |    |-SFML
|-src(my main.cpp)
|-CMakeLists.txt
|-MakeFile
c++ cmake sfml
© www.soinside.com 2019 - 2024. All rights reserved.