vgteam / libhandlegraph

Library for the Handle Graph abstraction
MIT License
20 stars 3 forks source link

undefined reference to `handlegraph::algorithms::dijkstra(handlegraph::HandleGraph const*, handlegraph::handle_t, std::function<bool (handlegraph::handle_t const&, unsigned long)>, bool)' #92

Open cgroza opened 1 year ago

cgroza commented 1 year ago

Hi,

I am trying to use the dijkstra algorithm defined in libhandlegraph but getting a linker error.

undefined reference to `handlegraph::algorithms::dijkstra(handlegraph::HandleGraph const*, handlegraph::handle_t, std::function<bool (handlegraph::handle_t const&, unsigned long)>, bool)'

There are not other errors and warnings. I compiled and installed both libbdsg and libhandlegraph on Ubuntu.

I inspected the libhandlegraph dynamic and static libraries for this symbol and it is indeed there.

cgroza@ubuntu:/$ nm ./usr/local/lib/libhandlegraph.so | grep dijkstra
0000000000024a10 t _GLOBAL__sub_I_dijkstra.cpp
0000000000059050 T _ZN11handlegraph10algorithms8dijkstraEPKNS_11HandleGraphENS_8handle_tESt8functionIFbRKS4_mEEbbb
0000000000023287 t _ZN11handlegraph10algorithms8dijkstraEPKNS_11HandleGraphENS_8handle_tESt8functionIFbRKS4_mEEbbb.cold
0000000000058470 T _ZN11handlegraph10algorithms8dijkstraEPKNS_11HandleGraphERKSt13unordered_setINS_8handle_tESt4hashIS5_ESt8equal_toIS5_ESaIS5_EESt8functionIFbRKS5_mEEbbb
0000000000023182 t _ZN11handlegraph10algorithms8dijkstraEPKNS_11HandleGraphERKSt13unordered_setINS_8handle_tESt4hashIS5_ESt8equal_toIS5_ESaIS5_EESt8functionIFbRKS5_mEEbbb.cold
0000000000056f30 t _ZNSt17_Function_handlerIFbRKN11handlegraph8handle_tEEZNS0_20BoolReturningWrapperIZNS0_10algorithms8dijkstraEPKNS0_11HandleGraphERKSt13unordered_setIS1_St4hashIS1_ESt8equal_toIS1_ESaIS1_EESt8functionIFbS3_mEEbbbEUlS3_E_Lb0EE4wrapERKSM_EUlDpOT_E_E10_M_managerERSt9_Any_dataRKSV_St18_Manager_operation
0000000000056fb0 t _ZNSt17_Function_handlerIFbRKN11handlegraph8handle_tEEZNS0_20BoolReturningWrapperIZNS0_10algorithms8dijkstraEPKNS0_11HandleGraphERKSt13unordered_setIS1_St4hashIS1_ESt8equal_toIS1_ESaIS1_EESt8functionIFbS3_mEEbbbEUlS3_E_Lb0EE4wrapERKSM_EUlDpOT_E_E9_M_invokeERKSt9_Any_dataS3_
0000000000080830 d _ZTIZN11handlegraph20BoolReturningWrapperIZNS_10algorithms8dijkstraEPKNS_11HandleGraphERKSt13unordered_setINS_8handle_tESt4hashIS6_ESt8equal_toIS6_ESaIS6_EESt8functionIFbRKS6_mEEbbbEUlSH_E_Lb0EE4wrapERKSK_EUlDpOT_E_
000000000006bf60 r _ZTSZN11handlegraph20BoolReturningWrapperIZNS_10algorithms8dijkstraEPKNS_11HandleGraphERKSt13unordered_setINS_8handle_tESt4hashIS6_ESt8equal_toIS6_ESaIS6_EESt8functionIFbRKS6_mEEbbbEUlSH_E_Lb0EE4wrapERKSK_EUlDpOT_E_

Here is the Makefile and the source code:

Makefile:

nearestpaths: nearestpaths.cpp
    g++ -std=c++2b  nearestpaths.cpp -lbdsg -lsdsl -lgomp -lhandlegraph -o nearestpaths

all: nearestpaths

Source code:

#include <handlegraph/algorithms/dijkstra.hpp>
#include <handlegraph/handle_graph.hpp>
#include <bdsg/packed_graph.hpp>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

const size_t max_distance = 100;

int main(int argc, char **argv) {
  std::vector<std::string> paths;

  std::ifstream paths_file("test/chr21_subset.paths");

  std::string p;
  while(!paths_file.eof()) {
    std::getline(paths_file, p);
    paths.push_back(p);
  }

  bdsg::PackedGraph graph;
  graph.deserialize("test/chr21_subset.pack");

  for (auto &s : paths) {
    std::cout << s << std::endl;
    if (!graph.has_path(s)) {
      std::cout << "No path " << s << std::endl;
      continue;
    }
    bdsg::path_handle_t path = graph.get_path_handle(s);
    bdsg::handle_t start_node = graph.get_handle_of_step(graph.path_begin(path));
    handlegraph::algorithms::dijkstra(
        &graph, start_node, [&](const handlegraph::handle_t h, size_t d) {
          std::cout << "Reached " << d << std::endl;
          if(d > max_distance)
            return false;
          return true;
        });
  }

  return 0;
}

Any pointers on why g++ does not find the symbols?

My thanks.

cgroza commented 1 year ago

I moved that code into my own source files and the symbol is found. Seems to me there is something wrong with the way the library is compiled?

jeizenga commented 1 year ago

Is it possible that you're not picking up any of libhandlegraph.a at linking? Most of libhandlegraph is header files, so it could be that your build is getting the includes but not the library without running into any other linking errors.