The compilers required are as follows:
Coost recommends using xmake as the build tool.
Run commands below in the root directory of co to build libco and other projects:
xmake -a # build all projects (libco, gen, test, unitest)
To enable HTTP and SSL features, build with the following commands:
xmake f --with_libcurl=true --with_openssl=true xmake -a
Xmake may install libcurl and openssl from the network, which may be slow.
-a in the command line means to build all projects in coost. If
-a is not added, only libco will be built by default. In addition, users may use
-vD to print more detailed compiling information:
xmake -v -a
Xmake provides the
xmake f command to configure compiling options. Note that multiple options must be set in a single xmake f command.
#Build debug version of libco
xmake f -m debug xmake -v
#Build dynamic library
xmake f -k shared xmake -v
#Build 32-bit libco
xmake f -a x86 xmake -v
xmake f -a i386 xmake -v
xmake f command means arch. The arch supported by different platforms may be different. Run
xmake f --help to see the details.
#set vs_runtime on Windows
On Windows, CO uses the MT runtime library by default, and users can use
xmake f to configure it:
xmake f --vs_runtime=MD xmake -v
#Android and IOS support
Coost can also be built on Android and IOS platforms, see Github Actions for details. Coost has not been tested on Android and IOS yet.
xmake f -p android --ndk=/path/to/android-ndk-r21 xmake -v
xmake f -p iphoneos xmake -v
#Build and run unitest code
co/unitest contains some unit test code, run the following commands to build and run the test program:
xmake -b unitest # build unitest xmake r unitest -a # run all unit tests xmake r unitest -os # run unit test: os xmake r unitest -json # run unit test: json
#Build and run test code
co/test contains some test code, add
xx.cc source file in the co/test directory or its subdirectories, and then run
xmake -b xx in the root directory of CO to build it.
xmake -b flag # compile test/flag.cc xmake -b log # compile test/log.cc xmake -b json # compile test/json.cc xmake -b rpc # compile test/rpc.cc xmake r flag -xz # test flag library xmake r log # test log library xmake r log -cout # also log to terminal xmake r log -perf # test performance of log library xmake r json # test json xmake r rpc # start rpc server xmake r rpc -c # start rpc client
#Build and use gen
xmake -b gen cp gen /usr/local/bin/ gen hello_world.proto
After building libco, you can use the
xmake install command to install libco to the specified directory:
xmake install -o pkg # install to pkg xmake i -o pkg # same as above xmake i -o /usr/local # install to /usr/local
#Install libco from xmake repo
xrepo install -f "openssl=true,libcurl=true" coost
izhengfan helped to provide the cmakefile:
- Only build libco by default.
- The library files are in build/lib directory, and the executable files are in build/bin directory.
- You can use BUILD_ALL to build all projects.
- You can use CMAKE_INSTALL_PREFIX to specify the installation directory.
#Build libco by default
mkdir build && cd build cmake .. make -j8
#Build all projects
mkdir build && cd build cmake .. -DBUILD_ALL=ON -DCMAKE_INSTALL_PREFIX=/usr/local make -j8 make install
#Enable HTTP and SSL features
To use HTTP or SSL features, libcurl, zlib, and openssl 1.1.0 or above must be installed.
mkdir build && cd build cmake .. -DBUILD_ALL=ON -DWITH_LIBCURL=ON -DWITH_OPENSSL=ON make -j8