I have been trying for a couple of weeks now to compile a program that
consists of a C++ main function which calls a C function. I have tried
using the -c option to compile object code for both files using gcc and
g++, then linking them together (I've trued using both gcc and g++ to
link the object code). However when I try the final link together I get
an error saying that there was an undefined reference to the C function
in the main function.
Here is the test code I have been using (I know there is no reason why
I can't compile them both as C or C++ but they are not the functions I
need to compile, only test ones. It makes sense to me. The final code I
create will involve RPC calls which I can only get working in C)
//C++ main function called main.cc
extern void funky(void);
void main()
{
funky();
};
//C function called funky.c
void funky()
{
int x;
x = 0;
};
The commands I used were
g++ -c main.cc
gcc -c funky.c
g++ main.o funky.o -o prog
I am sorry to bother you with this question but I don't know who else
to try, even my leactures at university don't know how to achieve this.
--
John, My reality check just bounced.