Skip to content

shawngao-org/c_tools

Repository files navigation

C Tools

Build Quality Gate Status Bugs Code Smells Coverage Duplicated Lines (%)

  • This project is a C language tool library.
  • This project will encapsulate some commonly used tools and functions.
  • This project has not been developed yet and many functions need to be added.

Build & Run

Requirements

  • CMake 3.27 or higher
  • Cmocka lib for develop and test

If you use Cmocka lib, you must change CMakeLists.txt:

if(CMAKE_SHARED_LIBRARY_SUFFIX STREQUAL ".so") # Linux
# ......
# Change to your real cmocka lib path.
elseif(CMAKE_SHARED_LIBRARY_SUFFIX STREQUAL ".dll") # Windows
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I\"C:/Program Files (x86)/cmocka/include\"")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L\"C:/Program Files (x86)/cmocka/lib\"")
endif()

Linux & macOS

# build and test
./build.sh
./build/tests

Windows

You need to install Cygwin(Recommended) or MingW to compile and run Windows programs.

If you want to use MingW to compile and run Windows programs, you need to change build.bat file.

# build and test
.\build.bat
.\build\tests.exe

Usage

Install library to system, or include library in your project

Install library to system

This method is not supported for Windows. Please see Include library in your project.

cd build
make install
# If Linux OS
sudo ldconfig

Include library in your project

Create lib directory in your project and create include directory in lib directory.

project_root/
├── CMakeLists.txt
└── lib/
    └── include/

Copy include/tools.h to lib/include/ directory.

Copy libraries to lib directory:

  • MacOS: build/libtools.dylib and build/libtools.1.0.0.dylib

  • Linux: build/libtools.so and build/libtools.so.1.0

  • Windows + Cygwin: build/libtools.dll.a and build/cygtools.dll

  • Windows + MingW: build/libtools.dll.a and build/libtools.dll

project_root/
├── CMakeLists.txt
└── lib/
    ├── include/
    │   └── tools.h
    ├── libtools.dll # Windows with MingW
    ├── cygtools.dll # Windows with Cygwin
    ├── libtools.dll.a # Windows
    ├── libtools.so # Linux
    ├── libtools.so.1.0 # Linux
    ├── libtools.dylib # macOS
    └── libtools.1.0.0.dylib # macOS

CMakeLists.txt example:

# tools_example replace with your project name
cmake_minimum_required(VERSION 3.27)
project(tools_example C)

set(CMAKE_C_STANDARD 11)

add_executable(tools_example main.c)

target_include_directories(tools_example PRIVATE lib/include)
target_link_directories(tools_example PRIVATE lib)
target_link_libraries(tools_example tools)

main.c example:

#include "tools.h"

int main() {
    hello();
    return 0;
}

If you run ./tools_example you will see:

Hello, World!

This means you can use this library for development.

Bugs

  • If you find a bug, please open an issue.
  • If you want to fix a bug or add a feature, please open a pull request.

Contributing

  • Fork this repository.
  • Make your changes.
  • Commit your changes.
  • Push your changes.
  • Create a pull request.
  • Wait for the maintainer to review your pull request.

Before submitting the code, please run the coverage check locally, and each item must be no less than 80%.

./build.sh
# run coverage check
./coverage.sh

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

CLion

CLion is an IDE that maximizes developer productivity in every aspect.

Special thanks to JetBrains for providing a free CLion license for open source and educational learning.

Logo

SonarQube Cloud

SaaS solution for high quality code. Simple, scalable, fast.

Special thanks to SonarSource for providing a free SonarQube Cloud Free Plan for open source.

Logo

Sourcery AI

Sourcery is an AI-powered code review tool that helps developers find bugs, vulnerabilities, and security issues in their code.

Special thanks to Sourcery for providing a free plan Sourcery AI for open source.

Logo

About

This project is a C language tool library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published