473,387 Members | 1,721 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,387 software developers and data experts.

C/C++ linkage issues

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
7 1949
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: qazmlp | last post by:
const has internal linkage in C++, but external linkage in C. Am I right ? But, linker reports multiply-defined error if the following header is included in multiple .cpp files. //...
20
by: Grumble | last post by:
Hello everyone, As far as I understand, the 'inline' keyword is a hint for the compiler to consider the function in question as a candidate for inlining, yes? What happens when a function with...
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
19
by: J. J. Farrell | last post by:
After many years of dealing with definition and linkage issues in ways that I know to be safe, I've decided it's time to try to understand this area properly. Consider a header file with the file...
6
by: Generic Usenet Account | last post by:
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...
3
by: al.cpwn | last post by:
do static and inline functions or members have internal linkage? I have been reading this newsgroup on google and found conflicting ideas. Can someone please help me understand why in some places...
13
by: fctk | last post by:
source: http://rm-f.net/~orange/devel/specifications/c89-draft.html#3.1.2.2 there are two passages in this paragraph i can't fully understand: 1) "If the declaration of an identifier for an...
12
by: Bit byte | last post by:
I have an application written in C (actually PostgreSQL). The application appears to have been built using the Mingw set of tools (mingw compiler tools). I want to write an extension library...
6
by: The Architect | last post by:
Hi, If I have the same symbol in the .data section of 2 obj files, LD gives a multiple declaration error on linking? Would like to know the reason for this (diab only issues a warning) Also...
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: 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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.