• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

Accessing C++ Compiled libraries.

Hi

I was just wondering if there was anyway to access C++ Libraries through C.

I know that C cannot support the objects that C++ supports, but lets say for example there was a function written in C++ like

int myfunc(int num){
  myClass myclass();
  myclass.printNum();
  return myclass.getNum();
}

Although this serves no useful purpose, I was just wondering, that if you wrapped object handlers up in functions, like in the above, could you use them in C.

What made me curious about this, was that Python is written in C(I believe), and it can Handle QT stuff(which is written in C++).

 
0
aolXFT
Asked:
aolXFT
1 Solution
 
mtmikeCommented:
You can write

extern "C" int myfunc(int num){
  myClass myclass();
  myclass.printNum();
  return myclass.getNum();
}

To make the function callable from C code.

The problem is that C++ allows functions with the same name but different argument types.
0
 
cupCommented:
To add to mtmike's answer, extern "C" tells the compiler not to mangle the names so that the names can be resolved during the link process.
0
 
aolXFTAuthor Commented:
So that's what extern "C" does, thanks mtmike.

Accepting answer now.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now