锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 开源技术 / C++平台框架库和混编开源 / error C2371: 'size_t' : redefinition; different basic types

服务方向

人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发

联系方式

固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

error C2371: 'size_t' : redefinition; different basic types


重点

用VC6也遇到这个问题,头文件包含改来改去不行,在VC2010下,问题解决,注意下图:

配置x64平台

vc6太麻烦了。不建议再用。如果看图还解决不了,请联系我,专业服务,保证解决。

翻译讨论

Hi, 你好
   I'm trying to recompile an application that runs on 32-bit Windows to 64-bit Windows. The system is a Xeon processor running Windows 2003 Server and Visual Studio 2005 Professional Edition (that comes with MSDN library). 我正在尝试将在32位Windows上运行的应用程序重新编译为64位Windows。该系统是运行Windows 2003 Server和Visual Studio 2005 Professional Edition(与MSDN库一起提供)的Xeon处理软件。
For the visual studio solution, I selected x64 as my platform.  However, when I compiled the code, I got the following error message, 对于Visual Studio解决方案,我选择了x64作为平台。但是,当我编译代码时,收到以下错误消息,

                C:\Program Files\Microsoft Platform SDK\Include\crt\stdio.h(68) : 
error C2371: 'size_t' : redefinition; different basic types
                    test.c : see declaration of 'size_t'

I gather from other posts that I might have mix 32-bits tools. How do I check if I'm using 32-bits tools instead of 64-bits? Thanks! 我从其他帖子中收集到可能混合使用32位工具的信息。如何检查我使用的是32位工具还是64位工具?谢谢!

 

 

I think your question should be restated as "how do I know which platform I'm targeting?" (Different than "how do I know which platform I'm running on.") 我认为您的问题应重新陈述为“我如何知道我针对的平台?” (不同于“我如何知道我在哪个平台上运行。”)

_WIN64 is a predefinition that the compiler gives you to distinguish between 32 bit and 64 bit Windows platforms.  I don't know of a "C++ standard" that tells you this, however. _WIN64是编译器为您提供的区分32位和64位Windows平台的预定义。但是,我不知道可以告诉您这一点的“ C ++标准”。

 

Are you actually defining size_t yourself?  If you are, I'd remove it and go with whatever the headers give you. 您实际上是自己定义size_t吗?如果是的话,我会删除它,并随标题提供的内容一起去。

 

 

I didn't redefine size_t in my code. By looking at stdio.h, the error message is coming from this line, 我没有在代码中重新定义size_t。

typedef unsigned __int64    size_t;

In the preprocessor definitions, I have define __int64 as long. Does this matter? Also, should I remove macro WIN32_LEAN_AND_MEAN? 在预处理器定义中,我已经定义了__int64。这有关系吗?
Is there an equivalent for 64-bit? 另外,我应该删除宏WIN32_LEAN_AND_MEAN吗?

 

 

My version of stdio.h (VS2005) doesn't define size_t.  Make sure you're not mixing headers from different versions of VS.  You should not have two defitions of size_t. 我的stdio.h版本(VS2005)没有定义size_t。确保您没有混合使用来自不同版本VS的头文件。您不应有两个size_t定义。

Yes, it matters.  Don't define __int64 yourself.  Let the compiler and/or the VC headers do this. 是的,这很重要。不要自己定义__int64。让编译器和/或VC标头执行此操作。

If you can compile all your stuff with WIN32_LEAN_AND_MEAN then you should keep it to speed up compilation.  This macro has nothing to do with platform.  It has to do with how much of the Win32 API is pulled in when you #include <windows.h> 如果可以使用WIN32_LEAN_AND_MEAN编译所有内容,则应保留它以加快编译速度。该宏与平台无关。 #include<windows.h>时,它与导入多少Win32 API有关。

 

 

I remove the include of Platform SDK header files. Now I got the same message, but from different file within Visual studio, 我删除了Platform SDK头文件的包含。现在我得到了相同的消息,但是来自Visual Studio中的不同文件,

C:\Program Files (x86)\Microsoft Visual Studio 8\VC\INCLUDE\crtdefs.h(430) : 
error C2371: 'size_t' : redefinition; different basic types
        hello.c : see declaration of 'size_t'

I have defined in my system settings to include C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\ instead of the 32-bit one, 我在系统设置中定义为包括C:\\ Program Files \\ Microsoft Visual Studio 8 \\ VC \\ INCLUDE \\而不是32位的,
but when I open the Visual Studio 2005 x64 Win64 Command Prompt, and type 但是当我打开Visual Studio 2005 x64 Win64命令提示符时,键入
"Set" to see the environment variables, it shows that 32-bit headers are picked up first. How do I change the ordering? “设置”以查看环境变量,它表明首先拾取了32位标题。如何更改订购?

                    FrameworkDir=C:\WINDOWS\Microsoft.NET\Framework64
FrameworkSDKDir=C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0 64bit
INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 8\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK\include;C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\include;C:\Program Files\Microsoft Visual Studio 8\VC\include; VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 8\VC
VS80COMNTOOLS=C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\
VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 8

 

 

Need more info--it seems like your includes are screwed up and I can't see much from here. Hopefully we can get to the bottom of this. Under C/C++, Command Line, Additional Options, temporarily add /P and compile hello.c. (Be sure to remove /P afterward.) Open the file hello.i. Look for the two definitions of size_t and post the full path to those header files here. Under C/C++, Command Line, Additional Options, temporarily add /showIncludes and compile hello.c. During compilation you should see the includes that get pulled in. Post them here. Also, give the source code for hello.c, in as few lines as possible but still reproduces the problem. (Ideally, the #includes and a short main() function). 需要更多信息-似乎您的包含已被搞砸,从这里我看不到太多。希望我们能深入了解这一点。在项目配置选项里添加/P试下,试过记的删除。项目配置选项里添加/showincludes,编译时会看到包含指示。

 

 

A couple of things to note: 需要注意的几件事:

1) there are no separate 64-bit headers - all 64/32 differences are handled via macros and typedefs within the existing header files. 1)没有单独的64位标头-所有64/32差异都通过现有标头文件中的宏和typedef处理。

2) The compiler predefines size_t along with operator new/delete internally. This was done a long time ago before it was finalized were these operators should be defined. 2)编译器在内部预定义size_t以及运算符new / delete。在确定这些运算符之前,它是在很久以前完成的。

So it seems to me that you may be using a 32-bit compiler (which thinks size_t is 32-bits) to compile some 64-bit code that thinks size_t is 64-bits - hence the error you are seeing. You can't use the 32-bit compiler to compile 64-bit code - you need to use the 64-bit x-compilers. 因此在我看来,您可能正在使用32位编译器(认为size_t是32位)来编译一些认为size_t是64位的64位代码-因此,您会看到错误。您不能使用32位编译器来编译64位代码-您需要使用64位x编译器。

 

I know this is an older thread but in Visual Studio under Projects-->Properties choose a configuration.  Then Configuration Properties --> C/C++ -->General and Select No to Detect 64-bit Portability Issues 我知道这是一个较旧的线程,但是在Visual Studio的Projects-> Properties下选择一个配置。然后配置属性-> C / C ++->常规,然后选择否以检测64位可移植性问题

友情链接
版权所有 Copyright(c)2004-2015 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:A、郑州市芯互联大厦北楼1803A(文化路优胜北路西北角),B、郑州大学北校区院内)