?
Solved

About map..

Posted on 2002-07-30
6
Medium Priority
?
186 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
[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
6 Comments
 
LVL 3

Accepted Solution

by:
MDarling earned 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

649 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