[mlpack] Follow-up: compilation / linking issue "undefined reference"

Hearn, David J. DHearn at towson.edu
Fri Sep 6 11:31:40 EDT 2019


Hello,

I'm very sorry to post a repeat request. i know you all are very busy, but for the life of me, I cannot get mlpack code - or the library itself - to compile correctly on my system. I'm reposting my previous message in the hopes in won't get lost in the transition between August and September posts. I've done quite a bit of coding and have not run into this issue before.

Begin repost:


Hello,

I've installed mlpack-3.1.1 and mlpack-devel in /usr/include/mlpack (headers) and /usr/lib64/libmlpack.so  using yum on Fedora 7.6.

I've tried to compile the following example code  ( compiling with g++ (GCC) 9.2.0)
_______________
#include <mlpack/core.hpp>
#include <mlpack/methods/neighbor_search/neighbor_search.hpp>
#include <mlpack/core/data/load.hpp>

using namespace mlpack;
using namespace mlpack::neighbor; // NeighborSearch and NearestNeighborSort
using namespace mlpack::metric; // ManhattanDistance

int main()
{
    arma::mat data;
    data::Load("data.csv", data, true);
    NeighborSearch<NearestNeighborSort, ManhattanDistance> nn(data);
    arma::Mat<size_t> neighbors;
    arma::mat distances;
    nn.Search(1, neighbors, distances);

    for (size_t i = 0; i < neighbors.n_elem; ++i)
    {
        std::cout << "Nearest neighbor of point " << i << " is point "
        << neighbors[i] << " and the distance is " << distances[i] << ".\n";
    }
}
__________

When I tried to compile this code with:
g++ knn_example.cpp -o knn_example -std=c++11 -larmadillo -lmlpack -lboost_serialization -fopenmp

or with

g++ knn_example.cpp -o knn_example -std=c++11 -larmadillo -lmlpack -lboost_serialization -fopenmp -I/usr/include/ -L/usr/lib64

, the error I get is as follows:

/tmp/cckP4kAv.o: In function `main':
knn_example.cpp:(.text+0x317): undefined reference to `bool mlpack::data::Load<double>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, arma::Mat<double>&, bool, bool)'
/tmp/cckP4kAv.o: In function `mlpack::neighbor::NeighborSearch<mlpack::neighbor::NearestNS, mlpack::metric::LMetric<1, false>, arma::Mat<double>, mlpack::tree::KDTree, mlpack::tree::BinarySpaceTree<mlpack::metric::LMetric<1, false>, mlpack::neighbor::NeighborSearchStat<mlpack::neighbor::NearestNS>, arma::Mat<double>, mlpack::bound::HRectBound, mlpack::tree::MidpointSplit>::DualTreeTraverser, mlpack::tree::BinarySpaceTree<mlpack::metric::LMetric<1, false>, mlpack::neighbor::NeighborSearchStat<mlpack::neighbor::NearestNS>, arma::Mat<double>, mlpack::bound::HRectBound, mlpack::tree::MidpointSplit>::SingleTreeTraverser>::Search(unsigned long, arma::Mat<unsigned long>&, arma::Mat<double>&)':
knn_example.cpp:(.text._ZN6mlpack8neighbor14NeighborSearchINS0_9NearestNSENS_6metric7LMetricILi1ELb0EEEN4arma3MatIdEENS_4tree6KDTreeENS9_15BinarySpaceTreeIS5_NS0_18NeighborSearchStatIS2_EES8_NS_5bound10HRectBoundENS9_13MidpointSplitEE17DualTreeTraverserENSH_19SingleTreeTraverserEE6SearchEmRNS7_ImEERS8_[_ZN6mlpack8neighbor14NeighborSearchINS0_9NearestNSENS_6metric7LMetricILi1ELb0EEEN4arma3MatIdEENS_4tree6KDTreeENS9_15BinarySpaceTreeIS5_NS0_18NeighborSearchStatIS2_EES8_NS_5bound10HRectBoundENS9_13MidpointSplitEE17DualTreeTraverserENSH_19SingleTreeTraverserEE6SearchEmRNS7_ImEERS8_]+0x256): undefined reference to `mlpack::Timer::Start(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
knn_example.cpp:(.text._ZN6mlpack8neighbor14NeighborSearchINS0_9NearestNSENS_6metric7LMetricILi1ELb0EEEN4arma3MatIdEENS_4tree6KDTreeENS9_15BinarySpaceTreeIS5_NS0_18NeighborSearchStatIS2_EES8_NS_5bound10HRectBoundENS9_13MidpointSplitEE17DualTreeTraverserENSH_19SingleTreeTraverserEE6SearchEmRNS7_ImEERS8_[_ZN6mlpack8neighbor14NeighborSearchINS0_9NearestNSENS_6metric7LMetricILi1ELb0EEEN4arma3MatIdEENS_4tree6KDTreeENS9_15BinarySpaceTreeIS5_NS0_18NeighborSearchStatIS2_EES8_NS_5bound10HRectBoundENS9_13MidpointSplitEE17DualTreeTraverserENSH_19SingleTreeTraverserEE6SearchEmRNS7_ImEERS8_]+0xb15): undefined reference to `mlpack::Timer::Stop(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cckP4kAv.o: In function `mlpack::bound::HRectBound<mlpack::metric::LMetric<1, false>, double>& mlpack::bound::HRectBound<mlpack::metric::LMetric<1, false>, double>::operator|=<arma::subview<double> >(arma::subview<double> const&)':
knn_example.cpp:(.text._ZN6mlpack5bound10HRectBoundINS_6metric7LMetricILi1ELb0EEEdEoRIN4arma7subviewIdEEEERS5_RKT_[_ZN6mlpack5bound10HRectBoundINS_6metric7LMetricILi1ELb0EEEdEoRIN4arma7subviewIdEEEERS5_RKT_]+0x6f): undefined reference to `mlpack::Log::Assert(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cckP4kAv.o: In function `unsigned long mlpack::tree::split::PerformSplit<arma::Mat<double>, mlpack::tree::MidpointSplit<mlpack::bound::HRectBound<mlpack::metric::LMetric<1, false>, double>, arma::Mat<double> > >(arma::Mat<double>&, unsigned long, unsigned long, mlpack::tree::MidpointSplit<mlpack::bound::HRectBound<mlpack::metric::LMetric<1, false>, double>, arma::Mat<double> >::SplitInfo const&, std::vector<unsigned long, std::allocator<unsigned long> >&)':
knn_example.cpp:(.text._ZN6mlpack4tree5split12PerformSplitIN4arma3MatIdEENS0_13MidpointSplitINS_5bound10HRectBoundINS_6metric7LMetricILi1ELb0EEEdEES5_EEEEmRT_mmRKNT0_9SplitInfoERSt6vectorImSaImEE[_ZN6mlpack4tree5split12PerformSplitIN4arma3MatIdEENS0_13MidpointSplitINS_5bound10HRectBoundINS_6metric7LMetricILi1ELb0EEEdEES5_EEEEmRT_mmRKNT0_9SplitInfoERSt6vectorImSaImEE]+0x40a): undefined reference to `mlpack::Log::Assert(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cckP4kAv.o: In function `double mlpack::bound::HRectBound<mlpack::metric::LMetric<1, false>, double>::MinDistance<arma::subview_col<double> >(arma::subview_col<double> const&, std::enable_if<IsVector<arma::subview_col<double> >::value, void>::type*) const':
knn_example.cpp:(.text._ZNK6mlpack5bound10HRectBoundINS_6metric7LMetricILi1ELb0EEEdE11MinDistanceIN4arma11subview_colIdEEEEdRKT_PNSt9enable_ifIXsr8IsVectorISA_E5valueEvE4typeE[_ZNK6mlpack5bound10HRectBoundINS_6metric7LMetricILi1ELb0EEEdE11MinDistanceIN4arma11subview_colIdEEEEdRKT_PNSt9enable_ifIXsr8IsVectorISA_E5valueEvE4typeE]+0x6a): undefined reference to `mlpack::Log::Assert(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cckP4kAv.o: In function `mlpack::bound::HRectBound<mlpack::metric::LMetric<1, false>, double>::MinDistance(mlpack::bound::HRectBound<mlpack::metric::LMetric<1, false>, double> const&) const':
knn_example.cpp:(.text._ZNK6mlpack5bound10HRectBoundINS_6metric7LMetricILi1ELb0EEEdE11MinDistanceERKS5_[_ZNK6mlpack5bound10HRectBoundINS_6metric7LMetricILi1ELb0EEEdE11MinDistanceERKS5_]+0x56): undefined reference to `mlpack::Log::Assert(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status

_________________________

I'm hoping someone may be able to help with this compilation issue.

I've also tried compiling mlpack itself from source using boost_1_71_0, but even after giving cmake the BOOST_ROOT, boost is not linking appropriately when 'make' is run. Although this is a separate issue, if anyone has suggestions about either of these approaches to using mlpack, I'd be very grateful.

Regards,
David

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://knife.lugatgt.org/pipermail/mlpack/attachments/20190906/cf2bf6a5/attachment-0001.html>


More information about the mlpack mailing list