【发布时间】:2018-11-15 09:46:44
【问题描述】:
我知道存在类似的问题,我已经看到了,但在我决定必须问之前,我在数小时的故障排除中遇到了这些问题。
我是 C++ 新手,通过课程学习。我的任务要求我使用第三方库:SFML。我当前的编码设置是使用带有 C++ 插件的 Netbeans,Windows 10。以前我使用的是 Cygwin 编译器。 SFML 声称它要求它与编译它的编译器之一的确切版本一起使用,所以我选择了 MinGW 7.3.0,我已经安装并继续尝试。
在"Project" -> Properties -> Build -> C++ Compiler,我添加了SFML的includes目录:
“C:/Users/Drayux/Documents/Coding/NetBeans/Third Party Libraries/SFML-2.5.1/include”
在这里,在 -> 我还添加了预处理器定义:
SFML_STATIC
按照教程here的建议。
在“Project” -> Properties -> Build -> Linker 中,我添加了 SFML 的 lib 和 bin 目录:
“C:/Users/Drayux/Documents/Coding/NetBeans/Third Party Libraries/SFML-2.5.1/bin”
“C:/Users/Drayux/Documents/Coding/NetBeans/第三方库/SFML-2.5.1/lib”
最后,我确保在链接器部分的库部分下手动添加每个库。也如上述教程所建议的那样。
做完这一切,我就可以编写一个标准的程序来编译和运行了。但是,一旦我开始包含 SFML 库的标头,有时代码会构建,但不会运行,有时它根本不会一起构建。
以这个示例代码为例:
#include <iostream>
using namespace std;
#include <SFML/Graphics.hpp>
using namespace sf;
int main() {
cout << "Test output line" << endl;
RenderWindow window(VideoMode(200, 200), "Hello there!");
//CircleShape shape(100.f);
return 0;
}
当我尝试在上述配置下构建它时,构建成功,但运行不成功。这是两个控制台。
构建:
cd 'C:\Users\Drayux\Documents\Coding\NetBeans\Lab7C'
C:\Program Files\MinGW\MSYS\bin\make.exe -f Makefile CONF=Debug
"/C/Program Files/MinGW/MSYS/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/Drayux/Documents/Coding/NetBeans/Lab7C'
"/C/Program Files/MinGW/MSYS/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/lab7c.exe
make.exe[2]: Entering directory `/c/Users/Drayux/Documents/Coding/NetBeans/Lab7C'
make.exe[2]: `dist/Debug/MinGW-Windows/lab7c.exe' is up to date.
make.exe[2]: Leaving directory `/c/Users/Drayux/Documents/Coding/NetBeans/Lab7C'
make.exe[1]: Leaving directory `/c/Users/Drayux/Documents/Coding/NetBeans/Lab7C'
BUILD SUCCESSFUL (total time: 3s)
运行:
C:/Users/Drayux/Documents/Coding/NetBeans/Lab7C/dist/Debug/MinGW-Windows/lab7c.exe: error while loading shared libraries: sfml_window-d-2.dll: cannot open shared object file: No such file or directory
RUN FAILED (exit value 127, total time: 74ms)
我也尝试了将 LD_LIBRARY_PATH 添加到项目属性中运行下的环境部分的解决方案,但没有成功。
考虑到我的情况,没有其他解决方案,我感到被困住了。非常感谢任何帮助。
谢谢, 利亚姆
【问题讨论】:
标签: c++ netbeans shared-libraries mingw sfml