Author Topic: undefined reference message  (Read 10067 times)

Offline jank9201

  • Multiple posting newcomer
  • *
  • Posts: 14
undefined reference message
« 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?


Offline jarod42

  • Multiple posting newcomer
  • *
  • Posts: 87
Re: undefined reference message
« Reply #1 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.

Offline jank9201

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: undefined reference message
« Reply #2 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 ?

Offline Freem

  • Almost regular
  • **
  • Posts: 219
Re: undefined reference message
« Reply #3 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?

Offline jank9201

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: undefined reference message
« Reply #4 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.