I'm trying to create a shared library which in turn uses libtorch and libngt. libtorch provides a proper way to link the project to itself and that works fine but somehow I'm running into issue while linking libngt using cmake.
My CMakeLists.txt
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(blksim_test)
find_package(Torch REQUIRED)
link_directories("/usr/local/lib/")
add_executable(test_sim test_sim.cc hash_network.cc hash_pool.cc)
target_include_directories(test_sim PRIVATE ../include)
target_link_libraries(test_sim "${TORCH_LIBRARIES}")
target_link_libraries(test_sim ngt)
set_property(TARGET test_sim PROPERTY CXX_STANDARD 14 )
I run into these errors:
Error:
/usr/bin/ld: CMakeFiles/test_sim.dir/hash_pool.cc.o: in function `NGT::Index::open(std::string const&, bool)':
hash_pool.cc:(.text._ZN3NGT5Index4openERKSsb[_ZN3NGT5Index4openERKSsb]+0x2e): undefined reference to `NGT::Index::open(std::string const&, bool, bool)'
/usr/bin/ld: CMakeFiles/test_sim.dir/hash_pool.cc.o: in function `NGT::Index::createGraphAndTree(std::string const&, NGT::Property&, bool)':
hash_pool.cc:(.text._ZN3NGT5Index18createGraphAndTreeERKSsRNS_8PropertyEb[_ZN3NGT5Index18createGraphAndTreeERKSsRNS_8PropertyEb]+0x6c): undefined reference to `NGT::Index::createGraphAndTree(std::string const&, NGT::Property&, std::string const&, unsigned long, bool)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/test_sim.dir/build.make:133: test_sim] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test_sim.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
I made sure to export the PATH
and LD_LIBRARY_PATH
to include /usr/local/lib
where libngt is located.
instance1:~/code$ ls -al /usr/local/lib/libngt.*
-rw-r--r-- 1 root root 4037082 Mar 20 21:40 /usr/local/lib/libngt.a
lrwxrwxrwx 1 root root 11 Mar 20 23:02 /usr/local/lib/libngt.so -> libngt.so.1
lrwxrwxrwx 1 root root 16 Mar 20 23:02 /usr/local/lib/libngt.so.1 -> libngt.so.1.14.5
-rw-r--r-- 1 root root 1581560 Mar 20 21:41 /usr/local/lib/libngt.so.1.14.5
I can't figure out what am I doing wrong. I'm using cmake for the first time so I'm almost certain that something is wrong with the way I'm linking libngt.
I tried creating a FindNGT.cmake
in the build directory but even that didn't help. I don't know what am I missing.