summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md140
1 files changed, 140 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..29eb65b
--- /dev/null
+++ b/README.md
@@ -0,0 +1,140 @@
+C++11 Examples
+--------------
+
+This repository contains short examples of some
+of the modern (c++11/14) features in C++/STL.
+
+
+Regular Expressions
+-------------------
+
+Note:
+At the time of this writing (July-2015), not all compilers
+can handle all regex functionality (also depends on the
+used libstdc++ version).
+
+1. g++ v4.8 - regex_match works.
+ regex_search compiles but crashes.
+ regex_replace does not compile.
+
+2. g++ v4.9 - regex_{match,search,replace} compile and work.
+
+3. clang 3.5 (build based on the libstdc++ for g++-4.8) -
+ same issues as g++ v4.8.
+
+
+Building and testing
+====================
+
+run `make` to compile and run all tests.
+If all worked, the output should be:
+
+
+To build using a different compiler, run `make CXX=g++-4.8` (or
+`make CXX=clang++-3.5`, etc.).
+
+To clean run `make clean`.
+
+
+Compilation Errors - regex_replace
+==================================
+
+If you get the following compilation error when compiling `test-replace.cpp`:
+
+ test-replace.cpp:13:16: error: no matching function for call to 'regex_replace'
+ std::cout << std::regex_replace (s,e,"sub-$2");
+ ^~~~~~~~~~~~~~~~~~
+ /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/regex.h:2182:5: note:
+ candidate template ignored: could not match 'basic_string<type-parameter-0-1,
+ char_traits<type-parameter-0-1>, allocator<type-parameter-0-1> >' against
+ 'char const[7]'
+ regex_replace(const basic_string<_Ch_type>& __s,
+
+It means the compiler/libstdc does *not* support `regex_replace` function.
+Upgrade compiler/libstdc or don't use this function.
+
+
+Abort errors - regex_search
+===========================
+
+If you get the following error when running `test-search`:
+
+ $ ./test-search
+ terminate called after throwing an instance of 'std::regex_error'
+ what(): regex_error
+ Aborted (core dumped)
+
+It means the compiler/libstdc++ does *not* implement `regex_search`
+(it only contains the stub declarations).
+Upgrade compiler/libstdc or don't use this function.
+
+
+Runtime errors - wrong GLIBC versions
+=====================================
+
+If you get the following errors when running `test-replace`:
+
+ $ ./test-replace
+ ./test-replace: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ./test-replace)
+
+It means the program was compiled using a newer compiler (and non-default libstdc++)
+and requires additional settings to locate and use the correct one.
+
+To see which versions of the C++ standand library are available on your
+system, search for `libstdc++.so` file, like so (you might need to
+use `locate` instead of `mlocate`, depending on your sysystem):
+
+ $ mlocate libstdc++.so | grep '\.so$'
+ /usr/lib/gcc/mips-linux-gnu/4.3.5/libstdc++.so
+ /usr/lib/gcc/mips-linux-gnu/4.3.5/64/libstdc++.so
+ /usr/lib/gcc/mips-linux-gnu/4.3.5/n32/libstdc++.so
+ /usr/lib/gcc/x86_64-linux-gnu/4.4/libstdc++.so
+ /usr/lib/gcc/x86_64-linux-gnu/4.4/32/libstdc++.so
+ /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.so
+ /usr/lib/gcc/x86_64-linux-gnu/4.6/32/libstdc++.so
+ /usr/lib/gcc/x86_64-linux-gnu/4.8/libstdc++.so
+ /usr/lib/gcc/x86_64-linux-gnu/4.8/32/libstdc++.so
+ /usr/lib/gcc/x86_64-linux-gnu/4.8/x32/libstdc++.so
+ /usr/local/lib32/libstdc++.so
+ /usr/local/lib64/libstdc++.so
+
+Often, files in `/usr/lib/*` are automatically searched for and
+used by default, but the ones under `/usr/local/*` are not.
+
+1. check which `libstdc++` file is used by default:
+
+ $ ldd ./test-replace | grep libstdc
+ libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f8deb6b9000)
+
+2. check which version is the default library ('version' is checked
+ indirectly: The GNU standard library exports symbols that corresponds to the
+ implemented version):
+
+ $ nm -D /usr/lib/x86_64-linux-gnu/libstdc++.so.6 \
+ | grep GLIBCXX | sort -K3V,3 | tail -n1
+ 0000000000000000 A GLIBCXX_3.4.19
+
+ As shown, the default library implements upto version 3.4.19,
+ and the compiled binary requires version 3.4.20.
+
+ It is very likely that the libraries under `/usr/local/lib64/` provide this
+ newer version (on my system, they were compiled from source, and therefor
+ installed under `/usr/local`):
+
+ $ nm -D /usr/local/lib64/libstdc++.so.6 \
+ | grep GLIBCXX | sort -k3V,3 | tail -n1
+ 0000000000000000 A GLIBCXX_3.4.20
+
+3. Use `LD_LIBRARY_PATH` to load a different library than the default:
+
+ $ LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH ./test-replace
+
+4. To permanently include these libraries, consider adding a new file
+ to `/etc/ld.so.conf.d/` and re-run `ldconfig`.
+ NOTE: this might have adverse effect on your system, as the these
+ libraries will might override the system's default libraries -
+ only do so if you know what you're doing.
+
+ $ echo '/usr/local/lib64' | sudo tee /etc/ld.so.conf.d/local-lib64.conf
+ $ sudo ldconfig -v
+