Собрал SFML из исходников компилятором MSVC как статическую библиотеку, далее прилинковал полученные
.lib
файлы к проекту:
cmake_minimum_required(VERSION 3.26)
project(PingPong)
set(CMAKE_CXX_STANDARD 23)
add_executable(PingPong main.cpp)
target_include_directories(PingPong PRIVATE libs/sfml/include)
target_link_libraries(PingPong PRIVATE
${PROJECT_SOURCE_DIR}/libs/sfml/bin/sfml-graphics-s-d.lib
${PROJECT_SOURCE_DIR}/libs/sfml/bin/sfml-main-d.lib
${PROJECT_SOURCE_DIR}/libs/sfml/bin/sfml-network-s-d.lib
${PROJECT_SOURCE_DIR}/libs/sfml/bin/sfml-system-s-d.lib
)
Затем в файл
main.cpp
поместил код из документации:
#include <SFML/Window.hpp>
int main()
{
sf::Window window(sf::VideoMode(800, 600), "My window");
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event{};
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
}
return 0;
}
И после запуска получаю ошибки (проект запускается тем же компилятором, что использовался при сборке библиотеки):
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::String::String(char const *,class std::locale const &)" (__imp_??0String@sf@@QEAA@PEBDAEBVlocale@std@@@Z) referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::String::~String(void)" (__imp_??1String@sf@@QEAA@XZ) referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QEAA@III@Z) referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __cdecl sf::WindowBase::isOpen(void)const " (__imp_?isOpen@WindowBase@sf@@QEBA_NXZ) referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __cdecl sf::WindowBase::pollEvent(class sf::Event &)" (__imp_?pollEvent@WindowBase@sf@@QEAA_NAEAVEvent@2@@Z) referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::Window::Window(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (__imp_??0Window@sf@@QEAA@VVideoMode@1@AEBVString@1@IAEBUContextSettings@1@@Z) referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl sf::Window::~Window(void)" (__imp_??1Window@sf@@UEAA@XZ) referenced in function main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void __cdecl sf::Window::close(void)" (__imp_?close@Window@sf@@UEAAXXZ) referenced in function main