CXX and ldd - yiliu30/yi GitHub Wiki
- Purpose: List memory-mapped files (including loaded libraries) for a running process.
- Steps:
- Find the Process ID (
PID):ps aux | grep <APP_NAME>
- List loaded libraries:
cat /proc/<PID>/maps | grep libSynMMM.so
- Find the Process ID (
- Output: Full path of the loaded library (e.g.,
/home/user1/qppp/p121/bin/latest/libSynMMM.so).
- Purpose: List open files by a process.
- Steps:
- Find the PID (as above).
- Filter for the library:
lsof -p <PID> | grep libSynMMM.so
- Output: Path of the loaded library.
- Purpose: Show memory mappings of a process.
- Steps:
- Find the PID (as above).
- Filter for the library:
pmap <PID> | grep libSynMMM.so
- Output: Memory address and path of the loaded library.
- Purpose: Trace library loading in real-time.
- Steps:
LD_DEBUG=libs <YOUR_APP> 2>&1 | grep libSynMMM.so
https://gist.github.com/yiliu30/9ceb9c073dcf6b17b21a411d745aca14
# https://bytes.usc.edu/cs104/wiki/gcc
# Compile a single program
g++ -Wall -g -std=c++17 test.cpp -o test
# Linking Multiple Files
gcc -o prog main.c sum.c
# Print all possible warning flags available to compile with
g++ --help=warnings
# Compile program using header files in ./include
# $(pwd) will expand to your current working directory
g++ -I /$(pwd)/include -Wall -g -std=c++17 test.cpp -o test
# Compile and optimize in parallel for helpful warnings about potential bugs
g++ -O2 -Wall -std=c++17 main.cpp -o maingcc [options] [input files] [output file]-
gcc file.c: Compilesfile.cand generates an executablea.out. -
gcc -o output file.c: Compilesfile.cand generates an executable namedoutput.
-
gcc -c file.c: Compilesfile.cto an object filefile.owithout linking.
-
gcc -o output file1.c file2.c: Compilesfile1.candfile2.c, and links them into a single executable namedoutput.
-
-O0: No optimization (default). -
-O1: Basic optimization. -
-O2: Further optimization. -
-O3: Maximum optimization. -
-Os: Optimize for size. -
-Og: Optimize for debugging.
-
-g: Generates debug information to be used by GDB (GNU Debugger).
-
-Wall: Enables most warning messages. -
-Werror: Treats warnings as errors.
-
-Dname: Defines a macroname. -
-Dname=value: Defines a macronamewith the valuevalue.
-
-I directory: Addsdirectoryto the list of directories to be searched for header files.
-
-L directory: Addsdirectoryto the list of directories to be searched for libraries. -
-l library: Links with the librarylibrary.
-
-std=c89: Conforms to the ISO C89 standard. -
-std=c99: Conforms to the ISO C99 standard. -
-std=c11: Conforms to the ISO C11 standard.
gcc -o myprogram main.cgcc -g -o myprogram main.cgcc -O2 -o myprogram main.cgcc -o myprogram main.c utils.cgcc -DDEBUG -I./includes -o myprogram main.cgcc -o myprogram main.c -L./lib -lmylib