Commit ed5434c0 by songxinkai

finish CMakeLists.txt in c++/protobuf

parent 8d19ba6f
cmake_minimum_required (VERSION 3.1)
set (CMAKE_CXX_COMPILER "/home/songxinkai/user/local/bin/g++")
project (test_0)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -g -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -pthread")
set(protobuf_exec "/home/songxinkai/protobuf-3.11.2/build/bin/protoc")
set(protobuf_include_dir "/home/songxinkai/protobuf-3.11.2/build")
set(protobuf_library "/home/songxinkai/protobuf-3.11.2/build/lib/libprotobuf.so")
# set(eden_include "eden.ph.h")
# set(eden_src "eden.pb.cc")
# add_custom_command(OUTPUT eden_include eden_src
# COMMAND "protoc eden.proto --cpp_out=."
# )
#
# message("=========== ===========")
# message("${eden_include} ${eden_src}")
# message("=========== ===========")
set(protobuf_include_dir "/home/songxinkai/protobuf-3.11.2/src")
set(protobuf_library "${protobuf_library} /home/songxinkai/protobuf-3.11.2/src/.libs/libprotoc.so")
set(protobuf_library "${protobuf_library} /home/songxinkai/protobuf-3.11.2/src/.libs/libprotobuf.so")
set(test_src "${PROJECT_SOURCE_DIR}/test_0.cpp")
set(eden_src "${PROJECT_SOURCE_DIR}/eden.pb.cc")
add_executable(test "${test_src}" "${eden_src}")
add_executable(test_exec "${test_src}" "${eden_src}" "eden.pb.h")
include_directories("${protobuf_include_dir}" "${PROJECT_SOURCE_DIR}")
target_link_libraries(test "${protobuf_library}")
target_link_libraries(test_exec "/home/songxinkai/protobuf-3.11.2/src/.libs/libprotoc.so" "/home/songxinkai/protobuf-3.11.2/src/.libs/libprotobuf.so" "/home/songxinkai/protobuf-3.11.2/src/.libs/libprotobuf-lite.so")
count: 1
speed: 3.3
sight: 5.5
#include <iostream>
#include "eden.ph.h"
#include "eden.pb.h"
#include <fstream>
#include <sstream>
#include <string>
#include "google/protobuf/text_format.h"
using namespace std;
int main(){
cout << "Hello!" << endl;
eden::pigs Pigs;
Pigs.set_count(10);
string str;
cout << "0" << endl;
google::protobuf::TextFormat::PrintToString(Pigs, &str);
cout << str << endl;
// fstream input("../pigs.pt", ios::in | ios::binary);
// if (!input) {
// cout << "pigs.pt" << ": File not found. Creating a new file." << endl;
// } else if (!Pigs->ParseFromIstream(&input)) {
// cerr << "Failed to parse pigs." << endl;
// }
cout << "1" << endl;
std::ostringstream conf_ss;
conf_ss << std::ifstream("../pigs.pt").rdbuf();
cout << "2" << endl;
google::protobuf::TextFormat::ParseFromString(conf_ss.str(), &Pigs);
cout << "3" << endl;
cout << Pigs.count() << endl;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment