From d0b9d80445c82d435c1d9320715376338ae0b6c8 Mon Sep 17 00:00:00 2001 From: j842 Date: Mon, 26 May 2025 13:31:56 +1200 Subject: [PATCH] . --- build.sh | 3 +++ install_host.sh | 20 ++++++++++++++++++++ test/CMakeLists.txt | 14 ++++++++++++++ test/main.cpp | 20 ++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 build.sh create mode 100755 install_host.sh create mode 100644 test/CMakeLists.txt create mode 100644 test/main.cpp diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..b88c62b --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build -t cpp-httplib-builder . \ No newline at end of file diff --git a/install_host.sh b/install_host.sh new file mode 100755 index 0000000..57330e8 --- /dev/null +++ b/install_host.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +sudo apt install -y nlohmann-json3-dev wget curl cmake ninja-build + +if [ ! -f /usr/local/lib/libassert.a ]; then + git clone https://github.com/jeremy-rifkin/libassert.git + git checkout v2.1.5 + mkdir libassert/build + cd libassert/build + cmake .. -DCMAKE_BUILD_TYPE=Release + make -j + sudo make install + cd ../.. + rm -rf libassert +fi + +if [ ! -f /usr/local/include/httplib.h ]; then + wget https://raw.githubusercontent.com/yhirose/cpp-httplib/refs/heads/master/httplib.h + sudo mv httplib.h /usr/local/include/httplib.h +fi diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..bd4d90d --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.10) +project(cppstaticbuild) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Static build settings +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") + +include_directories(/usr/local/include) + +add_executable(main main.cpp) +target_link_libraries(main pthread) diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..ddec2a8 --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,20 @@ +#include + +#include +#include +#include + +int main() { + httplib::Client cli("https://ipinfo.io"); + auto res = cli.Get("/ip"); + + ASSERT(res->status == 200, "Failed to get IP"); + + nlohmann::json j; + j["ip"] = res->body; + j["status"] = res->status; + + std::cout << j.dump(4) << std::endl; + + return 0; +} \ No newline at end of file