Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

史上最全编译evpp文档 #278

Open
gocpplua opened this issue Sep 8, 2021 · 1 comment
Open

史上最全编译evpp文档 #278

gocpplua opened this issue Sep 8, 2021 · 1 comment

Comments

@gocpplua
Copy link

gocpplua commented Sep 8, 2021

1. libevent

git clone https://github.com/libevent/libevent.git
git checkout release-2.1.8-stable
./autogen.sh
./configure
mkdir build && cd build
!!! 修改CMakeLists.txt,添加: set(CMAKE_POSITION_INDEPENDENT_CODE ON)
cmake ..  // 如果没有openssl,使用:cmake -DEVENT__DISABLE_OPENSSL=ON ..
make
sudo make install

不使用 set(CMAKE_POSITION_INDEPENDENT_CODE ON) 在编译evpp会出现下面错误:

/usr/bin/ld: //usr/local/lib/libevent.a(buffer.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
//usr/local/lib/libevent.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status

2. glog

方式一(我是使用这个方式)、
sudo apt-get install autoconf automake libtool

git clone https://github.com/google/glog.git
git checkout tags/v0.4.0   // 需要看0.4版本的Readme.md
./autogen.sh 
./configure
make 
sudo make install

方式二、
 sudo apt-get install libgoogle-glog-dev

3. boost --文档写着可选,实际上不是

使用apt-get直接进行安装: sudo apt-get install libboost-dev
  (这个安装成功了,但是使用失败,应该是包不全,没有boost_system与boost_thread等)
  
 1、下载安装包源码:
  wget -c "https://sourceforge.net/projects/boost/files/boost/1.77.0/boost_1_77_0.tar.gz"
 2、解压编译:
  tar -zxvf boost_1_77_0.tar.gz
  cd boost_1_77_0
  ./bootstrap.sh(不用加 --prefix=dir,会默认安装到/usr/local/目录下,成功会生成b2可执行文件)
  
  sudo ./b2 install(时间较长,20分钟) 

4. gflags (optional)

git clone https://github.com/gflags/gflags.git
git checkout tags/v2.2.2
mkdir build && cd build
cmake -DGFLAGS_NAMESPACE=google -DCMAKE_CXX_FLAGS=-fPIC ..
make
sudo make install

5. evpp

5.1 Download the source code of evpp
$ git clone https://github.com/Qihoo360/evpp
$ cd evpp
$ git checkout v0.7.0
$ git submodule update --init --recursive   // 不执行这个会出错:fatal error: concurrentqueue/concurrentqueue.h: No such file or directory
5.2 Compile and run unit tests.
$ mkdir -p build && cd build
$ cmake -DCMAKE_BUILD_TYPE=Debug ..
!!! 在 CMakeLists.txt中 删除
```
add_subdirectory (examples)  // 需要依赖gflags,如果我们不安装gflags就删除这个
add_subdirectory (benchmark) // 如果要编译的话,那么在benchmark/throughput/asio_from_chenshuo/handler_allocator.hpp中添加头文件#include <boost/noncopyable.hpp>
```
$ make   // 添加 -j 我的ubuntu 系统会崩溃
$ make test // 单元测试

或者直接执行

cd tools && ./release-build.sh // 脚本中的make package会出错(CPack Error: Cannot find rpmbuild), 除非我们执行: apt-get install rpm
5.3 Run the examples
$ cd evpp/build/bin
Run a HTTP client example:
$ ./example_http_client_request01
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0306 11:45:09.464159 13230 inner_pre.cc:37] ignore SIGPIPE
I0306 11:45:09.464896 13230 client01.cc:30] Do http request
I0306 11:45:09.493073 13231 client01.cc:14] http_code=200 [ok
]
I0306 11:45:09.493124 13231 client01.cc:16] HTTP HEADER Connection=close
I0306 11:45:09.493242 13231 event_loop.cc:103] EventLoop is stopping now, tid=140722561709824
I0306 11:45:09.993921 13231 event_loop.cc:93] EventLoop stopped, tid: 140722561709824
I0306 11:45:09.994107 13230 client01.cc:38] EventLoopThread stopped. 
Run a HTTP server example:
$ ./example_httpecho
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0306 12:15:31.703927 21228 inner_pre.cc:37] ignore SIGPIPE
I0306 12:15:31.706221 21228 http_server.cc:99] http server is running

And in another console:

$ curl "http://127.0.0.1:9009/echo" -d "Hello, world"
Hello, world
Run a TCP echo server example:
$ ./example_tcpecho

And in another console:

$ telnet 127.0.0.1 9099 
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

Here we can type any words and we will find it is responsed by our TCP echo server.

5.4 Other

If you want to compile evpp on Windows using Microsoft Visual Studio 2015, please see quick_start_windows_with_visualstudio.md

问题

1. ./example_http_client_request01 
./example_http_client_request01: error while loading shared libraries: libglog.so.0: cannot open shared object file: No such file or directory

实际上/usr/local/lib下面有的,那么执行 ldconfig


2. CPack Error: Cannot find rpmbuil
apt-get install rpm
@mynewcome
Copy link

赞,成功了!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants