Skip to content

Commit

Permalink
Rename the compiled library
Browse files Browse the repository at this point in the history
  • Loading branch information
dr8co committed Apr 12, 2024
1 parent d4baa9d commit 6a06f58
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
# set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -fsanitize=memory -fPIE -fno-optimize-sibling-calls -fno-omit-frame-pointer -g -O1")
endif ()

add_library(LiteString STATIC lite_string.h lite_string.c)
add_library(lite-string STATIC lite_string.h lite_string.c)

# Examples
add_subdirectory(examples)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ cmake --build build -j 4
Replace `Ninja` with `"Unix Makefiles"` or another generator if Ninja is not available.
The `-G` option can be omitted to use the default generator.

The library will be built as a static library named `libLiteString.a`, in the `build` directory.
The library will be built as a static library named `liblite-string.a`, in the `build` directory.

### Building Manually

To build the library, run the following commands:

```bash
gcc -c -O3 -std=c23 -o lite_string.o lite_string.c
ar rcs libLiteString.a lite_string.o
ar rcs liblite-string.a lite_string.o
```

`clang` can be used instead of `gcc` to compile the source code with Clang.
Expand All @@ -77,9 +77,9 @@ Compile the source code and link it with the library:

```bash
# C
gcc -std=c2x -O3 -o example example.c /path/to/libLiteString.a
gcc -std=c2x -O3 -o example example.c /path/to/liblite-string.a
# C++
g++ -std=c++20 -O3 -o example example.cpp /path/to/libLiteString.a
g++ -std=c++20 -O3 -o example example.cpp /path/to/liblite-string.a
```

Projects using CMake can link the library through the `target_link_libraries` command:
Expand Down
8 changes: 6 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
cmake_minimum_required(VERSION 3.28)

project(LiteString C CXX)

# C example
add_executable(word_stats word_stats.c)
target_link_libraries(word_stats LiteString)
target_link_libraries(word_stats lite-string)

# C++ example
add_executable(cheap_grep cheap_grep.cpp)
target_link_libraries(cheap_grep LiteString)
target_link_libraries(cheap_grep lite-string)
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The text file should not be bigger than 1MB.

```bash
# Compile and link the example
gcc -o word_stats word_stats.c /path/to/libLiteString.a -std=c2x
gcc -o word_stats word_stats.c /path/to/liblite-string.a -std=c2x
# Run the example
./word_stats blindtext.txt
```
Expand All @@ -25,7 +25,7 @@ gcc -o word_stats word_stats.c /path/to/libLiteString.a -std=c2x

```bash
# Compile and link the example
g++ -o cheap_grep cheap_grep.cpp /path/to/libLiteString.a -std=c++20
g++ -o cheap_grep cheap_grep.cpp /path/to/liblite-string.a -std=c++20
# Run the example
./cheap_grep -i "ipsum dolor" blindtext.txt
# The program can also read from standard input, when the file name is replaced with a hyphen
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
add_executable(testLiteString testLiteString.cpp)

# Link with gtest
target_link_libraries(testLiteString LiteString gtest gtest_main)
target_link_libraries(testLiteString lite-string gtest gtest_main)

include(GoogleTest)

Expand Down

0 comments on commit 6a06f58

Please sign in to comment.