This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: keep getting "undefined reference to" linker error


Brian Dessent wrote:
> "H.S." wrote:
> 
>> So, any advice how I can get this working with a C++ program? This was
> 
> Yes, edit taucs.h so that it has an 'extern "C"' block surrounding the
> function declarations but not for the entire file (i.e. just for the
> body of the file, not around headers that it includes.)

Thanks, that solved it!

Looks like the library header file is not written in a portable fashion.
Here is what I modified to relevant function declarations to:
ifdef __cplusplus
extern "C" {
#endif
taucs_ccs_matrix* taucs_dtl(ccs_create)          (int m, int n, int nnz);
taucs_ccs_matrix* taucs_ccs_create               (int m, int n, int nnz,
int flags);
void              taucs_dtl(ccs_free)            (taucs_ccs_matrix* matrix);
void              taucs_ccs_free                 (taucs_ccs_matrix* matrix);
#ifdef __cplusplus
}
#endif

Then, but just including taucs.h in my source file, my example program
compiles. Now I just have to modify all the header files in the library
accordingly. I was hoping I would not need to fiddle with the library
source ... oh, well.

The library was last released in 2003. This makes me wonder, has
anything in the gcc compiler changed since then that it might have
worked without the above changes at that time?


>> If there is way to create a
>> routine which does this in C and then link to it with my C++ program,
>> that would be great too, but I guess I will still need to solve the
>> problem of including taucs.h somehow.
> 
> Well that is also a solution but it essentially just moves the problem
> out of the taucs.h header and into a header of your own.  No matter how
> you slice it, at the junction between C++ code calling a C function you
> need 'extern "C"' on the declaration.

True.

much appreciated your help,
regards,
->HS


> Brian
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]