Solved

About map..

Posted on 2002-07-30
6
178 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

707 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

12 Experts available now in Live!

Get 1:1 Help Now