undefined reference to puts? - General Help and Assistance on using CHDK stable releases - CHDK Forum supplierdeeply

undefined reference to puts?

  • 2 Replies
  • 5857 Views
undefined reference to puts?
« on: 14 / June / 2011, 11:13:52 »
Advertisements
I've been trying to write some code to put into core/, and I've been running into lots of problems.

I want to be able to write stuff to a file, but I haven't been able to write anything. On top of this, every instance of fprintf and printf has returned the error "undefined reference to puts." I think I am able to work around the fprintf problem, but I am trying to use printf to debug (http://chdk.wikia.com/wiki/Debugging#Logging_camera_console_output), so I'm not sure there's an alternative to that. Can anyone figure out whats going wrong? Also, help with why a script calling this function crashes (when the printf compile errors are commented out) would be a great bonus  :D

file.h
Code: [Select]
#ifndef __FILE__
#define __FILE__

#include "../include/platform.h"
#include "../include/stdlib.h"

void function(void);

#endif

and file.c
Code: [Select]
#include "file.h"
#include "stdio.h"
#include "../include/platform.h"

/*declare some variables*/

void function(void)
{
    FILE* fn;
fn = fopen("A/CHDK/LOGS/file.txt", "w");
        if (fn == null) {
            printf("Error\n");
        }
int buflen = sprintf(buffer, "Writing test text to file\n");
fwrite(buffer, 1, buflen, fn);
fclose(fn);
fn = fopen("A/CHDK/LOGS/file.txt", "a");
        //perform actual operations
        fclose(fn);

}

*

Offline reyalp

  • ******
  • 14121
Re: undefined reference to puts?
« Reply #1 on: 14 / June / 2011, 17:02:48 »
Note that you will never see the output of the cameras Printf event proc (it starts with a capital P) unless you use uart redirection or similar, as described in the wiki page you linked.

The simplest way to call it is to just use call_event_proc("Printf",...) from your lua script. There are some complications calling vararg firmware functions from CHDK thumb code, which is why they aren't exposed directly.

You can hack around this by making your wrapper accept the most arguments you ever expect to use and pass them to the arm function, and then *not* giving any prototype and treating it as a vararg when you call it. This should be OK for printf like functions, as the extra garbage arguments will be ignored. You can also call arm functions directly *if* they return in a thumb safe way like BX LR.

I have no idea why your code crashes, but a romlog might give you some hints.

Here's how I set up LogPrintf in wrappers .c (note, you will have to find the address for your camera and add it to stubs_entry_2.s)
Code: [Select]
extern void _LogPrintf(int id,const char *fmt,int a,int b, int c, int d);
void LogPrintf(const char *fmt, int a,int b, int c,int d)
{
_LogPrintf(0x120,fmt,a,b,c,d);
}
Then you can call LogPrintf(...) with up to 5 arguments. *do not* make a prototype for LogPrintf in the files you call it from.

LogPrintf goes to the camera log. This is a buffer of recent log entries the camera writes all kinds of stuff to already. If the camera crashes, recent camera log entries are included in the romlog. Otherwise, you will not normally see them. You can also get them to a file, using ShowCameraLog and uart redirection. Note that uart redirection doesn't exist on older cameras (most if not all vxworks).
Don't forget what the H stands for.

Re: undefined reference to puts?
« Reply #2 on: 15 / June / 2011, 12:28:59 »
OK, I might play with that when I get the chance.

Do you have any idea why the function never works? Nothing ever appears to be written to the LOGS directory.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal