将SFML链接到Windows上的QT

Linking SFML into QT on Windows

本文关键字:上的 QT Windows SFML 链接      更新时间:2023-10-16

我应该做一个音频分析程序。我已经成功安装了QT Creator,并且我还设法包含SFML库。

这是我添加到 audioPlayer.pro 文件中的内容:

INCLUDEPATH += D:\qt\SFML-2.2\include\SFML

INCLUDEPATH += D:\qt\SFML-2.2\include

LIBS += D:\qt\SFML-2.2\bin\sfml-audio-d-2.dll

主寡妇.cpp:

void 主窗口::on_pushButton_clicked(){ QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "C://", tr("Audio files (*.wav)"));

std::string file = fileName.toStdString();
sf::SoundBuffer buffer;
buffer.loadFromFile((file));
sf::Sound sound;
sound.setBuffer(buffer);
sound.play();

}

我相信这里发生的事情很明显。

因此,当我构建项目时,我收到 8 个错误:

mainwindow.obj:-1: error: LNK2019: 未解析的外部符号 "__declspec(dllimport) public: __thiscall sf::Sound::Sound(void)" (__imp_??0Sound@sf@@QAE@XZ) 在函数"private: void __thiscall MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AAEXXZ) 中引用

其他的都是一样的,所以我没有粘贴它们。

这是最后一个:

调试\音频播放器.exe:-1:错误:LNK1120:7 个未解析的外部

所以是的。我尝试手动将编译器包含在工具>选项>构建和运行中。我设置了 MinGw 编译器。我已经遵循了这个网站和其他网站上的几个教程,但我就是想不通。

我查看了这两个链接:

https://github.com/LaurentGomila/SFML/wiki/Tutorial:-Compile-and-Link-SFML-with-Qt-Creatorhttps://github.com/LaurentGomila/SFML/wiki/Tutorial:-Link-SFML-with-Qt-Creator

但没有成功。

我通过切换到 Linux Ubuntu 解决了这个问题,我使用上面的这个链接成功地共同构建了它:https://github.com/LaurentGomila/SFML/wiki/Tutorial:-Compile-and-Link-SFML-with-Qt-Creator