473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Link C++ object with C object

Hi All,

I've compiled a cpp file with g++ without linking it and got an object
file.
Then I've compiled a C file with gcc and got an object file too.
Now if I try to link it to an executable (the main method is in the C
object) the linker complains about not finding the symbol for a
function declared in the C++ object.
Somebody told me that the two compilers use different symbol names for
the same function names.
He said also it would exist something like a "export this function as
C style" keyword but I didn't find anything.
Could somebody help me with this?

bye!
Dominik
Jul 22 '05 #1
3 1653

"Dominik Werder" <dw*****@gmx.net> wrote in message
news:31**************************@posting.google.c om...
Hi All,

I've compiled a cpp file with g++ without linking it and got an object
file.
Then I've compiled a C file with gcc and got an object file too.
Now if I try to link it to an executable (the main method is in the C
object) the linker complains about not finding the symbol for a
function declared in the C++ object.
Somebody told me that the two compilers use different symbol names for
the same function names.
He said also it would exist something like a "export this function as
C style" keyword but I didn't find anything.
Could somebody help me with this?

bye!
Dominik


In your C++ code

extern "C" int my_function()
{
...
}

john
Jul 22 '05 #2
On 9 Sep 2004 03:05:06 -0700 in comp.lang.c++, dw*****@gmx.net (Dominik
Werder) wrote,
Hi All,

I've compiled a cpp file with g++ without linking it and got an object
file.
Then I've compiled a C file with gcc and got an object file too.
Now if I try to link it to an executable (the main method is in the C
object)
No, that won't work, main must be in the C++ part.
the linker complains about not finding the symbol for a
function declared in the C++ object.
Somebody told me that the two compilers use different symbol names for
the same function names.
You must use a compiler or pair of compilers that explicitly support C
and C++ comparability. I guess that gcc would do that.
He said also it would exist something like a "export this function as
C style" keyword but I didn't find anything.


Yes, of course you need that part most.

This issue is covered in Marshall Cline's C++ FAQ. See section
"[32] How to mix C and C++"It is always good to check the FAQ before
posting. You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/

Jul 22 '05 #3
In article <31**************************@posting.google.com >,
Dominik Werder <dw*****@gmx.net> wrote:
I've compiled a cpp file with g++ without linking it and got an object
file.
Then I've compiled a C file with gcc and got an object file too.
Now if I try to link it to an executable (the main method is in the C
object) the linker complains about not finding the symbol for a
function declared in the C++ object.
Somebody told me that the two compilers use different symbol names for
the same function names.
He said also it would exist something like a "export this function as
C style" keyword but I didn't find anything.
Could somebody help me with this?


Check out http://www.comeaucomputing.com/techtalk/#externc
--
Greg Comeau / Comeau C++ 4.3.3, for C++03 core language support
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Murat Tasan | last post by:
i'm having trouble with some links using javadoc... basically, here is the example: {@link List}. {@link List#set(int, Object) List.set}. i'll run javadoc, but only the first link shows up....
4
by: Newbie | last post by:
Is it possible to set up an event handler or something else so that when *any* link on the page is clicked it 'fires-up', executes some JS and then continues to process the link that was clicked?...
6
by: juglesh | last post by:
hello, I just want to be able to use a keypress to do the same as clicking a link. such as will 'click' a certain link, while will 'click' a different link. thanks for your time, juglesh ...
13
by: Derek | last post by:
As I understand it there is a good amount of link compatibility among C compilers. For example, I can compile main.c with GCC and func.c with Sun One and link the objects using either linker (GNU...
3
by: Erik Cedergren (ecgn) | last post by:
I have been trying to get access to the details of a shell link (.LNK shortcut), but no matter what I do I never get the data I need. The basic thought behind the application is to drop a file or...
14
by: Steve McLellan | last post by:
Hi, Sorry to repost, but this is becoming aggravating, and causing me a lot of wasted time. I've got a reasonably large mixed C++ project, and after a number of builds (but not a constant...
4
by: zoookapi | last post by:
I'm attempting to dynamically add a link so I can take a mouseover action on it and am having problems in Safari (this works fine in Firefox and IE (Windows version of IE)). When I add the img...
2
by: mcraven.2 | last post by:
How do you send a browser to a link when a command is given? I've tried using Java Server Pages <jsp:forward /command but that doesn't change the link in the address bar and some other problems...
26
by: Nospam | last post by:
I am trying to open a link in a new template window : <a onclick="windowopen('example.html','example');return false;" href="http://www.example.com" target="_blank"example link</a> such that...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.