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.
- 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.
mkdir build && cd build
cmake .. -G "Ninja"
ninja
mkdir build && cd build
cmake .. -G "MinGW Makefiles"
cmake --build .
mkdir build && cd build
cmake ..
cmake --build .
Now we have executable output.
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
-
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
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
int *p = NULL;
*p = 1;
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