Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Linking a C...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 43301 of 47561
Post > Topic >>

Re: Linking a C program to a C++ library which uses STL

by Joe.pHsiao@[EMAIL PROTECTED] Feb 13, 2008 at 03:21 PM

Hi,

I finally understand the whole thing.
I was having a wrong impression that I could make a C program call a C+
+ library if g++ is used in the command, even without extern "C" in
the library header.
So I thought extern "C" is used for situations where gcc is used in
the compile command.

But I was wrong.
If there's no extern "C" in the library head file, trying to compile a
C main program (use g++) would give you undefined reference errors.
To get rid of those errors, include extern "C" in the head file.

Like tragomaskhalos said, use #ifdef __cplusplus in the head file, so
the same head file could be used for building the library and for
building the main program.
And the last step is to use g++ to compile the main program. gcc won't
work.
 




 1 Posts in Topic:
Re: Linking a C program to a C++ library which uses STL
Joe.pHsiao@[EMAIL PROTECT  2008-02-13 15:21:47 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 3:41:29 CDT 2008.