Question

I've compiled the netlib implementation of the Jenkins and Traub rpoly formula for finding the zeros of a real polynomial) into a library as follows

f77 -c toms493.f
ar r rpoly.a toms493.o

Next I tried to compile and link the following C++ program with rpoly.a

extern "C" void rpoly_( double *op_ , int* degree_ , double* zeror_ , double* zeroi_ , bool* fail_ );

int main()
{
    bool fail;
    int degree = 2;
    double zeror[2] , zeroi[2];
    double op[] = {1 , -5 , 6};     // x^2 -5x + 6

    rpoly_( op , &degree , zeror , zeroi , &fail );
    return 0;
}

Done as follows

 g++ Foo.cpp -L /path/to/rpoly.a

But I got the linker error undefined reference to _rpoly_

This is perticularly odd since the name _rpoly_ appears in rpoly.a, as the command nm rpoly.a shows

toms493.o:
00000000 b .bss
00000000 d .data
00000000 r .rdata
00000000 t .text
0000186c T _calcsc_
         U _exp
00000cc5 T _fxshfr_
00001090 C _global_
         U _log
00001c64 T _newest_
00001ab2 T _nextk_
00001eb5 T _quad_
00001117 T _quadit_
00001e0b T _quadsd_
0000208d T _r4_epsilon__
0000207a T _r4_huge__
0000150e T _realit_
00000000 T _rpoly_
Was it helpful?

Solution

The command line invocation of g++ is incorrect. The -L option specifies a directory to search for libraries specified via an -l option.

You could simply delete -L and then the command line will specify the library directly.

gcc foo.cpp /path/to/rpoly.a
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top