Oops...it looks like I accidentally deleted a { in the code below. Between
the extern statement and the first #include, there should be a { which is
closed by the } after the second #include. Sorry about that.

Austin Bingham

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of
Austin Bingham
Sent: Tuesday, March 28, 2000 9:39 AM
To: [EMAIL PROTECTED]
Subject: RE: link c libraries to c++ programs


What you need to do is inform the compiler that the code you are pointing at
is C. Of course, that's like saying that saying that the way to build a
space shuttle is to get the parts you need and put it together; so here's
how you do it ;)

In your C++ code, you include the headers to the C-library somewhere.
Wherever you include those headers, use the 'extern "C"' statement to tell
the compiler to look out for C decoration instead of C++. It looks something
like this:

--- CODE ---
// This is my C++ source file
extern "C"

#include "some_c_library_header_file.h"
#include "some_other_c_library_header_file.h"
}
#include <iostream.h>
#include "some_c++_library_header_file.h"

. . .

int main(void) {
        cout << "that's it." << endl;
        return 69;
}
--- CODE ---

I think this solves the problem you are discussing. Let me know if this
helps. Later...

Austin Bingham
Laboratory for Intelligent Processes and Systems
University of Texas at Austin
[EMAIL PROTECTED]

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of
Todd Gureckis
Sent: Monday, March 27, 2000 12:54 PM
To: [EMAIL PROTECTED]
Subject: link c libraries to c++ programs



i have a libxxx.a file that i want to link with a c++ program using g++.

if i compile like this:
g++ -c main.cpp
g++ main.o libxxx.a

i get a bunch of "undefined references" to functions in the library.
although if i write main.cpp in c
and do the same procedure above with gcc everything works.

what do you have to do to get the g++ linker to work with c libraries.

seems like to me like it should work automagically.

any help would be appreciated.

thanks,
tod.

-----------------------------------------------------------------
Todd Gureckis                           Webmaster http://kvrx.org
[EMAIL PROTECTED]                       [EMAIL PROTECTED]
http://www.adid.net/                    "Linux -- the choice of
phone: (512)415-5196                    the GNU Generation"
-----------------------------------------------------------------

---------------------------------------------------------------------------
Send administrative requests to [EMAIL PROTECTED]

---------------------------------------------------------------------------
Send administrative requests to [EMAIL PROTECTED]

---------------------------------------------------------------------------
Send administrative requests to [EMAIL PROTECTED]

Reply via email to