Cocoyaxi: An Elegant and Efficient C++ Foundation Library
In the field of C++ development, there are many excellent libraries to choose from, and Cocoyaxi (abbreviated as co) is undoubtedly one of the best. It is a cross-platform C++ foundation library that supports various operating systems such as Linux, Windows, and Mac. Cocoyaxi was developed by Alvin starting in 2013, initially aimed at reducing third-party dependencies in C++ projects while improving development efficiency.
Core Features
Go-Style Coroutines
One of the most striking features of Cocoyaxi is its Go-style coroutines. It implements a coroutine mechanism similar to Golang, supporting multi-threaded scheduling with the default number of threads equal to the number of system CPU cores. Coroutines are peer-level and can be created anywhere. Additionally, it supports coroutine locks, coroutine synchronization events, and coroutine pools. In terms of memory usage, Cocoyaxi’s coroutines perform exceptionally well, with 10 million coroutines consuming only 2.8G of memory.
Networking Framework
Based on coroutines, Cocoyaxi provides a powerful networking framework. It supports system API hooks, allowing third-party networking libraries to be used directly within coroutines. This enables developers to easily implement efficient concurrent network applications without worrying about the complexities of underlying thread management.
Command Line Argument and Configuration File Parsing
The co/flag module of Cocoyaxi is a powerful library for command line argument and configuration file parsing. It supports passing parameters from the command line and configuration files, and can automatically generate configuration files. Moreover, integer-type parameter values can include units (such as k, m, g, etc.), making it convenient for developers to configure parameters.
High-Performance Logging Library

Logging is an indispensable part of any large project. Cocoyaxi provides a high-performance logging library that can meet the logging needs of various scenarios. It supports multiple logging levels and can flexibly configure the way and format of log output.
Unit Testing Framework
To ensure the stability and reliability of the code, Cocoyaxi includes a simple and easy-to-use unit testing framework co/unitest. Developers can easily write test cases to test the code. This helps to identify and fix issues promptly during the development process, improving code quality.
JSON Library
In modern software development, JSON is a very common data exchange format. Cocoyaxi provides an efficient JSON library that facilitates developers in parsing and generating JSON data.
Compilation and Installation
Cocoyaxi recommends using xmake as the build tool. Building with xmake is very simple; just execute the xmake command in the project root directory to build the default libco. If you need to build all projects, you can execute xmake -a. Additionally, Cocoyaxi also supports building with CMake.
Usage Example
Here is a simple example of using Cocoyaxi coroutines:
#include "co/co.h"
void my_coroutine() {
LOG << "Hello from coroutine!";
}
int main(int argc, char** argv) {
flag::init(argc, argv);
go(my_coroutine);
co::sleep(100); // Wait for the coroutine to finish
return 0;
}
In this example, we define a function named my_coroutine and use the go function to create it as a coroutine. Then, we use the co::sleep function to pause the main thread for 100 milliseconds, waiting for the coroutine to complete.
Conclusion
Cocoyaxi is a feature-rich and high-performance C++ foundation library. It offers a series of high-quality foundational components, including Go-style coroutines, a networking framework, a command line argument and configuration file parsing library, a high-performance logging library, a unit testing framework, and a JSON library. These features make Cocoyaxi a very powerful tool that can help developers improve development efficiency and simplify project development processes. If you are looking for an efficient and reliable C++ foundation library, Cocoyaxi is definitely worth trying.