g++ linking to gcc compiled libraries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello guys.
I'm hoping you can tell me what I'm doing wrong here.
I have a library written in C that I'd like to link to from both c
programs and c++ programs.
I'm guessing that this is possible.

If I compile both the library and program using g++ it works fine, but
then I can't link to the c library from c programs.

Here is the output of me trying to use g++ to link to a c library
compiled with gcc.
What am I doing wrong?  Or is it even possible to do?

$ cat clibrary.h
int cfun(int d);
$ cat clibrary.c
int cfun(int d){
    return d*100 + 7;
}
$ cat cppsource.cc
#include <iostream>
using namespace std;

#include "clibrary.h"

int main(int argc, char* argv[]){
    int myint = cfun(3);
    cout << myint << endl;
}
$ gcc -c clibrary.c
$ g++ -c cppsource.cc
$ g++ -o cppsource.exe cppsource.o clibrary.o
cppsource.o(.text+0x83): In function `main':
: undefined reference to `cfun(int)'
collect2: ld returned 1 exit status
$

Thanks,
~Eric


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux