VS2015+SFML贪吃蛇跨设备运行报错:MSVCP140D.DLL缺失及0xc000007b问题求助
解决SFML贪吃蛇游戏在笔记本上的启动错误(MSVCP140D.DLL缺失及0xc000007b)
先帮你拆解下这两个错误的核心原因,再给你针对性的解决方案:
1. 为什么会出现MSVCP140D.DLL缺失?
MSVCP140D.DLL是Debug版本的VC++运行时库文件,这类文件是给开发环境(比如你主电脑上的Visual Studio)用的,本来就不应该靠复制文件来解决——笔记本没装VS,自然没有Debug版的运行时库。
2. 复制DLL后出现0xc000007b错误的原因
这个错误大概率是运行时库的架构不匹配:比如你主电脑是64位,编译的是64位Debug程序,但笔记本是32位;或者你复制的Debug DLL和笔记本上已有的VC++库版本冲突,导致程序无法正常加载。
正确的解决方案
方案一:切换到Release模式编译(最推荐)
Debug模式只适合开发调试,要在其他机器上运行程序,必须用Release模式:
- 在Visual Studio 2015的工具栏里,把当前解决方案配置从
Debug改成Release - 重新编译你的程序
- 把Release文件夹里的可执行文件,加上SFML对应的Release版依赖库(注意是不带
-d后缀的,比如sfml-graphics-2.dll、sfml-window-2.dll、sfml-system-2.dll),还有程序用到的images文件夹,一起复制到笔记本上
方案二:给笔记本装Debug版VC++运行时(仅用于调试)
如果你非要在笔记本上跑Debug版本的程序,需要安装对应版本的Debug运行时:
- 下载Visual Studio 2015的Remote Tools(用于在无VS的机器上调试),里面包含Debug版VC++库
- 或者直接在笔记本上装Visual Studio 2015开发环境(没必要,除非你要在笔记本上调试代码)
方案三:检查SFML架构匹配
确保你编译程序的架构(x86/x64)和SFML的架构完全一致:
- 程序是x86编译的,就用32位SFML库;x64编译的就用64位SFML
- 笔记本的系统架构(32/64位)也要和程序架构匹配
你的代码(格式化后)
// GraphicalLoopSnakeGame.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <SFML/Graphics.hpp> #include <time.h> using namespace sf; int N = 30, M = 20; int size = 16; int w = size*N; int h = size*M; int dir, num = 4; struct Snake { int x, y; } s[100]; struct Fruit { int x, y; } f; void Tick() { for (int i = num; i > 0; --i) { s[i].x = s[i - 1].x; s[i].y = s[i - 1].y; } if (dir == 0) s[0].y += 1; if (dir == 1) s[0].x -= 1; if (dir == 2) s[0].x += 1; if (dir == 3) s[0].y -= 1; if ((s[0].x == f.x) && (s[0].y == f.y)) { num++; f.x = rand() % N; f.y = rand() % M; } if (s[0].x > N) s[0].x = 0; if (s[0].x < 0) s[0].x = N; if (s[0].y > M) s[0].y = 0; if (s[0].y < 0) s[0].y = M; for (int i = 1; i < num; i++) if (s[0].x == s[i].x && s[0].y == s[i].y) num = i; } int main() { srand(time(0)); RenderWindow window(VideoMode(w, h), "Snake Game!"); Texture t1, t2, t3; t1.loadFromFile("images/white.png"); t2.loadFromFile("images/red.png"); t3.loadFromFile("images/green.png"); Sprite sprite1(t1); Sprite sprite2(t2); Sprite sprite3(t3); Clock clock; float timer = 0, delay = 0.12; f.x = 10; f.y = 10; while (window.isOpen()) { float time = clock.getElapsedTime().asSeconds(); clock.restart(); timer += time; Event e; while (window.pollEvent(e)) { if (e.type == Event::Closed) window.close(); } if (Keyboard::isKeyPressed(Keyboard::Left)) dir = 1; if (Keyboard::isKeyPressed(Keyboard::Right)) dir = 2; if (Keyboard::isKeyPressed(Keyboard::Up)) dir = 3; if (Keyboard::isKeyPressed(Keyboard::Down)) dir = 0; if (timer > delay) { timer = 0; Tick(); } ////// draw /////// window.clear(); for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) { sprite1.setPosition(i*size, j*size); window.draw(sprite1); } for (int i = 0; i < num; i++) { sprite2.setPosition(s[i].x*size, s[i].y*size); window.draw(sprite2); } sprite3.setPosition(f.x*size, f.y*size); window.draw(sprite3); window.display(); } return 0; }
内容的提问来源于stack exchange,提问作者Omid Ki
相关产品推荐
相关产品推荐

