Solved

About map..

Posted on 2002-07-30
6
181 Views
Last Modified: 2010-04-01
Hi Friends
       i have a problem... i have a file(say file1.cxx) in which i declare a map & through a function on this file say enter i can insert value in this map..now i want to call this function from another file having extension .c & wants to enter value in it from that file..but linker error comes .. how it can be possible..

bye
Jonmac
0
Comment
Question by:JonMac
6 Comments
 
LVL 3

Accepted Solution

by:
MDarling earned 50 total points
ID: 7187668
put

extern "C"

on the front of your function.

This will stop C++ name mangling and make it callable from your C file.
0
 
LVL 3

Expert Comment

by:MDarling
ID: 7187675
=== main.c ===

#include "myheader.h"

int main()
{
    map_insert("hello");
    map_insert("world");
    return 0;
}

=== header file ===

#ifndef myheader_h
#define myheader_h

#ifdef __cplusplus
extern "C" {
#endif

int map_insert(char* s);

#ifdef __cplusplus
};
#endif

#endif


=== C++ Source ===

#include "myheader.h"
#include <iostream>

using namespace std;

int map_insert(char* s)
{
    cerr << s << ' ';
    return 0;
}
0
 
LVL 30

Expert Comment

by:Axter
ID: 7188164
Which are you trying to do?

[1] Are you trying to access a function in a *.cxx file from a *.c file?

OR

[2] Are you trying to access a function in a *.c file from a *.cxx file?
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 30

Expert Comment

by:Axter
ID: 7207692
JonMac,
Did you forget this question?
0
 
LVL 11

Expert Comment

by:griessh
ID: 7439585
Dear

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "MDarling"

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7479729
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to understand recursion 12 224
Grammars for C C++ and java 1 122
max float value 3 39
How do i run a c++ file? 15 23
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

808 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