- The
spinlocklib is implemented withPimplmechanism, so it doesn't expose the implementation details.
- To build everything you need to run this command
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build build- To install the
spinlocklib to/usr/local/you need to use this command
sudo cmake --install buildFYI: You have to run with sudo as this path is under root ownership
If you want to compile some code from console you should use these commands:
g++ main.cpp -lspinlock -std=c++17 -Wl,-rpath,/usr/local/lib
./a.outIf you want to use the Makefile to build your target you can use following examples
- Makefile
CXX = g++
CXXFLAGS = -std=c++17 -I/usr/local/include
LDFLAGS = -L/usr/local/lib -lspinlock
# For runtime, embed rpath so no need to set env vars
LDFLAGS += -Wl,-rpath,/usr/local/lib
TARGET = target
SRC = main.cpp
all: $(TARGET)
$(TARGET): $(SRC)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
clean:
rm -f $(TARGET)- Run the target
make
./targetIf you want to use the CMakeLists.txt to build your target you can use following examples
- CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(Target VERSION 1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(spinlock REQUIRED)
add_executable(target main.cpp)
set_target_properties(target PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "@loader_path/../lib;/usr/local/lib"
INSTALL_RPATH_USE_LINK_PATH TRUE
)
target_link_libraries(target PRIVATE spinlock)- Run the target
cmake -S . -B build
cmake --build build
./build/target