This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Help! extern C linkage for thread entry functions


Hi.

> I'm working on the EB40A board and my application is
> in C++. Mine is a multi file application and I use a
> common header file and include it in all my cc files.
> I do have a #ifndef ... #define directive in my header
> file to avoid multiple declarations. 
> 
> But still when I try to make it all, I get multiple
> reference errors. But if the application is in C, the
> whole thing compiles and works fine. 
> 
> I kind of figured that it is somewhat related to
> declaring the thread entry functions within the extern
> C block. But I'm not sure. How do I declare the thread
> entry functions in C++. i.e if my thread function is
> "Read_FIFO"  can I say
> 
> extern "C"  {
> 	cyg_thread_entry_t Read_FIFO;
> }
> 
> or extern "C"  {
> 	void Read_FIFO(cyg_addrword_t );
> }
> 
> In the first case I'm getting the multiple definition
> erros, and in the second case I'm getting a conflict
> with the previous declaration of
> cyg_thread_entry_t Read_FIFO.

Well, your situation is a little unclear (at least to me); where's the
"thread entry" code and where from it's referenced? I assume you are
mixing C and C++ files, as you use 'extern "C"'.

I suppose you have a "thread entry" function written in C++ file, and
you are trying to call the function cyg_thread_create() (with that
"thread entry" function as an argument) from a C file.
If that is the case, you should have:
1) in C file:
   extern cyg_thread_entry_t Read_FIFO;
2) in C++ file (this is, of course, meaningless example implementation):
   extern "C" void Read_FIFO(cyg_addrword_t arg){
      int *foo = (int *)arg;
      cyg_mutex_lock(&thr_mutex);
      if(fifo_empty){
         *foo = 0;
      }else{
      ...
      }
      cyg_mutex_unlock(&thr_mutex);
      ...
   }

If the situation is "inverse", i.e. referencing  a "thread entry"
function from C++ file, but the "thread entry" function itself is
implemented in C file, than in C++ file you should have:
   extern "C" {
      cyg_thread_entry_t Read_FIFO;
   }
before referencing it, and normal implementation of Read_FIFO() in a C
file.

And for the third case, if you want to have declarations in a header
file included from both C and C++ files, then you might consider using
something like this:
   #ifdef __cplusplus
   extern "C" {
   #endif
      cyg_thread_entry_t Read_FIFO;
   #ifdef __cplusplus
   }
   #endif

Hope that helps a bit.
Not actually ecos-related question, nor answer... ;-)


Regards,
Ivan.



-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]