Basic Libraries for Linux
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
3rds
benchmark
fcache
fco
fconf
fev
fhash
flist
flock
flog
fmbuf
fnet
fthread_pool
ftime
include/flibs
tests
.Makefile.bench
.Makefile.doc
.Makefile.inc
.Makefile.libs
.Makefile.objs
.Makefile.targets
.Makefile.tests
.api_doxyfile
.clang-format
.gitignore
.gitmodules
.travis.yml
.ycm_extra_conf.py
ChangeLog.md
LICENSE
Makefile
README.md

README.md

Build Status GitHub license Platform GitHub release GitHub closed pull requests GitHub language count GitHub code size in bytes

Common Libraries (Linux Platform)

Lastest Release

See Here

ChangeLog

See change log

Library contains

Lib Name Description
flist Lockfree FIFO single-linked list in one-producer one-consumer scenario
fdlist Double-linked list
fhash Hash table
flock A wraper, which is safer and easier to use pthread condition
flog A High Performance Logging Library
fmbuf A light-weight ring-buffer
fconf A simple configuration file library
ftime Easy to create system timer
fthread_pool Simple thread pool, which is easy to use
fnet Wrap the system APIs, easy to use the networking api
fev Event framework, including buffer, networking, timer service...
fcache A simple cache with LRU
fco C coroutine. Notes: Legacy library, use it carefully
fut C Unit test framework. Notes: Migrated to fcunit
fmempool Thread-Cache memory pool. Notes: Migrated to skull-malloc
fpcap Pcap file conversion library. Notes: Migrated to fpcap

API Documents

See Wiki

Compile

git clone git@github.com:finaldie/final_libs.git flibs
cd flibs
git submodule update --init --recursive
make
make check
make valgrind-check

Benchmark

make bench
make bench-run

Flags

  • Change the compiler, such as using clang:
make CC=clang
  • Build shared library instead of static library:
make SHARED=true
  • Build debug version without any optimization parameters
make debug=true
  • Build 32bit libraries under 64bit platform
make BIT=32
  • Build in parallel
make -j4   # Adjust the number '4' according to the real cpu cores to speed up
the compile time
  • Skip building legacy library Currently, fco is defined as a legacy library, maybe it won't working well or lose support in some archs, use a specify macro to skip building it.
make FLIB_CFLAGS=-DFLIB_SKIP_LEGACY
  • Custom CFLAGS and LDFLAGS Sometimes, we want to define some different macros/compilation flags to control compiling/linking results, in flibs, instead of standard CFLAGS and LDFLAGS, we can use FLIB_CFLAGS and FLIB_LDFLAGS

Example (on 64bit platform)

  • Build 64bit static-link libraries
make -j4 && make -j4 check
  • Build 64bit dynamic-link libraries
make SHARED=true -j4 && make SHARED=true check
  • Install flibs to system After compilation, just call install target, to install flibs into system:
make install

notes: By default, the flibs will be installed in /usr/local/:

  • Headers in: /usr/local/include
  • Libraries in: /usr/local/lib If we want to change the location, maybe to /usr/, just run:
make prefix=/usr/ install

Use flibs in a Project

After installing flibs into system, basically we need few steps to use it:

  • Include the headers from the source file
  • Link the statis/dynamic library from the Makefile

Let's see an example Source file and Makefile, e.g. fhash:

// main.c
#include <stdlib.h>
#include <stdio.h>
#include <flibs/fhash.h>

int main(int argc, char** argv)
{
    // 1. Create string hash table
    fhash* tbl = fhash_str_create(0, FHASH_MASK_AUTO_REHASH);

    // 2. Set a key-value into table
    const char* key = "hello";
    fhash_str_set(tbl, key, "world");

    // 3. Get the value from table
    const char* value = fhash_str_get(tbl, key);
    printf("Key: %s, value: %s\n", key, value);

    // 4. Destroy the hash table
    fhash_str_delete(tbl);
    return 0;
}
# Makefile
all:
	gcc -Wall -g -O2 -o demo main.c -lflibs

Then Build and Run it:

final@ubuntu1404: ~/code/github/flibs/demo>make
gcc -Wall -g -O2 -o demo main.c -lflibs
final@ubuntu1404: ~/code/github/flibs/demo>./demo
Key: hello, value: world

Have fun :)