.
This commit is contained in:
parent
ad4d0ddfda
commit
d0b9d80445
20
install_host.sh
Executable file
20
install_host.sh
Executable file
@ -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
|
14
test/CMakeLists.txt
Normal file
14
test/CMakeLists.txt
Normal file
@ -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)
|
20
test/main.cpp
Normal file
20
test/main.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <httplib.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <libassert/assert.hpp>
|
||||
|
||||
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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user