C++ Shared Library Examples
Navigate to examples under the ouster-sdk source directory, which should contain several linux example folders building against the sdk library. To run each use the example.bash script.
Compiled In Linking example
- ::
This is a simple example on how to build and link a cpp project with the ouster_pcap library.
Bash script to run the example in a container:
#! /bin/bash set -e currentDir="$(cd $(dirname $0) && pwd)" baseDir=$currentDir/../.. tempDir="$(mktemp -d)" trap 'rm -rf $tempDir' EXIT trap 'echo \*\*\* ERROR on line: $LINENO exit_code: $?' ERR cd $baseDir docker build -f $currentDir/Dockerfile --iidfile=$tempDir/iid . docker run --rm $(cat $tempDir/iid)
Dockerfile:
FROM ubuntu:22.04 RUN apt-get update && apt-get install -y \ libeigen3-dev \ libtins-dev \ libpcap-dev \ libcurl4-openssl-dev \ git \ build-essential \ cmake \ zlib1g \ zlib1g-dev \ libglfw3-dev \ libpng-dev \ libflatbuffers-dev ENV WORKSPACE=/root COPY . $WORKSPACE/sdk/ COPY tests/pcaps/OS-2-32-U0_v2.0.0_1024x10.pcap examples/compiled_in_linking_example/CMakeLists.txt \ examples/compiled_in_linking_example/main.cpp $WORKSPACE/ RUN cd $WORKSPACE && \ cmake -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF . && \ cmake --build . --parallel 4 CMD $WORKSPACE/pcap_test /root/OS-2-32-U0_v2.0.0_1024x10.pcap
Shared Linking example
- ::
This is a simple example on how to build a shared library and link a cpp project with the ouster_pcap library.
Bash script to run the example in a container:
#! /bin/bash set -e currentDir="$(cd $(dirname $0) && pwd)" baseDir=$currentDir/../.. tempDir="$(mktemp -d)" trap 'rm -rf $tempDir' EXIT trap 'echo \*\*\* ERROR on line: $LINENO exit_code: $?' ERR cd $baseDir docker build -f $currentDir/Dockerfile --iidfile=$tempDir/iid . docker run --rm $(cat $tempDir/iid)
Dockerfile:
FROM ubuntu:22.04 RUN apt-get update && apt-get install -y \ git build-essential cmake \ curl zip unzip tar pkg-config \ python3 libxinerama-dev libxcursor-dev \ xorg-dev libglu1-mesa-dev flex bison \ libeigen3-dev ENV WORKSPACE=/root ENV INSTALL_DIR="/usr/local" RUN mkdir -p /opt/vcpkg && cd /opt && git clone https://github.com/microsoft/vcpkg.git \ && cd vcpkg && ./bootstrap-vcpkg.sh && ./vcpkg install "curl[core]" libtins \ glfw3 "glad[gl-api-33]" libpng flatbuffers zlib gtest openssl COPY . $WORKSPACE/ RUN cd $WORKSPACE && \ cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DBUILD_EXAMPLES=OFF \ -DBUILD_SHARED_LIBRARY=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF \ -DCMAKE_TOOLCHAIN_FILE=/opt/vcpkg/scripts/buildsystems/vcpkg.cmake . &&\ cmake --build . --parallel 4 --target install FROM ubuntu:22.04 RUN apt-get update && apt-get install -y \ libeigen3-dev \ libflatbuffers-dev \ git \ build-essential \ cmake ENV WORKSPACE=/root ENV INSTALL_DIR="/usr/local" COPY --from=0 $INSTALL_DIR $INSTALL_DIR COPY tests/pcaps/OS-2-32-U0_v2.0.0_1024x10.pcap examples/shared_linking_example/CMakeLists.txt \ examples/shared_linking_example/main.cpp $WORKSPACE/ RUN export CMAKE_PREFIX_PATH="$INSTALL_DIR" &&\ mkdir -p $WORKSPACE/build &&\ cd $WORKSPACE/build &&\ cmake $WORKSPACE && cmake --build . --parallel 4 CMD $WORKSPACE/build/pcap_test /root/OS-2-32-U0_v2.0.0_1024x10.pcap
Static Linking example
- ::
This is a simple example on how to build a static shared library and link a cpp project with the ouster_pcap library.
Bash script to run the example in a container:
#! /bin/bash set -e currentDir="$(cd $(dirname $0) && pwd)" baseDir=$currentDir/../.. tempDir="$(mktemp -d)" trap 'rm -rf $tempDir' EXIT trap 'echo \*\*\* ERROR on line: $LINENO exit_code: $?' ERR cd $baseDir docker build -f $currentDir/Dockerfile --iidfile=$tempDir/iid . docker run --rm $(cat $tempDir/iid)
Dockerfile:
FROM ubuntu:22.04 RUN apt-get update && apt-get install -y \ libeigen3-dev \ libtins-dev \ libpcap-dev \ libcurl4-openssl-dev \ git \ build-essential \ cmake \ zlib1g \ zlib1g-dev \ libglfw3-dev \ libpng-dev \ libflatbuffers-dev ENV WORKSPACE=/root ENV INSTALL_DIR="/usr/local" COPY . $WORKSPACE/ RUN cd $WORKSPACE && \ cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF . && \ cmake --build . --parallel 4 --target install FROM ubuntu:22.04 RUN apt-get update && apt-get install -y \ libeigen3-dev \ libtins-dev \ libpcap-dev \ libcurl4-openssl-dev \ git \ build-essential \ cmake \ libglfw3-dev \ zlib1g \ zlib1g-dev \ libpng-dev \ libflatbuffers-dev ENV WORKSPACE=/root ENV INSTALL_DIR="/usr/local" COPY --from=0 $INSTALL_DIR $INSTALL_DIR COPY tests/pcaps/OS-2-32-U0_v2.0.0_1024x10.pcap examples/static_linking_example/CMakeLists.txt \ examples/static_linking_example/main.cpp $WORKSPACE/ RUN export CMAKE_PREFIX_PATH="$INSTALL_DIR" &&\ mkdir -p $WORKSPACE/build &&\ cd $WORKSPACE/build &&\ cmake $WORKSPACE && cmake --build . --parallel 4 CMD $WORKSPACE/build/pcap_test /root/OS-2-32-U0_v2.0.0_1024x10.pcap