#Compiler requirements

The compilers required are as follows:


Coost recommends using xmake as the build tool.

#Install xmake

For Windows, mac and debian/ubuntu, you can go directly to the release page of xmake to get the installation package. For other systems, please refer to xmake’s Installation instructions.


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 -v or -vD to print more detailed compiling information:

xmake -v -a

#Compiling options

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

  • Windows
xmake f -a x86
xmake -v
  • Linux
xmake f -a i386
xmake -v

The -a in 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.

  • android
xmake f -p android --ndk=/path/to/android-ndk-r21
xmake -v
  • ios
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 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/
xmake -b log       # compile test/
xmake -b json      # compile test/
xmake -b rpc       # compile test/

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

#Install libco

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
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
make -j8