C programming: How can I get snprintf to work?

Discussion in 'Computer Programming, Emulation, and Game Modding' started by mashers, Sep 8, 2016.

  1. mashers

    mashers Stubborn ape

    Jun 10, 2015
    Kongo Jungle
    I'm integrating bits of GodMode9 into my custom A9LH payload. One of the parts I need uses the C function snprintf. When I compile GodMode9, this works fine. But when I compile my own software I get a warning about an implicit declaration, and then the following error at the end of the build process:

    /opt/devkitPro/devkitARM/bin/../lib/gcc/arm-none-eabi/5.3.0/../../../../arm-none-eabi/lib/libsysbase.a(sbrk.o): In function `_sbrk_r':
    (.text+0x6c): undefined reference to `__end__'
    collect2: error: ld returned 1 exit status
    make[1]: *** [build/payload_stage2.elf] Error 1
    make: *** [stage2] Error 2
    If I comment out the line with snprintf, it compiles fine. I have included stdio.h in the .c file which uses this function but it hasn't made any difference. I then checked the makefile and found that it was set to c11, so I changed it to c99 but this also made no difference. I then noticed that there are some differences between the C flags in the makefiles for GodMode9 and my own programme:

    • GodMode9 has the following flags which mine does not: -g -Wpedantic -Wcast-align -pedantic -march=armv5te -mtune=arm946e-s -fomit-frame-pointer
    • My software has the following flags which GodMode9 does not: -MMD -MP -mcpu=arm946e-s -fno-builtin -Wno-main

    Does anybody know if any of these flags are responsible for me not being able to use snprintf and if so, how can I get around this?

    Thanks in advance!
  2. JoostinOnline

    JoostinOnline Certified Crash Test Dummy

    Apr 2, 2011
    United States
    The Twilight Zone
    Please post a snippet of the code, including your use of snprintf.
  3. mashers

    mashers Stubborn ape

    Jun 10, 2015
    Kongo Jungle
    Thanks for your reply. The calls to snprintf() are quite deeply embedded within other functions so it's hard to post a snippet. However, in the end the solution was to set the CFLAGS in the makefile of 3DSafe to be the same as those in GodMode9 and to include <stdio.h>. It builds and works now :)
    JoostinOnline likes this.
  4. JohnGT

    JohnGT Member

    Jun 21, 2016
    Last edited by JohnGT, Sep 8, 2016
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice