已定义或声明"sf::Unicode::Text::text"成员函数
"sf::Unicode::Text::text" member function already defined or declared
我最近成功地为qt-creator设置了SFML,但在编译下面的代码时,我遇到了三个奇怪的错误,这些错误与我的程序无关。我必须指定其他C++程序运行良好。这是代码:
#include <SFML/System.hpp>
#include <iostream>
int main()
{
sf::Clock Clock;
while (Clock.GetElapsedTime() < 5.f)
{
std::cout << Clock.GetElapsedTime() << std::endl;
sf::Sleep(0.5f);
}
return 0;
}
错误如下:
f:SFML-1.6includeSFMLSystemUnicode.hpp:82: error: C2535: 'sf::Unicode::Text::Text(const wchar_t *)' : member function already defined or declared
f:SFML-1.6includeSFMLSystemUnicode.hpp:87: error: C2535: 'sf::Unicode::Text::Text(const std::wstring &)' : member function already defined or declared
f:SFML-1.6includeSFMLSystemUnicode.hpp:99: error: C2535: 'sf::Unicode::Text::operator std::wstring(void) const' : member function already defined or declared
知道是什么原因造成的吗?
编辑:
我还应该提到,我从未接触过出现错误的文件。我所尝试的只是粘贴SFML网站上的示例代码,这导致了上面的错误。我相信我已经正确地设置了SFML。
第2版:我使用的是Windows XP SP3,Mingw编译器
我很久以前就遇到过这个问题,唯一对我有效的解决方案和解释(复制自我最初咨询的另一个论坛帖子):
QMake将编译器选项
treat wchar_t as a built-in type
设置为false
,使wchar_t
成为unsigned short
的typedef,使对于unsigned short
和wchar_t
都过载的函数(如sf::Unicode::Text
构造函数)失败。。。我认为除了修改SFML源之外,唯一的解决方案是在\mkspecs\win32-msvc2008\qmake.conf文件。然后可能重新编译Qt。
我更改了配置文件并重新编译了qt,它已经开始发挥魅力了。
根据http://msdn.microsoft.com/en-us/library/dh8che7s%28v=vs.80%29.aspx
如果指定了/Zc:wchar_t-,编译器要求您定义wchar_t或包含定义它的许多头文件中的一个(例如wchar.h)。通常,wchar_t被定义为无符号短。
在Visual Studio开发环境中设置此编译器选项
Open the project's Property Pages dialog box. For details, see Modifying Project Settings.
Click the C/C++ folder.
Click the Language property page.
Modify the Treat wchar_t as Built-in Type property.
所以问题是在Config.hpp 中
typedef unsigned short Uint16;
并且有了这个/Zc:wchar_t选项,wchar_
typedef unsigned short wchar_t;
所以它们等于
- 使用 sf::Text 数组时崩溃
- 为什么 sf::Text 显示点而不是数字?
- 从DLL导出函数,LoadLibrary()需要用TEXT转换的字符串才能编译而不会出错
- 为 g++ build 设置超时,为 Sublime Text 运行?
- 编辑期间的 QTableWidgetItem text() 属性
- 如何找到目标文件 *.o 的 ram rom 使用情况(.bss .text .rodata .data)?
- 在 Linux 上编译 - 在函数 '_start' 中:(.text+0x20):对 'main' 的未定义引用
- 当我尝试绘制 sf::Text 对象时,SFML 中的分段错误
- 在 .text 部分中定义只读数据的原因是什么?
- (.text+0x20):对"主要"的未定义引用是什么意思
- 如何使用Stroustrup的Fltk Text类调用变量?
- 带有定制 GLFW 二进制 /usr/bin/ld 的 Centos 7: /usr/local/lib/libglfw3.a(init.c.o):".text"部分中无法识别的重定位 (0x2a)
- 从emxArray_uint8_T检测到错误:.text+0xc1):未定义对"emxInit_uint8_T1(emxArray_uint8_T**, int)"的引用?
- Poco c++ 如何从PostgreSQL DB读取"text"数据类型?
- crt1.o:在函数"_start"中:(.text+0x20):对"main"的未定义引用
- Sublime Text 3 在我尝试编译C++代码时在状态栏上显示"No Build System"。为什么?
- 看起来如此主要的错误.cpp:(.text.startup+0xd6):未定义对"vtable for Counter"的引用?
- 为什么参数接受"text"而不是字符串变量?
- main.cpp:(.text+0x8ea):在C++中未定义的引用
- 已定义或声明"sf::Unicode::Text::text"成员函数