# Install the protoc compiler and dependencies (if not installed, C++ can be used)sudo yum install gcc gcc-c++ automake autoconf libtool makesudo yum install cmake
# Manual download protobufwget https://github.com/protocolbuffers/protobuf/archive/v2.6.1.tar.gz# Decompress the source codetar -xzf v2.6.1.tar.gz# Access the decompressed directorycd protobuf-2.6.1# Generate configuration file. If the process hangs or a timed out error occurs, refer to the following [Common errors fix]../autogen.sh# Configure installation./configure# Compilation, this step may take a while, please wait patientlymakesudo make installsudo ldconfig
# Download the CLS SDKgit clone https://github.com/TencentCloud/tencentcloud-cls-sdk-cpp.git# Enter directorycd tencentcloud-cls-sdk-cpp# Install dependency.sudo yum install boost-develsudo yum install openssl-develsudo yum install libcurl-devel# Generate build filescmake .# Compile SDKmakesudo make install
sample.cpp under the cls folder in the Log Service SDK Demo as an example. The code analysis is shown below. In actual use, replace the key and other information in the code to run.# Compile example codeg++ -o sample ./cls/sample.cpp -std=c++11 -O2 -L/root/tencentcloud-cls-sdk-cpp-main -lclssdk -lcurl -lprotobuf -lssl -lcrypto -lboost_thread
error while....., see common errors../sample
statusCode:200 requestId: content: bodyBytes:49 header:key:Content-Length value:0 header:key:Date value:Wed, 20 Nov 2024 03:37:25 GMT header:key:X-Cls-Requestid value:e7329d6d-9a48-4091-bb0c-5cea8d1c6f48 header:key:X-Cls-Trace-Id value: header:key:x-cls-requestid value:
Variable | Type | Required | Description |
endpoint | String | Yes | |
accesskeyid | String | Yes | TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has appropriate SDK log upload permission. |
accessKeysecret | String | Yes | TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has appropriate SDK log upload permission. |
topic | String | Yes | Log topic ID info. |
#include "cls/producerclient.h"#include "cls/common.h"#include "cls/cls_logs.pb.h"#include "cls/logproducerconfig.pb.h"#include <string>#include <iostream>#include <unistd.h>#include <cstdlib>#include "cls/result.h"#include "cls/error.h"using namespace tencent_log_sdk_cpp_v2;using namespace std;class UserResult : public CallBack{public:UserResult() = default;~UserResult() = default;void Success(PostLogStoreLogsResponse result) override { std::cout << result.Printf() << std::endl; }void Fail(PostLogStoreLogsResponse result) override{std::cout << result.Printf() << std::endl;// std::cout<<result.loggroup_.ShortDebugString().c_str()<<std::endl;}};int main(){cls_config::LogProducerConfig config;// Fill in domain information. Completion guide: https://www.tencentcloud.com/document/product/614/18940?from_cn_redirect=1#.E5.9F.9F.E5.90.8D. See the Log upload via API Tab in the link for domain details.config.set_endpoint("ap-xxxxxxx.cls.tencentcs.com");// Fill in cloud API Key Information. For key information acquisition, please visit: https://console.tencentcloud.com/cam/capi// Please ensure the associated account of the key has appropriate log upload permissions. Permission configuration guide: https://www.tencentcloud.com/document/product/614/68374?from_cn_redirect=1#.E4.BD.BF.E7.94.A8-api-.E4.B8.8A.E4.BC.A0.E6.95.B0.E6.8D.AE// This example retrieves from environmental variables. Environment variable configuration guide: https://www.tencentcloud.com/document/product/614/113851?from_cn_redirect=1config.set_acceskeyid(getenv("TENCENTCLOUD_SECRET_ID"));config.set_accesskeysecret(getenv("TENCENTCLOUD_SECRET_KEY"));// Set the topic ID for log upload, replace with your Topic IDstd::string topic = "xxxxxxxxxxxxxxxxxxxxxxxxx";auto client = std::make_shared<ProducerClient>(config);auto callback = std::make_shared<UserResult>();client->Start();// Create a log objectcls::Log log;// Set the current time as the log timelog.set_time(time(NULL));// Construct the log data contentauto content = log.add_contents();// Set the key-value information of the log contentcontent->set_key("content");content->set_value("this my test");// Send logs and obtain returned resultsPostLogStoreLogsResponse ret = client->PostLogStoreLogs(topic, log, callback);if(ret.statusCode != 0){cout<<ret.content<<endl;}client->LogProducerEnvDestroy();return 0;}
Download file, decompress and rename (fit execute code)wget https://github.com/google/googletest/archive/release-1.5.0.tar.gztar -xzf googletest-release-1.5.0.tar.gzmv googletest-release-1.5.0 gtest
./autogen.sh.Run command./autogen.sh
./sample and Getting an Error./sample: error while loading shared libraries: libprotobuf.so.9: cannot open shared object file: No such file or directory
protobuf.so file by executing the following commands:whereis libprotobuf.so.9
cat /etc/ld.so.conf to check whether the path in step one exists.
ld.so.conf. Taking the above figure as an example, add /usr/local/lib to ld.so.conf.ldconfig
Feedback