By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,411 Members | 1,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,411 IT Pros & Developers. It's quick & easy.

C/C++ linkage issues

P: n/a
I am implementing a library that can be linked in with C as well as C++
code. Obviously, the library API is functional, but in my
implementation I am using STL. Because of this, my code is compiled
using a C++ compiler (gcc version 3.3.1). Given the differences in the
way C and C++ code gets linked in, what should I do to ensure that the
C code that links in the library does not give any linker error?

Thanks,
Gus

Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hello Generic, your question is off-topic in all the newsgroups you posted,
since it isn't about Standard C++, Standard C, and not about D either.

Generic Usenet Account wrote:
I am implementing a library that can be linked in with C as well as C++
code. Obviously, the library API is functional,
What do you mean by that? It works?
but in my implementation I am using STL. Because of this, my code is
compiled using a C++ compiler (gcc version 3.3.1). Given the differences
in the way C and C++ code gets linked in, what should I do to ensure that
the C code that links in the library does not give any linker error?


Link it with g++.

xpost&f'up2 gnu.g++.help

Jul 23 '05 #2

P: n/a
Generic Usenet Account wrote:
I am implementing a library that can be linked in with C as well as C++
code. Obviously, the library API is functional, but in my
implementation I am using STL. Because of this, my code is compiled
using a C++ compiler (gcc version 3.3.1). Given the differences in the
way C and C++ code gets linked in, what should I do to ensure that the
C code that links in the library does not give any linker error?


Well, Generic, section 32 of the FAQ for comp.lang.c++
covers those issues quite well. You can read it at:

http://www.parashift.com/c++-faq-lit...c-and-cpp.html

I've had to struggle with those issues myself a lot at work
(the software there is a Frankenstein of C and C++) but I
found the link above quite helpful.

--
Cheers,
Robbie Hatley
Tustin, CA, USA
email: lonewolfintj at pacbell dot net
web: home dot pacbell dot net slant earnur slant

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 23 '05 #3

P: n/a
Rolf Magnus wrote:
Hello Generic, your question is off-topic in all the newsgroups you posted,
since it isn't about Standard C++, Standard C, and not about D either.

I DISAGREE. The whole topic pertaining to the interworking between C
and C++ code is of great interest to an entire community of
programmers. IMHO it is not OT for comp.lang.c or comp.lang.c++. As
far as comp.sources.d goes, any posting that pertains to source code
falls within its realm.
code. Obviously, the library API is functional,


What do you mean by that? It works?


I though that my statement was pretty obvious. If the API needs to be
invoked by C as well as C++, the API cannot be defined in terms of
public methods on a class. It has to be defined in terms of
"free-standing" functions.
xpost&f'up2 gnu.g++.help


I don't know what makes you feel that this topic is more relevant to
the gnu.g++.help newsgroup. My query was general, and not pertaining
to g++. I volunteered the compiler version, because often times fellow
posters have asked for this kind of information in their response. I
submit that the issue of interoperability between C and C++ code has
less to do with the compiler that is being used and more to do with the
difference in C and C++ linkage. I am therefore "undoing" the f'up.

Jul 23 '05 #4

P: n/a
Generic Usenet Account wrote:
Rolf Magnus wrote:
Hello Generic, your question is off-topic in all the newsgroups you posted,
since it isn't about Standard C++, Standard C, and not about D either.
I DISAGREE. The whole topic pertaining to the interworking between C
and C++ code is of great interest to an entire community of
programmers.


Whether one prefers Chinese food to Italian food is of great interest to
an entire community of programmers. You are in error.
IMHO it is not OT for comp.lang.c or comp.lang.c++.


Your ill-informed opinion has nothing to do with the question.
Jul 23 '05 #5

P: n/a
Generic Usenet Account wrote:
Rolf Magnus wrote:
Hello Generic, your question is off-topic in all the newsgroups you
posted, since it isn't about Standard C++, Standard C, and not about D
either.

I DISAGREE. The whole topic pertaining to the interworking between C
and C++ code is of great interest to an entire community of
programmers.


comp.lang.c and comp.lang.c++ are about the C resp. C++ language as defined
by the ISO standards. Those don't define how the code is linked or how code
compiled from different languages interacts, and so problems you might find
when linking C and C++ code together are mostly (*) platform/compiler
specific, which means that such questions are best dealt with in a
platform/compiler specific programming newsgroup.

(*) One thing that the C++ standard does mention (but not define) is "C"
linkage. When writing a function in C++ that is supposed to be called from
a C function, you should declare it as extern "C". However, since there is
no specific linkage defined by the C standard, this will only work if the C
compiler actually uses the same linkage. For gcc/g++ (and here we're
compiler specific again), this is true.
IMHO it is not OT for comp.lang.c or comp.lang.c++. As
far as comp.sources.d goes, any posting that pertains to source code
falls within its realm.
It seems to me that postings that ask for or offer source code (neither of
which you were doing) are on-topic in comp.sources.d, but I haven't looked
well enough to judge that. I was wrong to assume that it's about the
programming language D, so now I dare only speak for comp.lang.c and
comp.lang.c++.
> code. Obviously, the library API is functional,


What do you mean by that? It works?


I though that my statement was pretty obvious. If the API needs to be
invoked by C as well as C++, the API cannot be defined in terms of
public methods on a class. It has to be defined in terms of
"free-standing" functions.


Ah. I see.
xpost&f'up2 gnu.g++.help


I don't know what makes you feel that this topic is more relevant to
the gnu.g++.help newsgroup. My query was general, and not pertaining
to g++.


However, the answers are mostly compiler specific, like mine that adviced
you to link everything with g++.
I submit that the issue of interoperability between C and C++ code has
less to do with the compiler that is being used and more to do with the
difference in C and C++ linkage.
The problem is just that C and C++ don't define a specific linkage. The
compiler does that.
I am therefore "undoing" the f'up.


I won't fight with you over f'ups. ;-)

Jul 23 '05 #6

P: n/a
On Tue, 14 Jun 2005 12:34:23 -0700, Generic Usenet Account wrote:
I am implementing a library that can be linked in with C as well as C++
code. Obviously, the library API is functional, but in my
implementation I am using STL. Because of this, my code is compiled
using a C++ compiler (gcc version 3.3.1). Given the differences in the
way C and C++ code gets linked in, what should I do to ensure that the
C code that links in the library does not give any linker error?


C has no facilities for inter-language linking, C++ has extern "C". Your
best bet would probably be to discuss that in comp.lang.c++ only.
Followups set.

Lawrence
Jul 23 '05 #7

P: n/a
Generic Usenet Account wrote:
Rolf Magnus wrote:
Hello Generic, your question is off-topic in all the newsgroups
you posted, since it isn't about Standard C++, Standard C, and
not about D either.
I DISAGREE. The whole topic pertaining to the interworking
between C and C++ code is of great interest to an entire community
of programmers. IMHO it is not OT for comp.lang.c or
comp.lang.c++. As far as comp.sources.d goes, any posting that
pertains to source code falls within its realm.

.... snip ...
I don't know what makes you feel that this topic is more relevant
to the gnu.g++.help newsgroup. My query was general, and not
pertaining to g++. I volunteered the compiler version, because
often times fellow posters have asked for this kind of information
in their response. I submit that the issue of interoperability
between C and C++ code has less to do with the compiler that is
being used and more to do with the difference in C and C++ linkage.
I am therefore "undoing" the f'up.


The .lang groups deal with the language, not the nitty gritty of
moving the code into suitable places on end machines. What makes
you think you can walk in from the street and postulate what is and
is not on-topic in these groups? F'ups set.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.