Solved

Accessing C++ Compiled libraries.

Posted on 2003-10-23
3
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
mtmike earned 100 total points
ID: 9610978
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
ID: 9612426
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
ID: 9615694
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

718 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