From: Joe Spanicek,BHP-Research PKL,, <joe@holly.resptk.bhp.com.au>
Subject: How can you call C++ code from C code, using "DEC C" & "DEC C++ V1.3B"
Date: 1995/08/10 [thread overview]
Message-ID: <40br6e$knf@merlin.resmel.bhp.com.au> (raw)
Hi,
I have OSF/1 V3.0 using "DEC C" & "DEC C++ V1.3B". The problem I am having is
calling a archive compiled with 'C++' from with C code witch is compiled with
'C'.
The problem lies with linking the archive library to the generated C code. The
C++ compiler produces object code with a 'name' reference to functions
differently than does the C compiler. So in the end the linker can not make
the connection between the functions.
Could anyone give pointers on how to get around this, I am fluent in C but just
started in C++. I am trying to use a library written in C++ within software
written only in C.
An example of what I mean is shown below:
The C++ code:
--------------------->>>> function.cc <<<----------------------
#include <stdio.h>
void
swapme(int *p, int *q)
{
printf("in swapme: %d %d\n", *p, *q);
int t = *p;
*p = *q;
*q = t;
}
-----------------------------------------------------------------
The C main code:
-------------------->>>> testfunction.c <<<<----------------------
#include <stdio.h>
extern void swapme(int *, int *);
void
swapmelocal(int *p, int *q)
{
int t;
printf("in swapmelocal: %d %d\n", *p, *q);
t = *p;
*p = *q;
*q = t;
}
main()
{
int x = 10;
int y = 20;
printf("in main 1: x=%d x=%d\n", x, y);
swapmelocal(&x, &y);
printf("in main 2: x=%d x=%d\n", x, y);
swapme(&x, &y);
printf("in main 3: x=%d x=%d\n", x, y);
}
---------------------------------------------------------------------------
Doing the following compilations I get:
cxx -c function.cc
ar rc libfun.a function.o
cc -c testfunction.c
cc -o test testfunction.o libfun.a
ld:
Unresolved:
swapme
nm libfun.a
libfun.a[function.o]:
Name Value Type Size
_fpdata | 0000000000000000 | U | 0000000000000000
printf | 0000000000000000 | U | 0000000000000008
swapme(int*, int*) | 0000000000000000 | T | 0000000000000008
nm testfunction.o
Name Value Type Size
_fpdata | 0000000000000000 | U | 0000000000000000
main | 0000000000000112 | T | 0000000000000008
printf | 0000000000000000 | U | 0000000000000008
swapme | 0000000000000000 | U | 0000000000000008
swapmelocal | 0000000000000000 | T | 0000000000000008
As you can see between the nm output the linker can not match the function
'swapme' and 'swapme(int*, int*)' as the same.
I believe there is a solution on how to get around this, but in all the books
and refernece manuals I got for DEC C++ & C there is no mention of this
though it talks about calling C functions from C++ code. I am doing the opposite
next reply other threads:[~1995-08-10 4:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-08-10 4:00 Joe [this message]
1995-08-10 4:00 ` How can you call C++ code from C code, using "DEC C" & "DEC C++ V1.3B" Michael Spratte
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox