Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: jank9201 on September 27, 2012, 09:15:47 am

Title: undefined reference message
Post by: jank9201 on September 27, 2012, 09:15:47 am
   Recently, I built a large dynamic library using codeblocks, the library is cpp source file, and it depends on another library which  is also cpp source file, at the linking step, the codeblocks showed me a message " undefined reference to ...", It mean that the linker could not found some functions which are in another library, but I searched and read the source file, the corresponding functions was fine and perfect.

  So I picked up a function and modified it , and rebuilt, I found if I add extern "C" keywards to the head of the function, the undefined reference message was dispeared, for example:

   if the function is like this:
EAIO_API  bool Create(const char16_t* pDirectory), the undefined reference message will appear.

   if the function is modified to this:
extern "C" EAIO_API  bool Create(const char16_t* pDirectory); the undefined reference message will dispear.

  how this happens? did I forgot to add something? Can anybody help me?

Title: Re: undefined reference message
Post by: jarod42 on September 27, 2012, 10:09:17 am
unrelated to CB.

C++ use a name mangling
and extern "C" is a way to export symbol.
Title: Re: undefined reference message
Post by: jank9201 on September 27, 2012, 01:45:35 pm
  I know it is name mangling problem, the two libraries are all cpp sources, and the linked library which also built using codelbocks is a c++ library.
     my meaning is that when I build the last library, why the linker intend to find the c mangled function not c++ mangled function, did I forgot to add some options, what should I add in the following: codblocks buid->project build option->other options ?
Title: Re: undefined reference message
Post by: Freem on September 27, 2012, 02:04:50 pm
Maybe an extension problem? I am not sure, but I think gcc (or C::B?) recognize language on the base of file extension?
Title: Re: undefined reference message
Post by: jank9201 on September 28, 2012, 02:54:31 am
  I have checked the file with the linked function source code, its extension is cpp, so it seems that it is not an extension problem.