error C3861: 'sprintf_s': identifier not found

Poscik

Addon Developer
Addon Developer
Joined
Mar 28, 2008
Messages
512
Reaction score
3
Points
18
Location
Sulejówek
It's not the first time, when I have that problem. I wrote very simple mfd with secure functions, but I can't compile it. I hace that error which is in topic. Compiler is configured like in OrbiterWiki article. I tried to compile source on VC2005 and VC2008. In both I couldn't do that. Included headers:

#include "windows.h"
#include "orbitersdk.h"
#include "ssua.h"
#include "math.h"
#include "stdio.h"

What's wrong?
 
Hmm... maybe you have not updated the platform SDK since 2003?
 
Heh, no :) In 2003 I didn't know what is C++. If I remember, I have installed Platform SDK 2 years ago.
 
Then, you should have the functions in the standard C libraries... <cstdio> for example.
 
When I replace "stdio.h" to <cstdio>, I have the same effect :(
And If I have this problem, I can't compile CRT MFD too...
 
Did you try compiling before you started your own MFD? Could it possibly be your code missing a ';' or something...
 
I made small experiment. I wrote program for command prompt, which is using sprintf_s. I included <stdio.h> and VC2008 built it with no errors and no warning. Very strange situation...
 
Yeah, looks like your settings lack an important system library maybe.
 
I tried to change a lot of options... no result.
Here is my configuration:
include.JPGlinkergeneral.JPGlinkerinput.JPG
 
And do you have any #defines missing in the beginning of the program? I think you need to define ORBITER_MODULE, but I doubt this causes your problem.
 
First few lines from CRT MFD:
Code:
#define STRICT
#define ORBITER_MODULE

#include "windows.h"
#include "orbitersdk.h"
#include "PanelR2.h"
#include "PanelC2.h"
#include "vc/MDU.h"
#include "vc/vc_defs.h"
#include "CRT.h"
#include "stdio.h"
#include "dps/IDP.h"
#include "dps/MasterTimingUnit.h"
...
 
Poscik
Just replace sprintf_s with plain old sprintf and throw away the second argument (buffer size). Should work.
The warnings about 'deprecated function' can be either ignored, or suppressed via
Code:
#define _CRT_SECURE_NO_WARNINGS
before you include standard libraries. A more radical approach is to put this #define right into "crtdefs.h", that is included in every CRT header (that's what I did).
 
Back
Top