icecube / nuflux

A library for calculating atmospheric neutrino fluxes.
https://docs.icecube.aq/nuflux/main
GNU Lesser General Public License v3.0
15 stars 5 forks source link

linking error on ubuntu #25

Open kjmeagher opened 7 months ago

kjmeagher commented 7 months ago

On ububntu there is a weird error when you try to actually link a c++ program against nuflux. The linking step works perfectly in the meson testing environment and all the tests pass but when linking another program you get:

/usr/bin/ld: /tmp/ccyWsns7.o: in function `main':
test_basic.cxx:(.text+0x28): undefined reference to `nuflux::availableFluxes[abi:cxx11]()'
/usr/bin/ld: test_basic.cxx:(.text+0x5b): undefined reference to `nuflux::makeFlux(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status

The symbols are in the so file so i cant figure out why linking isn't working

# nm /usr/local/lib/x86_64-linux-gnu/libnuflux.so|grep 'availableFluxes\|makeFlux'|c++filt
000000000002c990 T nuflux::SplineFlux2::makeFlux(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
0000000000030510 T nuflux::availableFluxes[abi:cxx11]()
0000000000014a5a t nuflux::availableFluxes[abi:cxx11]() [clone .cold]
0000000000033480 T nuflux::LegacyPromptFlux::makeFlux(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
0000000000027f40 T nuflux::SimpleSplineFlux::makeFlux(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
0000000000020730 T nuflux::IntegralPreservingFlux::makeFlux(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
00000000000263d0 T nuflux::LegacyConventionalFlux::makeFlux(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
0000000000019840 T nuflux::ANFlux::makeFlux(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
000000000002faf0 T nuflux::makeFlux(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
000000000001487c t nuflux::makeFlux(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [clone .cold]

This can be reproduced in a docker image:

docker run -it --rm  -v ~/icecube/nuflux:/nuflux ubuntu:latest
apt-get update
apt-get install ninja-build libcfitsio-dev python-is-python3 libboost-python-dev curl cmake g++ python3-pip pkg-config python3-numpy
python3 -m pip install meson pytest pytest-subtests
curl -L https://github.com/icecube/photospline/archive/refs/tags/v2.2.1.tar.gz | tar xz 
cmake -S photospline-2.2.1 -B photospline -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
make install -C photospline
cd /nuflux
meson setup build .
ninja -C build test
ninja -C build install
g++ -std=c++17 -lnuflux tests/test_basic.cxx