473,466 Members | 1,430 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

unable to link between c and c++

1 New Member
I have a class whose member I need to access in c prog.
I have defined the class object as extern.

when I tried to access the class member in c it says undefine reference.

where as I'm able to access the same class members in different places.
please help me
Aug 23 '07 #1
2 1372
Banfa
9,065 Recognized Expert Moderator Expert
You will not be able to access any class members from C because a class is a C++ construct that C is unaware of.

What you can do is declare functions with C naming convention in a C++ file

Header
Expand|Select|Wrap|Line Numbers
  1. #ifdef __cplusplus
  2. extern "C" {
  3. #endif
  4.  
  5. extern void MyFunction(void);
  6.  
  7. #ifdef __cplusplus
  8. }
  9. #endif
  10.  
cpp code
Expand|Select|Wrap|Line Numbers
  1. #include "header"
  2.  
  3. void MyFunction(void)
  4. {
  5.     // Code here that accesses the class
  6. }
  7.  
c code
Expand|Select|Wrap|Line Numbers
  1. #include "header"
  2.  
  3. void SomeFunction(void)
  4. {
  5.     MyFunction();
  6. }
  7.  
This enables C code to call into C++ modules, you then put the C++ code (code accessing classes for instance) inside the function with the C naming convention.
Aug 23 '07 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
Continuing Banfa's reply, you can write a function (extern "C") in C++ that calls the member function of the class and then you can call this function from C.

These are called buck-passer functions and are quite common.
Aug 24 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: MichaelF | last post by:
I've embedded a RealPlayer window in a page, and am unable to get mouse clicks. The clip plays, but clicks are ignored. I'm running IE5.5 on Win2k, with the following code: <embed...
1
by: mariox | last post by:
Hi everybody, compiling a program I receive this message: Fatal: Unable to open file 'WS2_32.OBJ' Object file "programName.OBJ" is created, but I can't link it. Anyone can help me, please?...
0
by: jrainey | last post by:
I recieve "LINK : fatal error LNK1171: unable to load ole32.dll" when compliling/linking my project some times Any one else have this problem. The file is in the right place and the output window...
22
by: EP | last post by:
When running my asp.net hosting service (asp.net without IIS), on server 2003 with IIS not installed, I get the following when trying to process a request. "System.DllNotFoundException: Unable to...
8
by: Carlos Ojea Castro | last post by:
Hello: I'm trying to use kylix3 and postgresql 7.4.1. My distro was Debian Woody, kernel 2.20. I make the link /usr/local/pgsql/lib/libpq.so pointing to libpq.so.2.2 and connection with my...
1
by: geetu | last post by:
hi to all.. pls help me its urgent.. i m unable to understand the exact answer .. tell me step to be carried to set libraries or directory path so that i can execute a simple program everytime i...
1
by: shrn4E | last post by:
i have hosted a website in window 2003 server. when i try to browse the website from window XP Pro the website unable to load the ASPX link. it show the link in a TEXT format which not able to link...
1
by: DR | last post by:
Unable to start TSQL Debugging. Could not attach to SQL Server Process on 'srvname'. The RPC server is unavailable. I get this error when I try to run a SQL Server Project with a CLR stored...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
7
freddieMaize
by: freddieMaize | last post by:
Hi, my first day in designing. Since I’m not a very good designer I tried copying a template from the net. Below is my problem. I saved the below web page,...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.