69,369
社区成员
发帖
与我相关
我的任务
分享
msdn上的说法
Visual C++ Concepts: Building a C/C++ Program
C Run-Time Error R6002
Error Message
floating-point support not loaded
The necessary floating-point library was not linked.
To fix by checking the following possible causes
1.
The program was compiled or linked with an option, such as /FPi87, that requires a coprocessor, but the program was run on a machine that did not have a coprocessor installed.
2.
A format string for a printf_s or scanf_s function contained a floating-point format specification and the program did not contain any floating-point values or variables.
3.
The compiler minimizes a program's size by loading floating-point support only when necessary. The compiler cannot detect floating-point format specifications in format strings, so it does not load the necessary floating-point routines.
4.
Use a floating-point argument to correspond to the floating-point format specification, or perform a floating-point assignment elsewhere in the program. This causes floating-point support to be loaded.
5.
In a mixed-language program, a C library was specified before a FORTRAN library when the program was linked. Relink and specify the C library last.
PRB: "Floating-point Support Not Loaded" Error with scanf()
View products that this article applies to.
Article ID : 37507
Last Review : September 17, 2003
Revision : 3.0
This article was previously published under Q37507
On This Page
SYMPTOMS
CAUSE
RESOLUTION
STATUS
MORE INFORMATION
Sample Code
SYMPTOMS
When an application uses the scanf() function to read a floating-point value from the console into an uninitialized "float" type global variable, an R6002 "floating-point format support not loaded" error occurs. This error also occurs when any formatted input routine is used to read a value.
Back to the top
CAUSE
The compiler does not generate a reference to the __fltused variable that instructs the linker to load the floating-point support module.
Back to the top
RESOLUTION
To work around this problem, initialize the floating-point variable or use the variable in an expression in the routine that contains the scanf() call.
Back to the top
STATUS
This behavior is expected. To minimize the size of the executable file, the compiler loads floating-point support only when it is required.
Back to the top
MORE INFORMATION
When a module uses only one of the formatted input routines and does not also initialize a floating-point variable, the compiler does not load floating-point support.
Remove the comment indication from either or both of the two lines in the sample code below to eliminate the R6002 error.
Back to the top
Sample Code
/*
* Compile options needed: none
*/
#include <stdio.h>
float x ;
main()
{
// Remove the comment from the next line to eliminate the error.
// x = 2.3 ;
scanf ("%f", &x) ;
// Remove the comment from the next line to eliminate the error.
// printf ("%f\n", x) ;
}
Back to the top
APPLIES TO
• The C Run-Time (CRT), when used with:
Microsoft C Professional Development System 6.0
Microsoft C Professional Development System 6.0a
Microsoft C Professional Development System 6.0a
Microsoft C Professional Development System 6.0
Microsoft C Professional Development System 6.0a
Microsoft C/C++ Professional Development System 7.0
Microsoft Visual C++ 1.0 Professional Edition
Microsoft Visual C++ 1.5 Professional Edition
Microsoft Visual C++ 5.0 Learning Edition
Microsoft Visual C++ 2.0 Professional Edition
Microsoft Visual C++ 4.0 Professional Edition
Microsoft Visual C++ 5.0 Professional Edition
Microsoft Visual C++ 6.0 Professional Edition
这个现象叫
Floating-point Support Not Loaded
vc6.0 和更老的版本会存在这个问题,vs2005 如果你使用c编译也可能存在这个问题,使用c++编译一般就正常
这个现象的表现是,如果你在使用scanf函数之前没使用过浮点运算,那么scanf就会出错
比如
#include <stdio.h>
int main()
{
float x ;
scanf ("%f", &x) ;
return 0;
}
所以为了避免这个问题,你可以在scanf之前使用一下浮点运算
比如上面的改成
#include <stdio.h>
int main()
{
float x = 0.f;
scanf ("%f", &x) ;
return 0;
}
就没问题了
// 加上这一句是避免连接器不载入c的运行时浮点库,参见《c专家编程》
float c = 1.f;