Skip to content

abhi3700/My_Learning-Cpp

Repository files navigation

My_Learning-Cpp

Learn C++ programming from past experienced programmers Java, Python, C.

Installation

Mac

Linux (via WSL)

How I use?

  • Editor (with suggestion): Sublime Text 3 (Crack version with setup), suggestion

  • Compiler

    • Testing: Use GNU compiler
      • gcc (via bash terminal) [for linux (Ubuntu)]
      • gcc (via Windows inside ST3) ctrl + b to build.

    NOTE: when you are not doing inside ST3, you don't have the facility of giving input via scanf/cin.

    • Production/Project: Use CMake (in linux (Ubuntu))

Tools

NOTES: Some important notes to be kept in mind before initiating Installation process:

  • For C++, I like Windows GUI & Linux. So, best of both world is Editor (in Windows Environment) & use the compiler (in Linux (Ubuntu)).
  • So, 2 methods:
    + M-1: ST3 (code suggestion from EasyClangComplete package) + CMake (in Ubuntu) [RECOMMENDED]
    + M-2: CLion. This is going to be heavy IDE, so it will take a lot of RAM space (3 GB approx.)
  • Along with std. libraries include this boost package in the directory of installed mingw-64 (gcc for windows) - "mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\lib\gcc\i686-w64-mingw32\8.1.0\include\c++"
  • gcc vs g++ differences
    + define gcc: GNU C Compiler g++: GNU C++ Compiler + gcc will compile: .c/.cpp files as C and C++ respectively. + g++ will compile: .c/.cpp files but they will all be treated as C++ files. + Also if you use g++ to link the object files it automatically links in the std C++ libraries (gcc does not do this). + gcc compiling C files has fewer predefined macros. + gcc compiling *.cpp and g++ compiling .c/.cpp files has a few extra macros.

Note: For c++ you should use g++.

  • Online IDE - https://www.onlinegdb.com/online_c++_compiler

  • Platforms:

    • Linux: GCC (sudo apt install gcc or sudo apt install gcc-8 or sudo apt install g++-8 >> prioritize b/w gcc versions like this: $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8), CMake
      • folders used by gcc for C:
     $ gcc -xc -E -v -
     Using built-in specs.
     COLLECT_GCC=gcc
     OFFLOAD_TARGET_NAMES=nvptx-none
     OFFLOAD_TARGET_DEFAULT=1
     Target: x86_64-linux-gnu
     Configured with: ../src/configure -v --with-pkgversion='Ubuntu 8.4.0-1ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
     Thread model: posix
     gcc version 8.4.0 (Ubuntu 8.4.0-1ubuntu1~18.04)
     COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
     /usr/lib/gcc/x86_64-linux-gnu/8/cc1 -E -quiet -v -imultiarch x86_64-linux-gnu - -mtune=generic -march=x86-64 -fstack-protector-strong -Wformat -Wformat-security
     ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
     ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/8/../../../../x86_64-linux-gnu/include"
     #include "..." search starts here:
     #include <...> search starts here:
     /usr/lib/gcc/x86_64-linux-gnu/8/include
     /usr/local/include
     /usr/lib/gcc/x86_64-linux-gnu/8/include-fixed
     /usr/include/x86_64-linux-gnu
     /usr/include
     End of search list.
     # 1 "<stdin>"
     # 1 "<built-in>"
     # 1 "<command-line>"
     # 31 "<command-line>"
     # 1 "/usr/include/stdc-predef.h" 1 3 4
     # 32 "<command-line>" 2
     # 1 "<stdin>"
     COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/
     LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../:/lib/:/usr/lib/
     COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
      + folders used by gcc for C++:
    
     $ gcc -xc++ -E -v -
     Using built-in specs.
     COLLECT_GCC=gcc
     OFFLOAD_TARGET_NAMES=nvptx-none
     OFFLOAD_TARGET_DEFAULT=1
     Target: x86_64-linux-gnu
     Configured with: ../src/configure -v --with-pkgversion='Ubuntu 8.4.0-1ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
     Thread model: posix
     gcc version 8.4.0 (Ubuntu 8.4.0-1ubuntu1~18.04)
     COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
     /usr/lib/gcc/x86_64-linux-gnu/8/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE - -mtune=generic -march=x86-64 -fstack-protector-strong -Wformat -Wformat-security
     ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/8"
     ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
     ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/8/../../../../x86_64-linux-gnu/include"
     #include "..." search starts here:
     #include <...> search starts here:
     .
     /usr/include/python3.6m/
     /usr/include/c++/8
     /usr/include/x86_64-linux-gnu/c++/8
     /usr/include/c++/8/backward
     /usr/lib/gcc/x86_64-linux-gnu/8/include
     /usr/local/include
     /usr/lib/gcc/x86_64-linux-gnu/8/include-fixed
     /usr/include/x86_64-linux-gnu
     /usr/include
     End of search list.
     # 1 "<stdin>"
     # 1 "<built-in>"
     # 1 "<command-line>"
     # 1 "/usr/include/stdc-predef.h" 1 3 4
     # 1 "<command-line>" 2
     # 1 "<stdin>"
     COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/
     LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../:/lib/:/usr/lib/
     COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
  • MinGW-64 (GNU, GCC for Windows)

    • Download from here
    • Also, available in Clion folder (available locally with me)
    • set the params during installation in the dialog screen:
      • Architecture: x86_64
      • Threads: posix (for Multithreading)
      • Exception: seh
    • Integrate with Sublime Text 3:
      • For C++: Create a new build system. File - "gcc-cpp.sublime-build"
       {
       	"shell_cmd": "g++ -std=c++17 ${file_path}/${file_name} -o ${file_path}/${file_base_name} && ${file_path}/${file_base_name}.exe"
       }
      
      • For C: Create a new build system. File - "gcc-c.sublime-build"
       {
       	"shell_cmd": "gcc -std=c11 ${file_path}/${file_name} -o ${file_path}/${file_base_name} && ${file_path}/${file_base_name}.exe"
       }
      
  • Clion (for Windows)

    • version:CLion 2019.3.5 x64
    • Installation: present in my laptop
    • Configure (File >> Settings): see the image
      • prerequisite installation: mingw-64 (for latest gcc & g++ .exe files), MinGW (32-bit) (Watch this video)
      • Image:

  • Sublime Text 3 ([RECOMMENDED] Editor)

    • For C++, ST3 is recommended for editing.
    • For compiling,
      • NOTE:
        • For just simple testing a file, use gcc (for C) or g++ (for C++).
        • For actual production, use cmake.
        • Here, Linting is done by fetching from a folder. E.g. mingw-64 (for C/C++): includes all required header files
      • GNU Compiler Collection (GCC):
        • Windows: mingw-64 [Use it for standard & custom libs (like Boost, etc...)]
        • Linux (Ubuntu): sudo apt install build-essential (includes: gcc, g++, make) [[Use it for standard]
      • CMake: [RECOMMENDED for a C/C++ Project]
        • Windows: Download & Install from here
        • Linux (Ubuntu):
            1. Download for linux platform from here
            1. $ tar -zxvf <download-file-name-with-ext> E.g.: $ tar -zxvf cmake-3.15.2.tar.gz
            1. $ cd cmake-3.15.2
            1. $ ./bootstrap
            1. $ make
            1. check if installed, cmake --version
    • To show where the function is defined:
      • just add mingw C++ folder (from C:\ drive i.e. installed directory) into the "OPEN FILES" tab on the left of ST3.
      • Then, on pointing the cursor on a function or subfunction => it shows the corresponding file where the function has been defined.
    • Packages
      • C++ Snippets: List of snippets Documentation. This includes C++11 snippets.
      • SublimeLinter: For linting, install this via: "Preferences >> Package Settings >> SublimeLinter >> Settings". Just replace with this (below):
       // SublimeLinter Settings - User
       {
       	"linters": {
       		"gcc": {
       			"disable": false,
       			"executable": ["gcc"],
       			"args": ["-fsyntax-only", "-std=c11"],
       			"I": [
       				// "${file_path}/include",
       				// "${folder}/include",
       				"/usr/local/include",
       				"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++",
       				"F:\\Coding\\github_repos\\cpp_libs"],
       			"excludes": [],
       			"working_dir": "${file_path}",
       		},
       		"g++": {
       			"disable": false,
       			"executable": ["g++"],
       			"args": ["-fsyntax-only", "-std=c++17"],
       			"I": [
       				// "${file_path}/include",
       				// "${folder}/include",
       				// "/usr/local/include",
       				"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++",
       				"F:\\Coding\\github_repos\\cpp_libs"],
       			"excludes": [],
       			"working_dir": "${file_path}",
       		},
       	},
       }
      
      • SublimeLinter-gcc: Install this after SublimeLinter package & then automatically, the linting starts. It fetches the header libraries from the mingw-64 or clang (whichever installed), provided in the settings page.
      • Append​Semi​Colon: Install this to append ; to the end of the code line using ctrl + ;. Also, to go to the new line & terminate the current line, use this: ctrl + shift + ;
    • Build system
      • One can use the default build system.
      • But it is recommended to use a custom build system. "Tools >> Build System >> New Build System" --> ctrl + s to save the file
        • C: "gcc-c.sublime-build"
         {
         	"shell_cmd": "gcc -std=c11 ${file_path}/${file_name} -o ${file_path}/${file_base_name} && ${file_path}/${file_base_name}.exe"
         }			
        
        • C++:"gcc-cpp.sublime-build"
         {
         	"shell_cmd": "g++ -std=c++17 ${file_path}/${file_name} -o ${file_path}/${file_base_name} && ${file_path}/${file_base_name}.exe"
         }
        
    • Snippet
      • cout
       <snippet>
       	<description>C/C++ - cout</description>
       	<content><![CDATA[
       std::cout << ${1:/*content*/} << "\n";
       ]]></content>
       	<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
       	<tabTrigger>coutendl</tabTrigger>
       	<!-- Optional: Set a scope to limit where the snippet will trigger -->
       	<scope>source.c++</scope>
       </snippet>		
      
      • int main()
       <snippet>
       	<description>C/C++ - int main</description>
       	<content><![CDATA[
       int main() {
       	${1:/*content*/}
      
       	return 0;
       }
       ]]></content>
       	<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
       	<tabTrigger>int main</tabTrigger>
       	<!-- Optional: Set a scope to limit where the snippet will trigger -->
       	<scope>source.c++</scope>
       </snippet>
      
  • CMake - Official, My notes

  • Using Boost library or custom library (via mingw-64)

    1. Download "Boost.zip" from here. Please ensure that the version is latest.

    2. [For Suggestion (in ST3 coding) & Compiling]

      • Suggestion for Editor: [Windows]--> Copy the "Boost" folder present inside, to the "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++"directory. Get started with Windows

      • Compiler: [Linux (Ubuntu)]-->
        • M-1: after extracting the "Boost" folder from downloaded file (.zip) just move to the directory "/usr/local/include/"
          • Go to extracted boost folder (say "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++",
          • open bash here,
          • Move folder to "/usr/local/include/": $ sudo cp -r ./x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/boost /usr/local/include
          • DONE! Now, you can start using GNU compiler: gcc, g++
        • [RECOMMENDED] M-2: Install as per the instruction here
          • Here also, doing the same thing as M-1, but boost-python also needs to be installed. Otherwise, boost-python installation would create a problem after following M-1 here in installing Boost.
    3. Now, write code in ST3 after the installation as per my sublime text guidelines

Education (Learn)

Repositories

Programming

Embedded System

  • A flight software and embedded systems framework - https://github.com/nasa/fprime
  • gRPC uses Protocol Buffer (data serialization 6 times faster than JSON)
    • About

      • an Interface Definition Language (IDL) for gRPC.
      • an Alternative to REST APIs and JSON
      • Why Consider Protobuf over XML or JSON?
        • When you serialize / encode a protobuf, it’s converted to a binary format => it’s significantly smaller than even JSON
        • Why not XML
        • less ambiguous with explicit data types
        • smaller (3-10 times smaller than XML)
        • faster (20-100 times faster than XML)
    • Github

    • Documentation

    • gRPC to JSON proxy generator

      • Google also create a gRPC ecosystem that includes a bunch of cool open source projects. One of these is the grpc-gateway, a gRPC to JSON proxy generator which generates a reverse-proxy server that translates RESTful JSON API into gRPC. So you can write your APIs using gRPC for internal communication between your components, but you can also host a thin wrapper that lets clients who want to communicate with it using familiar REST API calls do that as well.

Data Science

Maths

Machine Learning (ML)

Computer Vision

GUI

Others

Books

Blogs

Videos

Understanding

Talks

FAQs

Articles

IEEE

  • A Project-Based Curriculum for Teaching C++ Object-Oriented Programming