9

I am stumped about the cause of this:

recorders/r5000device.cpp: In function ‘unsigned int r5000_device_tspacket_handler(unsigned char*, int, void*)’:
recorders/r5000device.cpp:34:14: warning: no previous declaration for ‘unsigned int r5000_device_tspacket_handler(unsigned char*, int, void*)’ [-Wmissing-declarations]
 unsigned int r5000_device_tspacket_handler(unsigned char *tspacket, int len, void *callback_data)
          ^
recorders/r5000device.cpp: In function ‘void r5000_msg(char*)’:
recorders/r5000device.cpp:44:6: warning: no previous declaration for ‘void r5000_msg(char*)’ [-Wmissing-declarations]
 void r5000_msg(char * msg)
  ^
Cœur
  • 37,241
  • 25
  • 195
  • 267
user3033518
  • 125
  • 1
  • 1
  • 6

2 Answers2

11

You have the compile flag -Wmissing-declarations set. The compiler wants to see declarations (prototypes - usually in headers) for all function. Just add the missing headers or declare the prototype at the top of the file.

egur
  • 7,830
  • 2
  • 27
  • 47
  • I tried (as below), but I must be doing something wrong. – user3033518 Nov 26 '13 at 23:35
  • 1
    Make sure you include the header file. If this function is local to the file, declare it as static. BTW the Intel compiler gives a similar warning – egur Nov 27 '13 at 06:26
  • Thanks egur. I solved it by putting in r5000device.h: `unsigned int r5000_device_tspacket_handler(unsigned char *tspacket, int len, void *callback_data); void r5000_msg(char*);' so you'd nailed it. It was a big hassle determining whether I needed #ifndef or some other dressing up, but it turns out I just needed the bare declarations. – user3033518 Nov 27 '13 at 18:04
  • can also put the function into anonymous namespace – ricab Jun 20 '17 at 22:57
0

Free functions in C++ need to be declared in a header file as well as defined in a .cpp file. How do you define a global function in C++?

Community
  • 1
  • 1
Tim Pierce
  • 5,514
  • 1
  • 15
  • 31
  • It doesn't work as your link says it should. In r5000device.h I put at the top: `#ifndef r5000_device_tspacket_handler #define r5000_device_tspacket_handler unsigned int r5000_device_tspacket_handler(unsigned char *tspacket, int len, void *callback_data); #endif` ... but it responds: `In file included from videosource.cpp:39:0: recorders/r5000device.h:9:15: error: expected unqualified-id before ‘unsigned’ unsigned int r5000_device_tspacket_handler(unsigned char *tspacket, int len, void *callback_data);` – user3033518 Nov 26 '13 at 23:26