Skip to content

Instantly share code, notes, and snippets.

@cycyyy
Created December 22, 2020 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cycyyy/86b224ab70bd032cd70bcf7b8dab1c04 to your computer and use it in GitHub Desktop.
Save cycyyy/86b224ab70bd032cd70bcf7b8dab1c04 to your computer and use it in GitHub Desktop.
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(recsys)
find_package(Torch REQUIRED)
find_library(ROCKSDB_LIB rocksdb)
find_package(Boost 1.67.0 REQUIRED COMPONENTS system filesystem)
add_executable(recsys main.cpp)
target_link_libraries(recsys "${Boost_LIBRARIES}" "${ROCKSDB_LIB}") #It works fine
# If I link the libtorch, it will have segementation fault for boost example. For RocksDB, it will have complie error: "undefined reference to `rocksdb::DB::Open(rocksdb::Options const&, std::string const&, rocksdb::DB**)' "
# target_link_libraries(recsys "${TORCH_LIBRARIES}" "${Boost_LIBRARIES}" "${ROCKSDB_LIB}") ]]
set_property(TARGET recsys PROPERTY CXX_STANDARD 14)
#include <iostream>
#include "rocksdb/db.h"
int main(int argc, char *argv[])
{
rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
rocksdb::Status status = rocksdb::DB::Open(options, "./testdb", &db);
std::cout << "rocksb open status: " << status.ok() << std::endl;
std::string sKey("key-one");
std::string sValue("Value Some");
status = db->Put(rocksdb::WriteOptions(), sKey, sValue);
if (status.ok())
{
std::cout << "put key ok" << std::endl;
std::string rValue;
rocksdb::Status s = db->Get(rocksdb::ReadOptions(), sKey, &rValue);
if (s.ok()) {
std::cout << "read from rocksdb success: " << rValue << std::endl;
}
}
else
{
std::cout << "put key error, with status: " << status.code() << std::endl;
}
db->Close();
return 0;
}
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
int main()
{
string base_dir = "/home/xxx";
fs::path base_path(base_dir);
fs::path train_file("a.csv");
fs::path target_file("b.csv");
fs::path train_path = base_path / train_file;
fs::path target_path = base_path / target_file;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment