Solved

Accessing C++ Compiled libraries.

Posted on 2003-10-23
3
168 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

Suggested Solutions

Title # Comments Views Activity
negation in C function 14 178
why "." vs "->" 23 124
IIS Log files on Exchange 2013 server 6 326
How to translate this 2-line while loop into C from Perl? 8 165
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

734 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