g++ with C libraries

P

Praveen Srinivasan

Hi,
I'm trying to link a g++ program against a library called libumf.a compiled
from C code, and am having problems. When I do

gcc -o foo.o foo.c -llibumf.a it works fine. But when I do
g++ -o foo.o foo.c -llibumf.a it complains with:

/tmp/ccg2Xl4u.o(.text+0x17): In function `main':
: undefined reference to `umfpack_di_free_numeric(void**)'
collect2: ld returned 1 exit status

where "umfpack_di_free_numeric(void**)" is the only function that I'm
calling from the library.

Is there something I need to know about linking C++ code with C libraries?

TIA,
Praveen
 
P

Pete C.

Praveen said:
Hi,
I'm trying to link a g++ program against a library called libumf.a
compiled from C code, and am having problems. When I do

gcc -o foo.o foo.c -llibumf.a it works fine. But when I do
g++ -o foo.o foo.c -llibumf.a it complains with:

/tmp/ccg2Xl4u.o(.text+0x17): In function `main':
collect2: ld returned 1 exit status

where "umfpack_di_free_numeric(void**)" is the only function that I'm
calling from the library.

Is there something I need to know about linking C++ code with C
libraries?

TIA,
Praveen

Specific implementations and third-party libraries are off-topic here; try a
"G++" newsgroup or a mailing list or forum for your library.

Note: you may need to enclose the header like so:
extern "C"
{
#include "yourlib.h"
}

- Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,924
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top