From ae508df90e070e676b2f7533cd77a0ec85483480 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Tue, 23 Dec 2014 17:32:30 +0100 Subject: [PATCH] Clean up compile for c_simple_example --- examples/Makefile | 11 +++++++---- examples/{simple_example.c => c_simple_example.c} | 7 +++---- 2 files changed, 10 insertions(+), 8 deletions(-) rename examples/{simple_example.c => c_simple_example.c} (88%) diff --git a/examples/Makefile b/examples/Makefile index 96c8bc3cf..efc5fe30e 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -2,7 +2,7 @@ include ../build_config.mk .PHONY: clean -all: simple_example column_families_example compact_files_example simple_example-c +all: simple_example column_families_example compact_files_example c_simple_example simple_example: simple_example.cc $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++11 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) @@ -13,8 +13,11 @@ column_families_example: column_families_example.cc compact_files_example: compact_files_example.cc $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++11 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) -simple_example-c: simple_example.c - $(CXX) -xc -I../include simple_example.c -o$@ -L.. -lrocksdb -pthread -lsnappy -lbz2 -lz -lrt +.c.o: + $(CC) $(CFLAGS) -c $< -o $@ -I../include + +c_simple_example: c_simple_example.o + $(CXX) $@.o -o$@ ../librocksdb.a $(PLATFORM_LDFLAGS) $(EXEC_LDFLAGS) clean: - rm -rf ./simple_example ./column_families_example ./compact_files_example ./simple_example-c + rm -rf ./simple_example ./column_families_example ./compact_files_example ./c_simple_example c_simple_example.o diff --git a/examples/simple_example.c b/examples/c_simple_example.c similarity index 88% rename from examples/simple_example.c rename to examples/c_simple_example.c index e982cce89..8c6f89e39 100644 --- a/examples/simple_example.c +++ b/examples/c_simple_example.c @@ -14,8 +14,8 @@ int main(int argc, char **argv) { rocksdb_options_t *options = rocksdb_options_create(); // Optimize RocksDB. This is the easiest way to // get RocksDB to perform well - int cpus = sysconf(_SC_NPROCESSORS_ONLN); // get # of online cores - rocksdb_options_increase_parallelism(options, cpus); + long cpus = sysconf(_SC_NPROCESSORS_ONLN); // get # of online cores + rocksdb_options_increase_parallelism(options, (int)(cpus)); rocksdb_options_optimize_level_style_compaction(options, 0); // create the DB if it's not already present rocksdb_options_set_create_if_missing(options, 1); @@ -28,7 +28,7 @@ int main(int argc, char **argv) { // Put key-value rocksdb_writeoptions_t *writeoptions = rocksdb_writeoptions_create(); const char key[] = "key"; - char *value = "value"; + const char *value = "value"; rocksdb_put(db, writeoptions, key, strlen (key), value, \ strlen (value), &err); assert(!err); @@ -38,7 +38,6 @@ int main(int argc, char **argv) { value = rocksdb_get(db, readoptions, key, strlen (key), &len, &err); assert(!err); assert(strcmp(value, "value") == 0); - free(value); // cleanup rocksdb_writeoptions_destroy(writeoptions);