Question

I am currently trying to develop a C++ application which will envolve solving some algebraic tasks (such as differentiation or integration) using GiNaC; I've installed it first from the Ubuntu Software Center (Ubuntu 13.04) and afterwards directly from the ftp ftp://ftpthep.physik.uni-mainz.de/pub/GiNaC/ ; however, everytime i try to compile the following example program:

#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;

int main()
{
    symbol x("x"), y("y");
    ex poly;

    for (int i=0; i<3; ++i)
        poly += factorial(i+16)*pow(x,i)*pow(y,2-i);

    cout << poly << endl;
    return 0;
 }

i get a list of errors, all starting with "undefined reference to GiNaC::". I have verified that cln is also installed and the header files are on the default locations. Also, when compiling I've used the command g++ -o simple pkg-config --cflags --libs ginac simple.cpp and g++ -o simple -lginac -lcln simple.cpp, both have failed to compile.

Was it helpful?

Solution

The problem is the order of the parameters on the compile line. Try one of the following two variants:

g++ -o simple simple.cpp `pkg-config --cflags --libs ginac`

g++ -o simple -Wl,--no-as-needed `pkg-config --cflags --libs ginac` simple.cpp

The idea is that the order of the object files and libraries is important to the linker. Very simply put, by default it only links a library if it needs it to resolve some previously unresolved symbols.

The first variant above moves the libraries at the end of the build parameters (so after the object file for your code), while the second variant disables this behavior in the linker.

OTHER TIPS

I ran into the same exact issue, and I found 2 things that does bring you to where you want to be:

  1. I placed -lcln after -lginac on the command line

This enabled me to compile it, but the program would not run. I found the solution to this. The error was "GLIB_CXX_3.4.21 not defined in libstdc++.so.6 with link time reference"

  1. Link statically to libstdc++ with -static-libstdc++

As in:

g++ -g testgin.cpp -o simple -lcln -lginac -static-libstdc++

Peace

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top