10

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)
  ^

2 Answers 2

12

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I tried (as below), but I must be doing something wrong.
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
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.
can also put the function into anonymous namespace
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++?

1 Comment

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);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.