SFML教程1:线程问题
你好,我正在使用 msVS++2010,并且一整天都在尝试设置 SFML.... 我从网站下载了1.6,然后在VS2010中重建它,但悲伤地发现这并没有产生一个sfml-system-d.lib文件,这是我习惯使用的,并且只产生了新的system-s和系统 SD 库。
然后我仔细观看了这个视频,发现他通过添加 sfml-system-sd 的外部库来运行他的测试代码所以我在 .exe 旁边添加了 sfml-system-d.dll 并获得了与视频显示的完全相同的代码:
#include <iostream>
#include <SFML/System.hpp>
int main(int argc, char **argv)
{
sf::Clock clock;
sf::Sleep(0.1f);
while(clock.GetElapsedTime() < 5.0f)
{
std::cout << clock.GetElapsedTime() << std::endl;
sf::Sleep(0.5f);
}
}
显然时钟和睡眠正在工作,但是当我添加简单的代码行 'sf::Thread线();'会弹出一个错误框,显示“无法启动程序”、“配置不正确”、“检查清单文件以了解可能的错误”、“正在重新安装我的修复程序。”
另外:当尝试运行有关线程的教程的第一个程序:
#include <SFML/System.hpp>
#include <iostream>
void ThreadFunction(void* UserData)
{
// Print something...
for (int i = 0; i < 10; ++i)
std::cout << "I'm the thread number 1" << std::endl;
}
int main()
{
// Create a thread with our function
sf::Thread Thread(&ThreadFunction);
// Start it !
Thread.Launch();
// Print something...
for (int i = 0; i < 10; ++i)
std::cout << "I'm the main thread" << std::endl;
return EXIT_SUCCESS;
}
我得到 8 个未解析的外部符号,如下所示:
1>sfml-system-s-d.lib(Thread.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::ios_base::width(int)" (__imp_?width@ios_base@std@@QAEHH@Z)
fatal error LNK1120: 8 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
最后,这就是我的项目的设置方式:
- 包含开箱即用的目录,新下载的 SFML 1.6/include
- lib 目录到 VS2010 重建的 SFML (调试/释放 DLL 设置和静态)。
- 对 sfml-system-sd.lib 文件的额外依赖。
- 出于沮丧,我将每个 dll 文件放在 .exe 旁边
Hi so i am using msVS++2010 and have been attempting to set up SFML all day....
I downloaded 1.6 from the site, then rebuilt it in VS2010, but sad to find that this did not result in a sfml-system-d.lib file, which is what i am used to using, and only produced new system-s and system-s-d libs.
I then closely watched this Video to find that he ran his test code by adding the external lib of sfml-system-s-d and so i added the sfml-system-d.dll next the .exe and got the following exact same code the video showed to work:
#include <iostream>
#include <SFML/System.hpp>
int main(int argc, char **argv)
{
sf::Clock clock;
sf::Sleep(0.1f);
while(clock.GetElapsedTime() < 5.0f)
{
std::cout << clock.GetElapsedTime() << std::endl;
sf::Sleep(0.5f);
}
}
obviously clock and sleep are working, but when i add the simple line of code 'sf::Thread thread();' an error box pops up saying "unable to start program," "configuration is incorrect," "Review the manifest file for possible errors," "renstalling my fix it."
Also: when trying to run the first program of the tutorials regarding threads:
#include <SFML/System.hpp>
#include <iostream>
void ThreadFunction(void* UserData)
{
// Print something...
for (int i = 0; i < 10; ++i)
std::cout << "I'm the thread number 1" << std::endl;
}
int main()
{
// Create a thread with our function
sf::Thread Thread(&ThreadFunction);
// Start it !
Thread.Launch();
// Print something...
for (int i = 0; i < 10; ++i)
std::cout << "I'm the main thread" << std::endl;
return EXIT_SUCCESS;
}
I get 8 unresovled external symbols like this one:
1>sfml-system-s-d.lib(Thread.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::ios_base::width(int)" (__imp_?width@ios_base@std@@QAEHH@Z)
fatal error LNK1120: 8 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Lastly this is how my project is set up:
- include directory to out of the box, freshly downloaded SFML 1.6/include
- lib directory to the VS2010 rebuilt SFML (debug/release DLL setting, and static).
- extra dependency on sfml-system-s-d.lib file.
- out of frusteration i placed every dll file next to the .exe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您在构建 SFML 时可能没有链接到 CRT。 (ios_width 是 iostream,需要 CRT 库。)
您需要重建 SFML,只不过这次执行以下操作:
0。复制此库列表
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
comdlg32.lib
advapi32.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
odbc32.lib
odbccp32.lib
进入每个
单个项目的
属性 ->
。配置->链接器->输入
或者如果它没有“链接器”,则去
进入
属性->配置->
图书管理员。
将“忽略默认库”设置为
“否”,它可能会起作用
如果您在“图书馆员”选项卡中,请设置
将库依赖项链接到 YES
每次重复步骤 1-4
更改调试的构建设置
DLL、调试静态等。
当我重新编译 SFML 时(当然,我进行了静态编译,因为 1.6 是 1.x 行的最后一个,而 2.0 不兼容;))我必须添加这些引用。它将忽略(并“警告”忽略)它不需要的任何内容,但它们是默认值;)
不幸的是,您需要更新 SFML 解决方案中的所有内容,因为,如果我没记错的话,它们都缺少默认库。
It sounds like you might not be linking to the CRT when building SFML. (ios_width is iostream, which requires the CRT library.)
You need to rebuild SFML, except this time do the following:
0. copy this list of libs
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
comdlg32.lib
advapi32.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
odbc32.lib
odbccp32.lib
go into each
individual Project's
Properties ->
.Configuration -> Linker -> Input
or if it doesn't have 'Linker' go
into
Properties -> Configuration ->
.Librarian
Set "Ignore Default Libraries" to
"no" and it will probably work
If you wanna be 100% safe, click on additional dependencies, expand it, and click "edit." now just paste in the libs above
If your in the 'librarian' tab, set
Link Library Dependencies to YES
repeat steps 1-4 each time you
change the build setting of Debug
DLL, Debug static, etc.
When I recompiled SFML (granted, I have a static compile because 1.6 is the last of the 1.x line, and 2.0 isn't compatible ;)) I had to add those references. It will ignore (and 'warn' about ignoring) anything it doesn't need, but they are the defaults ;)
Unfortunately you'll need to update everything in the SFML solution, as, if I recall correctly, they are all missing the default libraries.