gcc: GNU C Compiler
g++: GNU C++ Compiler
g++: GNU C++ Compiler
The main differences:
- 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.
You can link the std C++ library in
gcc by passing -lstdc++ parameter.There are more differences between 'gcc' and 'g++' than only the standard libraries, so
gcc -lstdc++ will still not get you the same behavior as g++Tabela wersji gcc Link
Instalacja ubuntu WSI (sklep MS) na Windows10:
w Powershel:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
warto zainstalować HyperTerminal: https://hyper.is/
uruchamianie w terminalu:
wsl
zainstalowac visualcode
ze sciezki z lokalnym linuxem
C:\Users\eblzmrc\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs
wejsc na repo i dodac jako working directory projektu w visualu
Instalacja g++ na Debianie:
$ sudo apt-get update
$ sudo apt-get install build-essential manpages-dev
Instalacja nowszych wersji gcc na ubuntu LINK
Instalacja Eclipse na Ubuntui Link
(Fedora, RedHat,CentOs)
# yum groupinstall 'Development Tools'
To run this program, type:
Program
#include <iostream> using namespace std; int main(void) { cout << "It's me, your first program."; return 0; }
kompilowanie w określonym standardzie
$ g++ test.cpp -std=c++ 11
inne standardy:
-std=c++98, or-std=gnu++98(C++98 with GNU extensions)-std=c++11, or-std=gnu++11(C++11 with GNU extensions)-std=c++14, or-std=gnu++14(C++14 with GNU extensions), default mode for GCC 6.1 and above.-std=c++17, or-std=gnu++17(C++17 with GNU extensions), experimental.-std=c++2a, or-std=gnu++2a(C++2a with GNU extensions), experimental.
wygeneruje plik uruchamialny - uruchamiać ./a.out
a.out
Kompilatory online:
Coliru⁸ - uses GCC 8.1.0 (as of July 2018), offers link sharing and a basic text editor, it’s
simple but very effective.
• Wandbox⁹ - it offers a lot of compilers - for example, most of Clang and GCC versions
- and also you can use boost libraries. Also offers link sharing.
• Compiler Explorer¹⁰ - shows the compiler output from your code! Has many compilers
to pick from.
• CppBench¹¹ - run a simple C++ performance tests (using google benchmark library).
• C++ Insights¹² - it’s a Clang-based tool which does a source to source transformation.
It shows how the compiler sees the code, for example by expanding lambdas, auto,
structured bindings or range-based for loops.
Jeśli rozbite na kilka plików:
Główny plik main.cpp który uruchamia funkcję foo();
#include "test.h" int main() { void foo(); }
Plik test.h który zawiera prototyp funkcji foo() (deklaracja - zakończona średnikiem )
void foo();
Plik test.cpp który zawiera definicję (ciało) funkcji foo()
#include "test.h" void foo() { // ... }
Jak kompilować
-o tworzy wykonywalny (-o2 poziom optymalizacji) albo z obiektów albo od razu z cpp
g++ test.cpp main.cpp -o program
ewentualnie po kolei: Sss
-c tworzy obiekt *.o
g++ -c test.cpp -o test.o
g++ -c main.cpp -o main.o
i linkujemy:
g++ test.o main.o -o program
$ file program
dostajemy informacje o pliku (linux)
Makefile - patrz C
Link
CMAKE
1) stwórz:
CMakeLists.txt
zad3 - nazwa pliku uruchamialnego
zad3.c - plik z programem
dodaj kolejne plik *.c i *.h
cmake_minimum_required(VERSION 3.0) set(CMAKE_BUILD_TYPE Debug) project(zad3) add_executable( zad3 zad3.c )
zad3 - nazwa pliku uruchamialnego
zad3.c - plik z programem
dodaj kolejne plik *.c i *.h
2) polecenie
$ cmake . (kropka po spacji !!!)
tworzy plik MakeFile
3) polecenie
$ make
plik uruchamialny "zad3" stworzony
Przykład tworzenia plików
$ cmake . (kropka po spacji !!!)
tworzy plik MakeFile
3) polecenie
$ make
plik uruchamialny "zad3" stworzony
Przykład tworzenia plików
|
|
|
|
How do I generate symbolic information for gdb and warning messages?
The syntax is as follows C compiler:
The syntax is as follows C++ compiler:
cc -g -Wall input.c -o executableThe syntax is as follows C++ compiler:
g++ -g -Wall input.C -o executableHow do I generate optimized code on a Linux machine?
The syntax is as follows C compiler:
The syntax is as follows C++ compiler:
cc -O input.c -o executableThe syntax is as follows C++ compiler:
g++ -O -Wall input.C -o executableHow do I compile a C program that uses math functions?
The syntax is as follows when need pass the -lm option with gcc to link with the math libraries:
cc myth1.c -o executable -lmHow do I compile a C++ program that uses Xlib graphics functions?
The syntax is as follows when need pass the -lX11 option with gcc to link with the Xlib libraries:
g++ fireworks.C -o executable -lX11How do I compile a program with multiple source files?
The syntax is as follows if the source code is in several files (such as light.c, sky.c, fireworks.c):
C++ syntax is as follows if the source code is in several files:
cc light.c sky.c fireworks.c -o executableC++ syntax is as follows if the source code is in several files:
g++ ac.C bc.C file3.C -o my-program-name
The
Standard C++ library consists of 53 headers. Of these 53 headers, 13 constitute
the
Standard Template Library, or STL. These are indicated below with the
notation
(STL):
<algorithm>
(page 249) — (STL) for defining numerous templates that
implement
useful algorithms
<bitset>
(page 54) — for defining a template class that administers sets of bits
<complex>
(page 61) — for defining a template class that supports complex
arithmetic
<deque>
(page 274) — (STL) for defining a template class that implements a
deque
container
<exception>
(page 74) — for defining several functions that control exception
handling
<fstream>
(page 76) — for defining several iostreams template classes that
manipulate
exteral files
<functional>
(page 282) — (STL) for defining several templates that help
construct
predicates for the templates defined in <algorithm> (page 249) and
<numeric>
(page 345)
<iomanip>
(page 85) — for declaring several iostreams manipulators that take
an argument
<ios>
(page 86) — for defining the template class that serves as the base for
many
iostreams classes
<iosfwd>
(page 102) — for declaring several iostreams template classes before
they are
necessarily defined
<iostream>
(page 103) — for declaring the iostreams objects that manipulate the
standard
streams
<istream>
(page 105) — for defining the template class that performs
extractions
<iterator>
(page 293) — (STL) for defining several templates that help define
and
manipulate iterators
<limits>
(page 114) — for testing numeric type properties
<list>
(page 310) — (STL) for defining a template class that implements a list
container
<locale>
(page 119) — for defining several classes and templates that control
locale-specific
behavior, as in the iostreams classes
<map>
(page 320) — (STL) for defining template classes that implement
associative
containers that map keys to values
<memory>
(page 336) — (STL) for defining several templates that allocate and
free storage
for various container classes
<new>
(page 164) — for declaring several functions that allocate and free
storage
<numeric>
(page 345) — (STL) for defining several templates that implement
useful
numeric functions
<ostream>
(page 168) — for defining the template class that performs insertions
<queue>
(page 347) — (STL) for defining a template class that implements a
queue
container
<set>
(page 353) — (STL) for defining template classes that implement
associative
containers
<sstream>
(page 176) — for defining several iostreams template classes that
manipulate
string containers
<stack>
(page 368) — (STL) for defining a template class that implements a
stack
container
<stdexcept>
(page 184) — for defining several classes useful for reporting
exceptions
<streambuf>
(page 185) — for defining template classes that buffer iostreams
operations
<string>
(page 195) — for defining a template class that implements a string
container
<strstream>
(page 217) — for defining several iostreams classes that manipulate
in-memory
character sequences
<typeinfo>
(page 224) — for defining class type_info, the result of the typeid
operator
<unordered_map>
(page 371) — (STL) for defining template classes that
implement
unordered associative containers that map keys to values
<unordered_set>
(page 386) — (STL) for defining template classes that
implement
unordered associative containers
<utility>
(page 400) — (STL) for defining several templates of general utility
<valarray>
(page 225) — for defining several classes and template classes that
support
value-oriented arrays
<vector>
(page 403) — (STL) for defining a template class that implements a
vector
containerLink
WikiLink
Standard Library header files Link
PUB
PR
Csh
Google C++ Style Guide
Google protocol-buffers
Program studiów Informatycznych
Bartłomiej Filipek book: C++17 in Detail book
MeetUp: C++ User Group Krakow
C++ Team Blog MS
ciekawe artykuły z bloga MS:
C++ with Visual Studio 2019 and Windows Subsystem for Linux (WSL)
Linux Development with C++ in Visual Studio 2019: WSL, ASan for Linux, Separation of Build and Debug
Visual Studio Code C/C++ extension: May 2019 Update
Using VS Code for C++ development with containers