Linking Errors with "undefined reference to..."

Help
npcfish
2014-03-05
2014-03-05
  • npcfish
    npcfish
    2014-03-05

    Hi,

    I am new to itpp. I installed itpp under UBUNTU 12.04 using these commands:
    apt-get install libitpp7
    apt-get install libitpp7-dbg
    apt-get install libitpp-dev

    It seems to be OK when compiling, but when linking it shows error messages like this:

    wtmf.o: In function read_smat_data(char*, itpp::Sparse_Mat<double>&)': /home/npcfish/Desktop/code/wtmf.cpp:84: undefined reference toitpp::Sparse_Mat<double>::set_size(int, int, int)'
    /home/npcfish/Desktop/code/wtmf.cpp:97: undefined reference to itpp::Sparse_Mat<double>::set(int, int, double)' /home/npcfish/Desktop/code/wtmf.cpp:102: undefined reference toitpp::Sparse_Mat<double>::compact()'
    /home/npcfish/Desktop/code/wtmf.cpp:106: undefined reference to `itpp::Sparse_Mat<double>::nnz()'
    ...

    and so on. How can I solve this problem?
    Thank you in advance~

     
  • Bogdan Cristea
    Bogdan Cristea
    2014-03-05

    it seems that you forgot to link with it++ library

     
  • npcfish
    npcfish
    2014-03-05

    So.. As I am really new to this, how should I do to make sure I am linking with it++ library? I tried "g++ wtmf.cpp $(pkg-config --libs itpp)" but it doesn't work...

     
  • npcfish
    npcfish
    2014-03-05

    When I type this command:
    % pkg-config --libs itpp

    It displays:
    '-L/usr/local/lib -litpp'

    While when I try this command:
    % itpp-config --libs

    It displays:
    ' -L/usr/local/lib -litpp'

    I note there is a space before the second output?

     
  • Bogdan Cristea
    Bogdan Cristea
    2014-03-05

    That space should not be an issue. Please use directly in the command line:
    g++ -L/usr/local/lib -litpp main.cpp -o main
    and check the output

     
  • npcfish
    npcfish
    2014-03-05

    I tried, but it reports the same error messages...

     
  • Bogdan Cristea
    Bogdan Cristea
    2014-03-05

    It might be a problem with your IT++ library. Check that it is really inside /usr/local/lib folder. Also, you might try to build IT++ from sources using the version from master branch

     
  • npcfish
    npcfish
    2014-03-05

    It works now. It seems adding '$(pkg-config --libs itpp)' to the linking command would be OK. My mistake is I just forgot to link some of my code files that are used in my main cpp.

    Thank you very much!