linking c++ code with c library

J

junky_fellow

Guys,

Can we link a c++ code with a library written in C ?

Can both static and dynamic linking be done ?

thanks.
 
F

Frank

Guys,

  Can we link a c++ code with a library written in C  ?

Can both static and dynamic linking be done ?

thanks.

I don't think dynamic linking means anything in C.
 
K

Keith Thompson

Can we link a c++ code with a library written in C ?

Can both static and dynamic linking be done ?

Probably.

C++ has language features designed for interfacing between the two
languages. C does not. So you're more likely to get information from
comp.lang.c++ -- but first take a look at section 32 of the "C++ FAQ
Lite", <http://www.parashift.com/c++-faq-lite/>.

Details of how to accomplish this are likely to be system- or
compiler-specific.
 
N

Nick Keighley

but, dont you think you need to know this ?

ok, dynamic and static linking are not mentioned in the C standard.
Hence dynamic linking doesn't mean anything in the standard C
language. Implementations of C may implement these features.
 
J

jacob navia

Nick Keighley wrote:
ok, dynamic and static linking are not mentioned in the C standard.
Hence dynamic linking doesn't mean anything in the standard C
language. Implementations of C may implement these features.


This is just nonsense!

Linking is mentioned EXPLICITLY in the C Standard

See the C standard paragraph 5.1.1.2
"Translation phases".

Translation phase 8 (the final step) is
described as follows:

<quote>
All external object and function references are resolved. Library
components are linked to satisfy external references to functions and
objects not defined in the current translation. All such translator
output is collected into a program image which contains information
needed for execution in its execution environment
<end quote>

Linkers are further mentioned in an example, or referred to when
the identifiers contain wide characters.

Before spewing nonsense please READ the standard you are quoting.

jacob
 
P

Paul N

This is just nonsense!

Linking is mentioned EXPLICITLY in the C Standard

See the C standard paragraph 5.1.1.2
"Translation phases".

Translation phase 8 (the final step) is
described as follows:

<quote>
All external object and function references are resolved. Library
components are linked to satisfy external references to functions and
objects not defined in the current translation. All such translator
output is collected into a program image which contains information
needed for execution in its execution environment
<end quote>

Linkers are further mentioned in an example, or referred to when
the identifiers contain wide characters.

Before spewing nonsense please READ the standard you are quoting.

I think he means that the C standard does not mention dynamic linking
or static linking (whatever they are). The draft standard only uses
the word "dynamic" a few times, none of which relate to linking, and
doesn't include the phrase "static linking".

The passage you've quoted doesn't use the words "dynamic" or "static"
or compare two different types of linking.
 
J

junky_fellow

I think he means that the C standard does not mention dynamic linking
or static linking (whatever they are). The draft standard only uses
the word "dynamic" a few times, none of which relate to linking, and
doesn't include the phrase "static linking".

The passage you've quoted doesn't use the words "dynamic" or "static"
or compare two different types of linking.- Hide quoted text -

- Show quoted text -

Thats fine. C Standard may not mention everytning about dynamic or
static linking. But, as a programmer, I believe everyone must know
about it. Every C programer uses library at one or other time. Just
because is is not mentioned in the standard, we should not escape such
things.
 
F

Frank

Nick Keighley wrote:

  ok, dynamic and static linking are not mentioned in the C standard.


This is just nonsense!

Linking is mentioned EXPLICITLY in the C Standard

See the C standard paragraph 5.1.1.2
"Translation phases".

Translation phase 8 (the final step) is
described as follows:

<quote>
All external object and function references are resolved. Library
components are linked to satisfy external references to functions and
objects not defined in the current translation. All such translator
output is collected into a program image which contains information
needed for execution in its execution environment
<end quote>

Linkers are further mentioned in an example, or referred to when
the identifiers contain wide characters.

Before spewing nonsense please READ the standard you are quoting.

jacob

Would it make a difference to talk about dynamic loading instead of
linking?
 
K

Keith Thompson

Thats fine. C Standard may not mention everytning about dynamic or
static linking. But, as a programmer, I believe everyone must know
about it. Every C programer uses library at one or other time. Just
because is is not mentioned in the standard, we should not escape such
things.

Sure, anyone programming for a system that supports static and/or
dynamic linking should know something about them.

On the other hand, you can't program without a text editor.
That doesn't make text editors a good topic for this newsgroup.

Linking is likely to be an issue for any compiled language.
If something is equally applicable to C and to other languages,
that's a clue that comp.lang.c probably isn't the best place to
discuss it. That doesn't mean it's unimportant, merely that there
are better places to discuss it.
 
B

BartC

Keith Thompson said:
Sure, anyone programming for a system that supports static and/or
dynamic linking should know something about them.

On the other hand, you can't program without a text editor.
That doesn't make text editors a good topic for this newsgroup.

Linking is likely to be an issue for any compiled language.
If something is equally applicable to C and to other languages,
that's a clue that comp.lang.c probably isn't the best place to
discuss it. That doesn't mean it's unimportant, merely that there
are better places to discuss it.

Possibly. But little else is being discussed at the minute (traffic seems
about 2/3 down since start of the year), so why not?
 
K

Keith Thompson

BartC said:
Possibly. But little else is being discussed at the minute (traffic
seems about 2/3 down since start of the year), so why not?

Because, as I said, there are better places to discuss it.

Do you think the off-topic traffic will just go away when topical
traffic picks up again? (Please let's not have yet another topicality
flame-war; just consult the archives.)
 
J

jacob navia

Nick said:

Of course not. Both static and dynamic linking are part of the language
since they belong to the phase 8 of the program translation according
to the definition of C.

Both are, then, ON TOPIC here. Mr Keighly sterile contribution
(off topic off topic) is just a lack of understanding what
the language IS.

This kinds of "contributions" just increase the noise of this
group, like most of the posts of the so called "regulars".
 
J

jacob navia

Rui said:
Care to point out what those places might be?


Rui Maciel
Please understand that this group is here to discuss

(1) The prototype of main is int main(void)
(2) i=i++ is not correct
(3) Answer any homework your teacher may give you so
that no effort is done by you.

This group is NOT here to discuss:

(1) Anything interesting, related to software development and C
development in particular.
(2) Any real world discussion like about dynamic linking,
debuggers, etc.
(3) Any improvements to C as a language. You should use C++
since that's C future.
 
E

Eric Sosman

Rui said:
Care to point out what those places might be?

comp.lang.c++ for the C++ aspects, surely. And for the
system-specific linker machinery, comp.unix.programmer or
comp.os.ms-windows.something or comp.unix.aix or whatever.
 
B

BartC

Eric Sosman said:
comp.lang.c++ for the C++ aspects, surely.

Linking must surely be off-topic there too.
And for the
system-specific linker machinery,
comp.os.ms-windows.something

MS Windows provides a linker now? That's news.
comp.unix.programmer or ... or comp.unix.aix or whatever.

Same goes for Unix I suppose. Anyway the OP didn't even mention an OS, and
may not have wanted a answer for one compiler on one os using one linker and
on a single platform, but may have wanted a broader view.

On usenet, .c and .c++ groups sound like the best bet for coming across
someone who's already tackled the problem.
 
K

Keith Thompson

BartC said:
Linking must surely be off-topic there too.

C++ provides built-in features, particularly
extern "C"
for combining C and C++ code. C does not. I believe I mentioned
that in my initial response.

So yes, questions regarding extern "C" would surely be topical in
comp.lang.c++ -- assuming you've already tried and failed to find
the answers in the C++ FAQ.

As for static vs. dynamic linking, I don't believe C++ provides any
mechanism that distinguishes between the two. So it's not a language
issue, any more than vi vs. emacs is a language issue. You might as
well ask in comp.lang.fortran (no, that's not a serious suggestion).

[...]
 
S

Stephen Sprunk

Can we link a c++ code with a library written in C ?

That question is better addressed in comp.lang.c++.

<OT>
Yes, but the library's header file needs to surround any C function
declarations with extern "C" { ... } for a C++ compiler to know not to
mangle their function names. If the names are mangled, the linker won't
be able to match them up with the unmangled names in the C library.
Can both static and dynamic linking be done ?

The Standard does not address such things; that is an implementation detail.

<OT>
Yes, provided the implementation allows both static and dynamic linking
for both C and C++ objects.
</OT>

S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top