How to link torch in leveldb, and use leveldb in YCSB-cpp?

WangTingZheng: <blockquote>
<p>I want use <a href="https://pytorch.org/cppdocs/installing.html" rel="noopener nofollow ugc">torch</a>(C++ version of pytorch) in <a href="https://github.com/WangTingZheng/Paperdb" rel="noopener nofollow ugc">leveldb</a>, and link leveldb in <a href="https://github.com/WangTingZheng/YCSB-cpp" rel="noopener nofollow ugc">YCSB-cpp</a> to benchmark it, I can not install torch and leveldb in system path, because I using public sever. I got some error when I bind leveldb in YCSB-cpp.</p>
</blockquote>
<p>I put torch in CMakeLists.txt like this, try to find python  and torch, and set Torch path flag:</p>
<pre data-code-wrap="cmake"><code class="lang-cmake">find_package(PythonInterp REQUIRED)
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
add_library(leveldb "")
target_sources(leveldb
  PRIVATE
    "${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h"
    "db/builder.cc"
</code></pre>
<p>after target_sources, I use target_link_libraries to link torch libraries:</p>
<pre data-code-wrap="shell"><code class="lang-shell"># Needed by port_stdcxx.h
find_package(Threads REQUIRED)
target_link_libraries(leveldb Threads::Threads)

target_link_libraries(leveldb "${TORCH_LIBRARIES}")
</code></pre>
<p>I use this command to pass in libtorch, and build:</p>
<pre data-code-wrap="shell"><code class="lang-shell">cmake -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch ..
make -j 24
</code></pre>
<p>I use this shell to bind leveldb in YCSB-cpp</p>
<pre data-code-wrap="shell"><code class="lang-shell">make BIND_LEVELDB=1 EXTRA_CXXFLAGS=-I/path/to/leveldb/include \ EXTRA_LDFLAGS="-I/path/to/leveldb/include -L/path/to/leveldb/build -lleveldb"
</code></pre>
<p>but I got this error message:</p>
<pre data-code-wrap="shell"><code class="lang-shell">CC       leveldb/leveldb_db.o
  CC       core/basic_db.o
  CC       core/db_factory.o
  CC       core/measurements.o
  CC       core/ycsbc.o
  CC       core/acknowledged_counter_generator.o
  CC       core/core_workload.o
/usr/bin/ld: leveldb/leveldb_db.o: in function `ycsbc::LeveldbDB::Init()':
leveldb_db.cc:(.text+0x40ee): undefined reference to `leveldb::DestroyDB(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, leveldb::Options const&amp;)'
/usr/bin/ld: leveldb_db.cc:(.text+0x4133): undefined reference to `leveldb::DB::Open(leveldb::Options const&amp;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, leveldb::DB**)'
/usr/bin/ld: leveldb/leveldb_db.o: in function `ycsbc::LeveldbDB::InsertSingleEntry(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, std::vector&lt;ycsbc::DB::Field, std::allocator&lt;ycsbc::DB::Field&gt; &gt;&amp;) [clone .cold]':
leveldb_db.cc:(.text.unlikely+0x33): undefined reference to `leveldb::Status::ToString[abi:cxx11]() const'
/usr/bin/ld: leveldb/leveldb_db.o: in function `ycsbc::LeveldbDB::DeleteSingleEntry(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) [clone .cold]':
leveldb_db.cc:(.text.unlikely+0x181): undefined reference to `leveldb::Status::ToString[abi:cxx11]() const'
/usr/bin/ld: leveldb/leveldb_db.o: in function `ycsbc::LeveldbDB::UpdateSingleEntry(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, std::vector&lt;ycsbc::DB::Field, std::allocator&lt;ycsbc::DB::Field&gt; &gt;&amp;) [clone .cold]':
leveldb_db.cc:(.text.unlikely+0x30a): undefined reference to `leveldb::Status::ToString[abi:cxx11]() const'
/usr/bin/ld: leveldb_db.cc:(.text.unlikely+0x3c8): undefined reference to `leveldb::Status::ToString[abi:cxx11]() const'
/usr/bin/ld: leveldb/leveldb_db.o: in function `ycsbc::LeveldbDB::ReadSingleEntry(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, std::vector&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::allocator&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; const*, std::vector&lt;ycsbc::DB::Field, std::allocator&lt;ycsbc::DB::Field&gt; &gt;&amp;) [clone .cold]':
leveldb_db.cc:(.text.unlikely+0x622): undefined reference to `leveldb::Status::ToString[abi:cxx11]() const'
/usr/bin/ld: leveldb/leveldb_db.o:leveldb_db.cc:(.text.unlikely+0xa08): more undefined references to `leveldb::Status::ToString[abi:cxx11]() const' follow
collect2: error: ld returned 1 exit status
make: *** [Makefile:89: ycsb] Error 1
</code></pre>
<p>Here are some possible reasons：</p>
<ol>
<li>I misplaced target_link_libraries(leveldb “${TORCH_LIBRARIES}”)</li>
<li>I should pass in torch link to in YCSB-cpp too, just like snappy</li>
</ol>