Undefined reference - General Discussion and Assistance - CHDK Forum

Undefined reference

  • 21 Replies
  • 8314 Views
Undefined reference
« on: 14 / April / 2014, 08:41:19 »
Advertisements
Hi,

today I wanted to create an own c-file where I can put some of my own functions for testing etc..
But during compilation I get following error:

main.c:(.text+0x262): undefined reference to `mb_test'

What I did:ยด

1. I created a mb.h file:

Code: [Select]
#ifndef MB_H_
#define MB_H_

void mb_test(int var1);

#endif /* MB_H_ */

2. I created mb.c file:

Code: [Select]
#include "mb.h"

void mb_test(int var1)
{
  // todo
}

3. I included the mb.h into main.c:

Code: [Select]
#include "platform.h"
#include "stdlib.h"
#include "core.h"
#include "conf.h"
#include "gui.h"
#include "gui_draw.h"
#include "histogram.h"
#include "raw.h"
#include "console.h"
#include "shooting.h"

#include "edgeoverlay.h"
#include "module_load.h"

#include "mb.h" // mrBurns

4. I called mb_test(1) from main.c:

Code: [Select]
   ...
  shooting_init();

   // mrBurns test
   mb_test(1);
   // mrBurns test

   while (1)
   ...

5. I compiled the code

Two question here:

1. Why I get this compiler error?

2. What is the right place to put some code for testing e.g. read third terminal of battery, read usb pulses, pulse LEDs etc.. I mean just for testing the code and do some measurements with oscilloscope. I want to create some code which is immediatley executed after the cam starts.

Thanks a lot!

   

2 x IXUS 860IS 100c
2 x Powershot S110 103a

Re: Undefined reference
« Reply #1 on: 14 / April / 2014, 10:08:49 »
You have to ensure your function is compiled.
In SDM, if the function was located in  \core\ you would add it to the list of object files in Makefile.
In CHDK, the core Makefile is handling the already created libraries, such as libcore.a.
So, find out where that library is compiled.

Re: Undefined reference
« Reply #2 on: 14 / April / 2014, 10:28:17 »
Hi Microfunguy,

thanks for reply, but sorry I am not familiar with the CHDK makefile. I still have to learn.
Can someone please show me some more detailed steps how to get this working?

And I also need an idea where is the best place to put some testing code, as mentioned in my 1st post under 2.

Thanks a lot!
2 x IXUS 860IS 100c
2 x Powershot S110 103a

Re: Undefined reference
« Reply #3 on: 14 / April / 2014, 10:57:35 »
Can someone please show me some more detailed steps how to get this working?
Try using grep -r main.c to get some idea of how the whole CHDK build goes together.

Quote
And I also need an idea where is the best place to put some testing code, as mentioned in my 1st post under 2.
Add the file(s) to  chdk/core and include using what you learn using the method above.   Or just edit your test code into an existing file.
Ported :   A1200    SD940   G10    Powershot N    G16


Re: Undefined reference
« Reply #4 on: 14 / April / 2014, 11:09:07 »
I am not familiar with the CHDK makefile.

Who is, apart from those who have closely followed the eternal growth of the code.

Look at folder 'lib' and its Makefile.

Change 'OBJS+= usb_input.o usb_module.o usb_remote.o autoiso.o' to 'OBJS+= usb_input.o usb_module.o usb_remote.o autoiso.o mb_test.o'

That will ensure your 'c' code is compile into an object file and the object file will be added to the libcore.a archive (library).

Do you want your function to run once.
For example, and a bit of a hack, just once after taking a photo.

What information do you want to display ?

Re: Undefined reference
« Reply #5 on: 14 / April / 2014, 19:26:06 »
Look at folder 'lib' and its Makefile.
Actually, it's lib/core/Makefile for the current stable & dev trunks.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Undefined reference
« Reply #6 on: 15 / April / 2014, 02:46:10 »
Hi waterwingz and Microfunguy,

thanks for your help I could compile now. For anybody who is interested:

Quote
Change 'OBJS+= usb_input.o usb_module.o usb_remote.o autoiso.o' to 'OBJS+= usb_input.o usb_module.o usb_remote.o autoiso.o mb_test.o'

in my case must be:

Quote
Change 'OBJS+= usb_input.o usb_module.o usb_remote.o autoiso.o' to 'OBJS+= usb_input.o usb_module.o usb_remote.o autoiso.o mb.o'

because the file I created was mb.c not mb_test.c (mb_test was the function name).

Anyway, thanks to both of you that worked now.

Quote
Try using grep -r main.c to get some idea of how the whole CHDK build goes together.

Unfortunately I could not try that because I am on Windows 7 and there grep does not exist. :-(
(may I should better switch to linux ubuntu?)

Quote
Do you want your function to run once.

Yes, at least in the beginning. I want to develop the communication from microcontroller to S110 via the batterie middle terminal. Further I want to test how fast I can send pulses to it and may some feedback sent from S110 back to microcontroller via the WiFi-LED.
2 x IXUS 860IS 100c
2 x Powershot S110 103a

Re: Undefined reference
« Reply #7 on: 15 / April / 2014, 05:02:40 »
In file main.c, look at function core_spytask().
This is a CHDK task created in boot.c :-

_CreateTask("SpyTask", 0x19, 0x2000, spytask, 0);

After booting, that task enters an endless 'while' loop and yields processor time every 20 msec (msleep(20)).
It updates the gui and amongst other things it checks if 'raw_data_available' is true.
That flag is set by function core_rawdata_available() which is called by capt_seq_hook_raw_here() in \generic\capt_seq.c.

(That file is included in the \platform\sub\capt_seq.c).

That flag is signalling that the raw sensor data is available and the data can be modified by CHDK before passing-on to Canon firmware for Canon jpg/raw saving (and CHDK raw saving).

So, spytask() jumps to raw_process() and when it has finished calls function hook_raw_save_complete() in \generic\capt_seq.c to indicate the Canon capture task can proceed.

In raw_process() add a call to your function.
In your function add play_sound(5);
If you do not include your header, it will compile but you will get a warning.

Now, after you take a photo you will get a nasty sound !


Re: Undefined reference
« Reply #8 on: 15 / April / 2014, 07:03:20 »
Hi Microfunguy,

thanks for reply, this gives me a lot helpful information!

Lets say I have a function read_batt_mid_terminal() can I call that directly out of core_spytask?
I want to trigger an action if middle battery terminal changes. So I need a function which must read middle terminal of the battery at any time and in rec and play mode I guess inside core_spytask() it could be the right place?

something like this:

Quote
...
while(1)
{
  ...
  if (camera_info.perf.md_af_tuning)
  {
      sprintf(osd_buf, "MD last %-4d min %-4d max %-4d avg %-4d",
          camera_info.perf.af_led.last, camera_info.perf.af_led.min, camera_info.perf.af_led.max,
          (camera_info.perf.af_led.count>0)?camera_info.perf.af_led.sum/camera_info.perf.af_led.count:0);
            draw_txt_string(1, i++, osd_buf, conf.osd_color);
  }

  read_batt_mid_terminal(); // mrBurns
 
  // Process async module unload requests
  module_tick_unloader();
 
  msleep(20);
  chdk_started_flag=1;
}

2 x IXUS 860IS 100c
2 x Powershot S110 103a

Re: Undefined reference
« Reply #9 on: 15 / April / 2014, 08:39:22 »
Unfortunately I could not try that because I am on Windows 7 and there grep does not exist. :-(
(may I should better switch to linux ubuntu?)
Actually, if you are planning on doing a serious amount of coding,  there is  this : http://www.cygwin.com/

Alternatively, if your right hand must remain glued to your mouse, I'd recommend :
http://www.wingrep.com/  or http://stefanstools.sourceforge.net/grepWin.html

I want to develop the communication from microcontroller to S110 via the batterie middle terminal.

FYI - if you need some tips, there is a USB remote patch file that replaces the use of  USB port with the battery middle terminal here :
    Battery third (temp) terminal as multipurpose analogue input
This frees the USB port for ptp communications.  The patch will no longer apply cleanly against the current trunk (too many changes since I posted it) but now that the HP timer stuff is in the dev trunk,  I'll add some GUI configuration code to it and submit for inclusion in the svn sometime in the next week or so. 

I have some camera Lua script code under test that implements high speed communications with my Arduino clone using the HP timer stuff - I'll also test with the A/D channel patch.
Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal