Problem:
You use Docker, but working with it created lots of images and containers. You want to remove all of them to save disk space.
You use Docker, but working with it created lots of images and containers. You want to remove all of them to save disk space.
You want to use mmap()
from sys/stat.h
POSIX header to map a file for reading (not writing). You can’t find any simple bare example on the internet.
You want to use stat()
from sys/stat.h
POSIX header in order to get the size of a file.
You want to use stat()
from sys/stat.h
POSIX header to check if a file with a given name exists.
You want to create a binary DEB package of the msgpack C++ binding. However, there is no official DEB package available.
Problem:
On your Linux system, you want to check whether transparent hugepages are enabled on your system.
Solution:
It’s pretty simple:
cat /sys/kernel/mm/transparent_hugepage/enabled
You will get an output like this:
always [madvise] never
You’ll see a list of all possible options ( always
, madvise
, never
), with the currently active option being enclosed in brackets.madvise is the default.
You want to create a binary DEB package of libsodium. However, there is no official DEB package available for the latest version.
This is not the first tutorial on UML — there are hundreds of them publicly available on the internet. However, none of them seems to fulfill my requirements:
You want to use the mkdir()
function from the sys/stat.h
POSIX header, but you don’t know what the mode_t
argument should look like.
You intend to install LevelDB, but you don’t want to manually install & compile it as described here.
Instead, you just want to use the debian packaging system and some reproducible method of creating a DEB package from LevelDB.
Reasons for preferring not to compile & install manually could be:
The following C++ program uses boost::iostreams
to memory-map a file, read it’s content into a std::string
and print it to cout
.
It provides a minimal example of how to use the boost::iostreams
portable mmap
functionality.
//Compile like this: g++ -o mmap mmap.cpp -lboost_iostreams #include <boost/iostreams/device/mapped_file.hpp> #include <iostream> #include <string> using namespace std; using namespace boost::iostreams; int main(int argc, char** argv) { //Initialize the memory-mapped file mapped_file_source file(argv[1]); //Read the entire file into a string string fileContent(file.data(), file.size()); //Print the string cout << fileContent; //Cleanup file.close(); }
Also see A simple mmap() readonly example
This article describes a method of reading TAR archives (including .tar.gz and .tar.bz2) in C++ using Boost IOStreams.
You could use libtar for this, but the original version hasn’t been updated since 2003 and doesn’t provide you flexibility and insight to the internal structure of a TAR archive. Continue reading →
You can list all codecs supported by libavconv
(the library used by ffmpeg
/ avconv
) by using this command:
ffmpeg -codecs
If you don’t have the ffmpeg
executable simply use
avconv -codecs
Note that avconv and ffmpeg are essentially the same, but the projects split at some time and then re-merged. Starting from Ubuntu 15.04, ffmpeg is available in the repositories again, whereas previously, ffmpeg was replaced by avconv.
For details, see this StackOverflow thread and this detailed post about the ffmpeg/libav situation.
Using the libcurl easy API you want to download a file using HTTP GET. No extended features such as authentication shall be used.
The download result shall be stored in a std::string
Why trying to access your Android device using ADB, you encounter the following error:
error: insufficient permissions for device
You’re trying to compile something (e.g. using GCC) on Ubuntu, but you get an error message similar to this one:
/usr/bin/ld: error: cannot open crt1.o: No such file or directory /usr/bin/ld: error: cannot open crti.o: No such file or directory /usr/bin/ld: error: cannot open crtn.o: No such file or directory
You want to use the LLVM Gold linker plugin but LLVMgold.so can’t be found.
You want to compile and install libc++ (sometimes also named libcxx), but CMake complains with this error message
CMake Error at cmake/Modules/MacroEnsureOutOfSourceBuild.cmake:7 (message):
libcxx requires an out of source build. Please create a separate</em>
build directory and run 'cmake /path/to/libcxx [options]' there.
Call Stack (most recent call first):
CMakeLists.txt:24 (MACRO_ENSURE_OUT_OF_SOURCE_BUILD)
CMake Error at cmake/Modules/MacroEnsureOutOfSourceBuild.cmake:8 (message):
In-source builds are not allowed.
CMake would overwrite the makefiles distributed with Compiler-RT.
Please create a directory and run cmake from there, passing the path
to this source directory as the last argument.
This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
Please delete them.
Call Stack (most recent call first):
CMakeLists.txt:24 (MACRO_ENSURE_OUT_OF_SOURCE_BUILD)
You want to use git-svn
to clone a SVN repository, but you don’t want to clone the entire history (which can be quite slow) but only the latest revision.
You want to find out what the last revision number of a remote subversion repository is without cloning it (e.g. because cloning takes a looong time with subversion).