-1

I installed casacore from source using the GitHub repository on my Ubuntu 18.04. The installation completes without any errors and the respective files are written to the expected directories (the .h files to /usr/local/include & libraries to /usr/local/lib). On trying to compile a basic C++ file using these I'm given the following error:

tmp/ccBxZcf3.o: In function 'main': /home/zealouspriest/C_C++_Projects/bb++/ms.cpp:15: undefined reference to 'casacore::MeasurementSet::MeasurementSet()'

/home/zealouspriest/C_C++_Projects/bb++/ms.cpp:15: undefined reference to 'casacore::MeasurementSet::~MeasurementSet()'

collect2: error: ld returned 1 exit status

The compiler command that I use is as follows:

g++ -g -Wall -I/usr/local/include -L/usr/local/lib -lcasa_casa -lcasa_tables -lcasa_ms ms.cpp -o ms

The ms.cpp file being compiled is extremely simple and just creates an empty measurement set to test for successful linking and is as follows:

//ms.cpp
#include <iostream>
#include </usr/local/include/casacore/ms/MeasurementSets/MeasurementSet.h>

int main(){
    casacore::MeasurementSet ms = casacore::MeasurementSet();
    return 0;
}

Here is all that I have tried:

a) Building from source using GitHub instructions,

b) Installing from Ubuntu repository.

Thanks in advance for your time!

  • 1
    Can you find the missing symbols in the output of `nm -D -C libcasa_ms.so`? – pptaszni Sep 21 '20 at 09:44
  • @pptaszni on running the command it returns the symbols for each object in the library. Almost all the symbols are either 'T' , 'U', 'V' or 'u'. I don't understand what you mean by "find the missing symbols". – Dewan Arun Singh Sep 21 '20 at 11:50
  • I mean if `m -D -C libcasa_ms.so | grep "MeasurementSet::MeasurementSet()" shows that the symbol you are looking for is defined. With the libraries installed by hand it is a common problem to mix headers and shared libs from different project versions. Anyway, I see that you just used g++ args in incorrect order. – pptaszni Sep 21 '20 at 15:49

1 Answers1

0

When compiling manually with g++ you need to first specify your sources, and then the dependencies (libraries):

g++ -o ms ms.cpp -I/usr/local/include -L/usr/local/lib -lcasa_casa -lcasa_tables -lcasa_ms -g -Wall

Better just use CMake if you plan to have something more that just one cpp.

Related topics:

Alternatively, you can use the -Wl,--no-as-needed options:

g++ -g -Wall -I/usr/local/include -L/usr/local/lib -Wl,--no-as-needed -lcasa_ms ms.cpp -o ms
pptaszni
  • 5,591
  • 5
  • 27
  • 43