Solved

Accessing C++ Compiled libraries.

Posted on 2003-10-23
3
163 Views
Last Modified: 2010-04-15
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
Comment
Question by:aolXFT
3 Comments
 
LVL 5

Accepted Solution

by:
mtmike earned 100 total points
Comment Utility
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
 
LVL 11

Expert Comment

by:cup
Comment Utility
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
 
LVL 6

Author Comment

by:aolXFT
Comment Utility
So that's what extern "C" does, thanks mtmike.

Accepting answer now.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now