Author Topic: C++ project can not call C static library functions  (Read 4335 times)

Offline amit1947

  • Single posting newcomer
  • *
  • Posts: 3
C++ project can not call C static library functions
« on: December 04, 2008, 08:23:22 pm »
Hi everyone, I'm just getting started with Code::Blocks but I have some issues. I created a static library with C (.a extension) and I want to call these functions within another C++ project. When I try to build the C++ project I get an error in the Build Log : "undefined reference to 'HwOpen()' ". HwOpen() is a function in the static library.

I went into the C++ Project's build options and selected the correct lib.a file in the "Linker Settings" tab.

I know this process worked when I called the static library functions from a C project, but I think I need to do something else for the C++ project.

Thanks for any help!

Offline amit1947

  • Single posting newcomer
  • *
  • Posts: 3
Re: C++ project can not call C static library functions
« Reply #1 on: December 04, 2008, 08:36:39 pm »
I forgot to mention that I'm using Code::Blocks in Ubuntu Linux.

Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: C++ project can not call C static library functions
« Reply #2 on: December 04, 2008, 09:08:50 pm »
Hi,

search the web for "extern c"

Dje

Offline amit1947

  • Single posting newcomer
  • *
  • Posts: 3
Re: C++ project can not call C static library functions
« Reply #3 on: December 04, 2008, 09:11:22 pm »
Thanks for the help! That did it , I added

extern "C"{

function_prototypes();

}

to the C lib's header file and it works now.