error: ‘snprintf’ was not declared in this scope

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

error: ‘snprintf’ was not declared in this scope

Postby JohnHolmes on Tue Nov 22, 2016 4:25 pm

Hoi,

I am not able to get it working :( ,

Includes:

Code: Select all
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
//#include <cstdio>
#include <kos.h>


Currently using the default path set by KOS but have also tried the absolute for stdio in newlib 2.0 but no difference.

Makefile
Code: Select all
main.elf: $(OBJS)
   $(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $@ $(KOS_START) $^ -lkmg -lkosutils -lstdc++ -lm $(KOS_LIBS)



Code: Select all
GCC 4.7.3


Any suggestions ?
JohnHolmes
Chaos Rift Newbie
Chaos Rift Newbie
 
Posts: 8
Joined: Wed Jul 20, 2016 6:18 am

Re: error: ‘snprintf’ was not declared in this scope

Postby Nokurn on Tue Nov 22, 2016 8:37 pm

Are you using C or C++? Your includes are for C headers (with a C++ header commented out). In your makefile, you're using KOS_CC, which should be a C compiler (vs. KOS_CXX), but you're linking with the C++ standard library (-lstdc++). If you're using C++ you might want to try std::snprintf instead (or put using namespace std; after your includes). The compiler is passing the preprocessor stage since you're getting semantic analysis errors, so your include statements are working. It's not a linker error, although I suspect your linking isn't all there. Other than that, it's hard to say. You could see if snprintf's declaration is being preprocessed out with #ifndef/#ifdef/#if directives in stdio.h.
User avatar
Nokurn
Chaos Rift Regular
Chaos Rift Regular
 
Posts: 174
Joined: Mon Jan 31, 2011 2:08 pm
Location: Southern California

Re: error: ‘snprintf’ was not declared in this scope

Postby JohnHolmes on Wed Nov 23, 2016 6:37 pm

Thank you for the reply!

c++.
I feel like neo when he took the pill..(going from ms vs to vim and having to setup everything)

changed the makefile to kos_cpplus, still complaining, tried both the default cstdio and the one in global, same thing.
and then....... in environ from export KOS_CPPFLAGS="-std=c++11" to export KOS_CPPFLAGS="-std=gnu++11", and my life is complete.

:oops:
JohnHolmes
Chaos Rift Newbie
Chaos Rift Newbie
 
Posts: 8
Joined: Wed Jul 20, 2016 6:18 am


Return to Programming Discussion

Who is online

Users browsing this forum: No registered users and 2 guests