-
Notifications
You must be signed in to change notification settings - Fork 0
/
c++ text.txt
66 lines (37 loc) · 1.64 KB
/
c++ text.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
--------------- C++ ---------------
command -> action -> output
## 1 ##
g++ -c main.cpp -> compiles main.cpp -> main.o object file
NOTE:
- To include external header files out of standard path (/usr/include/) use:
g++ -c main.cpp -I<ext-lib-install-path>/include
- The include folder contains the .hpp files, which are the declarations for
the classes, functions, etc.
## 2 ##
g++ main.o -o my-app -> links the libraries -> my-app executable
NOTE:
- C++ dynamic libraries are of kind lib<name-of-lib>.so (libsqlite3.so).
Similarly static/archive are lib<name-of-lib>.a
- To link external library use:
g++ main.o -o my-app -l<name-of-lib> (without lib and, so or a).
- To link external library out of standard path (/usr/lib/) use:
g++ main.o -o my-app -L<ext-lib-install-path>/lib -l<name-of-lib>
## 3 ##
./my-app -> runs the executable -> output in console or external window, etc.
NOTE:
- If external dynamic library is not in standard path (/usr/lib/) use:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<ext-lib-install-path>/lib && ./my-app
- Generally, library files (.so and .a) are in lib folders, if not so adjust accordingly.
Ref:
* https://www.sfml-dev.org/tutorials/2.5/start-linux.php
* https://iq.opengenus.org/create-archive-library-in-cpp
* https://iq.opengenus.org/link-static-archive-file-in-gcc
* http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
PS:
On Windows .a extension is .lib and .so is .dll
#### Generate dynamic library ####
- g++ -fPIC -c library.cpp
- g++ -shared library.o -o liblibrary.so
#### Generate static library ####
- g++ -c library.cpp -o librarystat.o
- ar rcs liblibrarystat.a librarystat.o