|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 hellomyprogram 于 2023-7-22 18:51 编辑
我在按照网上的教程构建完环境之后,运行时遇到了这样的问题:D:/NoSpacePrograms/MinGW/bin/g++.exe -fdiagnostics-color=always -g "项目目录/*.cpp" -o "项目目录/.vscode/program.exe" -I D:/NoSpacePrograms/MinGW-SFML/include -lsfml-graphics -lsfml-system -lsfml-window
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/libsfml-graphics.a when searching for -lsfml-graphics
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib\libsfml-graphics.a when searching for -lsfml-graphics
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/../lib/libsfml-graphics.a when searching for -lsfml-graphics
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/../lib\libsfml-graphics.a when searching for -lsfml-graphics
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/libsfml-graphics.a when searching for -lsfml-graphics
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib\libsfml-graphics.a when searching for -lsfml-graphics
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/libsfml-graphics.a when searching for -lsfml-graphics
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/../lib/libsfml-graphics.a when searching for -lsfml-graphics
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/libsfml-graphics.a when searching for -lsfml-graphics
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsfml-graphics
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/libsfml-system.a when searching for -lsfml-system
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib\libsfml-system.a when searching for -lsfml-system
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/../lib/libsfml-system.a when searching for -lsfml-system
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/../lib\libsfml-system.a when searching for -lsfml-system
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/libsfml-system.a when searching for -lsfml-system
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib\libsfml-system.a when searching for -lsfml-system
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/libsfml-system.a when searching for -lsfml-system
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/../lib/libsfml-system.a when searching for -lsfml-system
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/libsfml-system.a when searching for -lsfml-system
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsfml-system
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/libsfml-window.a when searching for -lsfml-window
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib\libsfml-window.a when searching for -lsfml-window
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/../lib/libsfml-window.a when searching for -lsfml-window
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/../lib\libsfml-window.a when searching for -lsfml-window
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/libsfml-window.a when searching for -lsfml-window
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib\libsfml-window.a when searching for -lsfml-window
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/libsfml-window.a when searching for -lsfml-window
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/../lib/libsfml-window.a when searching for -lsfml-window
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible D:/NoSpacePrograms/MinGW-SFML/lib/libsfml-window.a when searching for -lsfml-window
D:/NoSpacePrograms/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: [b]cannot find -lsfml-window
collect2.exe: error: ld returned 1 exit status
我的MinGW版本为7.3.0,SFML为2.5.1。
以下是我按照网上教程构建的时候创建的“c_cpp_properties.json”文件:{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:/NoSpacePrograms/MinGW/include",
"D:/NoSpacePrograms/MinGW-SFML/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/NoSpacePrograms/MinGW/bin/gcc.exe",
"cStandard": "c17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
还有“tasks.json”文件:{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "D:/NoSpacePrograms/MinGW/bin/g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${fileDirname}/*.cpp",
"-o",
"${fileDirname}/.vscode/program.exe",
"-I",
"D:/NoSpacePrograms/MinGW-SFML/include",
"-lsfml-graphics",
"-lsfml-system",
"-lsfml-window"
],
"options": {
"cwd": "D:/NoSpacePrograms/MinGW/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
VSCode并没有对我的这行代码进行警告,但是编译器产生的错误指向了这一行代码:#include <SFML/Graphics.hpp>
我已经向用户环境变量PATH添加了MinGW和SFML的bin路径,向用户环境变量CPLUS_INCLUDE_PATH和LIBRARY_PATH分别添加了SFML的include路径和lib路径。
错误信息似乎提到不存在-lsfml之类的参数,但是网上的教程都是加了这些参数的,去掉参数照样报错。
根据“skipping incompatible”一则消息,编译器似乎觉得SFML的源文件是不可取的。
我参考的教程是https:// www .xjx100.cn/news/435339.html
看起来你遇到的问题是由于链接器找不到与你的 MinGW 环境兼容的 SFML 库文件。你需要确保下载的 SFML 版本与你的 MinGW 的架构(32位或64位)和版本匹配。如果 MinGW 是64位的,那么 SFML 库也必须是64位的。反之亦然,如果你的 MinGW 是32位的,你需要使用32位的 SFML 库。
你可以按照以下步骤进行操作:
1. 首先,确定你的 MinGW 是32位还是64位。你可以通过在终端中运行 gcc -v 来查看。在最后一行,如果看到 "Target: x86_64-w64-mingw32",那么你的 MinGW 是64位的。如果看到 "Target: i686-w64-mingw32",那么你的 MinGW 是32位的。
2. 一旦你知道了 MinGW 的架构,你就可以下载相应版本的 SFML 库。你可以从 SFML 官方网站的下载页面下载。确保选择的 SFML 库与你的 MinGW 架构匹配。
3. 下载并解压 SFML 库后,将其复制到你的 MinGW 安装目录中。例如,如果你的 MinGW 安装在 "D:/NoSpacePrograms/MinGW",你可以将 SFML 库复制到 "D:/NoSpacePrograms/MinGW-SFML"。
4. 在你的 "tasks.json" 文件中,确保 -lsfml-graphics , -lsfml-system 和 -lsfml-window 参数出现在链接器参数列表的最后。链接器参数应该如下所示:
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "D:/NoSpacePrograms/MinGW/bin/g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${fileDirname}/*.cpp",
"-o",
"${fileDirname}/.vscode/program.exe",
"-I",
"D:/NoSpacePrograms/MinGW-SFML/include",
"-L",
"D:/NoSpacePrograms/MinGW-SFML/lib",
"-lsfml-graphics",
"-lsfml-window",
"-lsfml-system"
],
...
}
在这里, -L 参数指定了库文件的路径, -l 参数告诉链接器链接哪些库。
5. 最后,确保你的项目中包含了 SFML 的头文件,并且你正确地使用了 SFML 的命名空间和类。例如:
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
// ...
return 0;
}
希望这些信息对你有所帮助,如果你还有其他问题,欢迎继续提问。
|
评分
-
查看全部评分
|