erensayar / cpp-hello-world-apps

My C++ and C++ environments exploration trials...

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What's Repository For?

C and C++ environments exploration trials and notes repo.

This repo include C++ projects, that projects include C++ development tools like CMAKE, CPM, Conan.io, maybe Ninja someday... I'm trying cross compiling.


Notes

  • Cmake: Build generator, otomation tool. Cmake need a build tool.
  • Ninja: Build tool.
  • MinGw: Build tool. (For windows. It has gcc, gpp compiler)
  • Make: Build tool.
  • gcc: Compiler.

1. CMAKE Notes

1.1. Ninja

mkdir build && cd build
cmake .. -G "Ninja"
ninja

1.2. MinGw

mkdir build && cd build
cmake .. -G "MinGW Makefiles"
cmake --build .

1.3. Make (Linux)

mkdir build && cd build
cmake ..
cmake --build .

Now we have executable output.

Install Output To System

If outputs wants install to system we can use MAKE. (Example: We have downloaded the OpenCV source code. Then compile and built the source code. If want add to system we can use MAKE. Automatically add to system library.)

Enter these commands in order

make -j4 (4 : processor core number)
sudo make install

2. Compiler Notes

GPP

  • Usage 1 : Compiling and Running

    Compiling:

     g++ main.cpp
    

    Running:

     ./a.out
    
  • Usage 2 : Compiling and Running And Specified Output Type

     g++ -o main.sh main.cpp
    

    or

     g++ -o main.exe main.cpp
    

3. IDE Configurations Notes

VS Code

If you use windows, this config can be helpful

If libraries has warning underline, IDE can't see library than you can change include and compiler directory.

  • Mouse should be on the warning underline and select quick fix automaticly c_cpp_properties.json file create and then change like this example:

  • Add These Lines

      {
          "configurations": [
              {
                  "name": "Win32",
                  "includePath": [
                      "${workspaceFolder}/**",
                      "C:\\mingw64\\x86_64-w64-mingw32\\include"
                  ],
                  "defines": [
                      "_DEBUG",
                      "UNICODE",
                      "_UNICODE"
                  ],
                  "windowsSdkVersion": "10.0.22000.0",
                  "compilerPath": "C:\\mingw64\\bin\\gcc.exe",
                  "cStandard": "gnu17",
                  "cppStandard": "gnu++17",
                  "intelliSenseMode": "windows-gcc-x64"
              }
          ],
          "version": 4
      }        
    
  • You can maually create config file under this line:

      <workspace_dir>/.vscode/c_cpp_properties.json
    

4. Notes C/C++

Segmentation Fault Causative Conditions

Condition 1

int *p = NULL;
*p = 1;

Condition 2

char *str = "Foo"; // Compiler marks the constant string as read-only
*str = 'b'; // Which means this is illegal and results in a segfault

Dangling pointer points to a thing that does not exist anymore, like here:

char *p = NULL;
{
    char c;
    p = &c;
}
// Now p is dangling

5. Sources

About

My C++ and C++ environments exploration trials...


Languages

Language:CMake 93.3%Language:C++ 6.7%