[ProtoBuf] 2. Environment configuration

v2-51ee98b05ce2ada206b744b6ff86cbd1_r
———————————— Every day without dancing is a disappointment to life.

PS: A lot of errors occurred during the installation. It may be that the performance of the lightweight cloud server is not enough. In addition, there are some configuration errors in the middle. Finally, a virtual machine is used. The solution to the problem is in the solution column

1. Install Protofbuf-Win

Download address: Release Protocol Buffers v21.11 protocolbuffers/protobuf (github.com)

image-20230520170513411

You can install it according to the version you need. I use Win64, so the version with the red box is installed.

2. Configure environment variables

  1. After downloading, decompress the compressed package in a certain location, and open the decompressed folder:

image-20230520170837110

  1. Enter the bin directory and copy the address in it

image-20230520170922805

  1. Search: "edit system environment variables" and enter

image-20230520171017675

Click on:image-20230520171102815

Next:image-20230520171201632

image-20230520171334285

3. Verify whether the addition is successful

  1. Open the terminal: shortcut key (Win + R), enter cmd to enter the terminal:

image-20230520171448625

  1. Click OK, enter the terminal, enter: protoc --version

  2. If the following results appear, the configuration is successful:

image-20230520171607866


4. Installation of Protobuf installation package under Linux

1. Download ProtoBuf

Before downloading ProtoBuf, you must install the dependent library: autoconf automake libtool curl make g++ unzip
If not installed, the installation command is as follows:

Ubuntu users choose:

sudo apt-get install autoconf automake libtool curl make g++ unzip -y

Centos users choose:

sudo yum install autoconf automake libtool curl make gcc_c++ unzip

After the above download is complete, continue to the next operation

ProtoBuf download address 21.11 path: Release Protocol Buffers v21.11 protocolbufs/protobuf (github.com)

If it is a C++ version, download the following file:image-20230520172749489

If you want to use it in various languages ​​(such as Java, C++, php, etc.), download the second file:image-20230520172855274

For better compatibility, we choose to download the second file, copy the link by right-clicking, enter in xshell: wget, and paste the link just now into xshell:image-20230520173113338

In fact, it is to download the compressed package and the code inside to the Linux environment. (Downloading will take some time.)

image-20230520173658847

Download completed.

2. Unzip the archive

Order:unzip protobuf-all-21.11.zip

image-20230520173838115

This directory after decompression is the source code content.

image-20230520173941510

Through the files inside, the program can be actually installed.

3. Install ProtoBuf

# 第⼀步执⾏autogen.sh,但如果下载的是具体的某⼀⻔语⾔,不需要执⾏这⼀步。
./autogen.sh
# 第⼆步执⾏configure,有两种执⾏⽅式,任选其⼀即可,如下:
# 1、protobuf默认安装在 /usr/local ⽬录,lib、bin都是分散的
./configure
# 2、修改安装⽬录,统⼀安装在/usr/local/protobuf下
./configure --prefix=/usr/local/protobuf
  1. enter./autogen.sh

image-20230520174227949

wait a moment~

image-20230520174301153

Finish.

  1. enter:./configure --prefix=/usr/local/protobuf

Then execute in sequence

make // 执⾏15分钟左右
make check // 执⾏15分钟左右
sudo make install
  1. enter:make

(The makefile was generated in the previous step, and then make can be performed. This step takes a long time, about 15 minutes)

image-20230520174642035

long time …

image-20230520180036526

  1. 输入make check

(This process is testing and is dispensable)

After execution make check, the following content can be executed sudo make install.

image-20230520180237842

If FAIL occurs in the test, that is, the following situation:

image-20230520210452117

The problem is that there are a lot of test cases in the test module. Some test cases have very strict requirements on the server environment and need to increase the swap partition, but it does not affect our subsequent normal use, so you can skip this step. If there is an error in the header file later, it means that the compiler version is relatively low, so we need to upgrade g++ to 8, and our normal installation method is up to 4.8.5. Therefore, other configuration methods are required.

  1. entersudo make install

image-20230521142706292

Finish.

4. Final additions

At this point, you need to recall that when executing configure, if you choose the first execution method, that is, ./configure, then you can use protobuf normally. If you choose the second execution method, that is, modify the installation directory, you also need to add some content in /etc/profile:

sudo vim /etc/profile
# 添加内容如下:
#(动态库搜索路径) 程序加载运⾏期间查找动态链接库时指定除了系统默认路径之外的其他路径
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib/
#(静态库搜索路径) 程序编译期间查找动态链接库时指定查找共享库的路径
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/protobuf/lib/
#执⾏程序搜索路径
export PATH=$PATH:/usr/local/protobuf/bin/
#c程序头⽂件搜索路径
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/protobuf/include/
#c++程序头⽂件搜索路径
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/protobuf/include/
#pkg-config 路径
export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/

The last step is to re-execute the /etc/profile file:

source /etc/profile

5. Check whether the installation is successful

Enter protoc --version to view the version, if it is displayed, the installation is successful.

cfy@139-159-150-152:~/install/protobuf-21.11$ protoc --version
libprotoc 3.21.11

5. Upgrade g++ to version 8

As mentioned above, if g++ is not upgraded to the latest version, the header file will report an error in subsequent operations, so let's configure the g++ compiler below

[Solution] Upgrade g++ to version 8_ Make progress every day~ Blog-CSDN Blog

Guess you like

Origin blog.csdn.net/NEFUT/article/details/130945050