?
Solved

About map..

Posted on 2002-07-30
6
Medium Priority
?
185 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
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!

 
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

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.

Question has a verified solution.

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

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 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