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

Post Reply
JohnHolmes
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 8
Joined: Wed Jul 20, 2016 5:18 am

error: ‘snprintf’ was not declared in this scope

Post by JohnHolmes »

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 ?
User avatar
Nokurn
Chaos Rift Regular
Chaos Rift Regular
Posts: 164
Joined: Mon Jan 31, 2011 12:08 pm
Favorite Gaming Platforms: PC, SNES, Dreamcast, PS2, N64
Programming Language of Choice: Proper C++
Location: Southern California
Contact:

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

Post by Nokurn »

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.
JohnHolmes
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 8
Joined: Wed Jul 20, 2016 5:18 am

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

Post by JohnHolmes »

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:
Post Reply