Skip to content

Instantly share code, notes, and snippets.

@caiorss
Last active June 21, 2020 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caiorss/0557cd0fa1d5370723b015e443a7c036 to your computer and use it in GitHub Desktop.
Save caiorss/0557cd0fa1d5370723b015e443a7c036 to your computer and use it in GitHub Desktop.
Portable Linux Binaries - GLIBC Hell
cmake_minimum_required(VERSION 3.9)
project(Simple_Cmake_Project)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON)
#========== Targets Configurations ============#
add_executable( filesys filesys.cpp )
target_link_libraries( filesys stdc++fs)
# $ docker run -it --rm -v $PWD:/work -w /work phusion/holy-build-box-64:latest bash
FROM phusion/holy-build-box-64:latest
ENTRYPOINT [ "/hbb_exe/activate-exec", "bash" ]
#include <iostream>
#include <string>
#include <iterator>
#include <iomanip>
#include <filesystem>
namespace fs = std::filesystem;
template<typename Range, typename Function>
auto dotimes(size_t n, Range&& iterable, Function fun)
{
size_t i = 0;
auto it = fs::begin(iterable);
auto end = fs::end(iterable);
while(i < n && it != end ){
fun(it);
++it;
i++;
}
}
int main(){
std::cout << std::boolalpha;
std::cout << "\n ===== Listing directory /etc =====" << std::endl;
// Show first 10 files of directory /etc
dotimes(10, fs::directory_iterator("/etc"),
[](auto p){
auto path = p->path();
std::cout << std::left
<< std::setw(0) << path.filename().string()
<< " " << std::setw(35)
<< std::right << std::setw(40) << path
<< std::endl;
});
return EXIT_SUCCESS;
}
build:
cmake --config Debug -H. -B_build2
cmake --build _build2 --target
FROM alpine:latest
RUN apk add musl cmake make g++
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment