g++
-c - object파일로 컴파일 할때 옵션
-o name -name.out으로 실행파일 빌드 옵션
-I - include( header파일) 위치 추가 옵션
-L 라이브러리 위치 -라이브러리 검색 위치 추가
-l 라이브러리 이름 -라이브러리 추가
-static -정적 링크로 빌드
-O0 -최적화 안함
-O1 -기본 최적화
-O2 - 더많은 최적화
-O2 - 더더 많은 최적화
-g -디버깅 정보 포함 (디버그 모드 빌드)
-std=c++11 - c++11을 사용
liba.a가 libb.a를 사용하고 있다면
g++ -o main main.cpp liba.a libb.a 순서로 적어줘야 한다.
g++ -o main main.cpp libb.a liba.a순서로 빌드하면 에러날 수 있음
c++ mysql연동
sudo apt-get install libmysqlclient-dev
header file - /usr/include/mysql/
libfile - /usr/lib/x86_64-linux-gnu/libmysqlclient.a
libssl, libcrypto설치
sudo apt-get install libssl-dev
/usr/lib/x86_64-linux-gnu/libssl.a
/usr/lib/x86_64-linux-gnu/libcrypto.a
hiredis(redis), Curl, libuv(UV)
github에서 다운로드 후 cmake로 빌드
cmake없으면 sudo apt-get install cmake
libzstd, libz필요할수도있음
/usr/lib/x86_64-linux-gnu/libzstd.a
/usr/lib/x86_64-linux-gnu/libz.a
실행시 동적링크파일 못찾는 경우
export LD_LIBRARY_PATH=[동적파일이 들어있는 디렉토리 경로]:$LD_LIBRARY_PATH
static 빌드시 아래와 같은 warning이 나와서 알아보는 중,..
warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
getaddrinfo는 동적 링크에 최적화되어 있으며, 정적 링크로 사용할 경우 여러 외부 의존성을 충족시키는 데 문제가 발생하기 때문에
다른 함수들은 상대적으로 단순하고 독립적인 경우가 많아 정적 링크로 사용할 때 문제가 발생하지 않는 경우가 많다.
glibc는 동적 라이브러리로 설계되었기 때문에, 대부분의 함수(특히 시스템 호출 및 네트워크 관련 함수)는 동적으로 로드되어야 해서 warning 발생
해당 함수를 호출해봐서 문제 없으면 그 시스템에선 괜찮음
그래도 dynamic 링크하는게 권장됨
555555554000-555555557000 r--p 00000000 103:0a 11419159 /home/yeongjae/Desktop/test/test_server/a.out
555555557000-555555567000 r-xp 00003000 103:0a 11419159 /home/yeongjae/Desktop/test/test_server/a.out
555555567000-55555556d000 r--p 00013000 103:0a 11419159 /home/yeongjae/Desktop/test/test_server/a.out
55555556d000-55555556e000 r--p 00019000 103:0a 11419159 /home/yeongjae/Desktop/test/test_server/a.out
55555556e000-55555556f000 rw-p 0001a000 103:0a 11419159 /home/yeongjae/Desktop/test/test_server/a.out
55555556f000-555555571000 rw-p 00000000 00:00 0
555555571000-5555555b3000 rw-p 00000000 00:00 0 [heap]
7ffff6a00000-7ffff6a28000 r--p 00000000 103:0a 16526467 /usr/lib/x86_64-linux-gnu/libc.so.6
7ffff6a28000-7ffff6bb0000 r-xp 00028000 103:0a 16526467 /usr/lib/x86_64-linux-gnu/libc.so.6
7ffff6bb0000-7ffff6bff000 r--p 001b0000 103:0a 16526467 /usr/lib/x86_64-linux-gnu/libc.so.6
7ffff6bff000-7ffff6c03000 r--p 001fe000 103:0a 16526467 /usr/lib/x86_64-linux-gnu/libc.so.6
7ffff6c03000-7ffff6c05000 rw-p 00202000 103:0a 16526467 /usr/lib/x86_64-linux-gnu/libc.so.6
7ffff6c05000-7ffff6c12000 rw-p 00000000 00:00 0
7ffff6e00000-7ffff6e9d000 r--p 00000000 103:0a 16526993 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.33
7ffff6e9d000-7ffff6fdd000 r-xp 0009d000 103:0a 16526993 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.33
7ffff6fdd000-7ffff706b000 r--p 001dd000 103:0a 16526993 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.33
7ffff706b000-7ffff7076000 r--p 0026b000 103:0a 16526993 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.33
7ffff7076000-7ffff7079000 rw-p 00276000 103:0a 16526993 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.33
7ffff7079000-7ffff707d000 rw-p 00000000 00:00 0
7ffff7117000-7ffff7127000 r--p 00000000 103:0a 16526772 /usr/lib/x86_64-linux-gnu/libm.so.6
7ffff7127000-7ffff71a6000 r-xp 00010000 103:0a 16526772 /usr/lib/x86_64-linux-gnu/libm.so.6
7ffff71a6000-7ffff71fe000 r--p 0008f000 103:0a 16526772 /usr/lib/x86_64-linux-gnu/libm.so.6
7ffff71fe000-7ffff71ff000 r--p 000e7000 103:0a 16526772 /usr/lib/x86_64-linux-gnu/libm.so.6
7ffff71ff000-7ffff7200000 rw-p 000e8000 103:0a 16526772 /usr/lib/x86_64-linux-gnu/libm.so.6
7ffff7200000-7ffff72b3000 r--p 00000000 103:0a 16551511 /usr/lib/x86_64-linux-gnu/libcrypto.so.3
7ffff72b3000-7ffff75e6000 r-xp 000b3000 103:0a 16551511 /usr/lib/x86_64-linux-gnu/libcrypto.so.3
7ffff75e6000-7ffff76b1000 r--p 003e6000 103:0a 16551511 /usr/lib/x86_64-linux-gnu/libcrypto.so.3
7ffff76b1000-7ffff770d000 r--p 004b0000 103:0a 16551511 /usr/lib/x86_64-linux-gnu/libcrypto.so.3
7ffff770d000-7ffff7710000 rw-p 0050c000 103:0a 16551511 /usr/lib/x86_64-linux-gnu/libcrypto.so.3
7ffff7710000-7ffff7713000 rw-p 00000000 00:00 0
7ffff7717000-7ffff771b000 r--p 00000000 103:0a 16527125 /usr/lib/x86_64-linux-gnu/libzstd.so.1.5.5
7ffff771b000-7ffff77c2000 r-xp 00004000 103:0a 16527125 /usr/lib/x86_64-linux-gnu/libzstd.so.1.5.5
7ffff77c2000-7ffff77cf000 r--p 000ab000 103:0a 16527125 /usr/lib/x86_64-linux-gnu/libzstd.so.1.5.5
7ffff77cf000-7ffff77d0000 r--p 000b7000 103:0a 16527125 /usr/lib/x86_64-linux-gnu/libzstd.so.1.5.5
7ffff77d0000-7ffff77d1000 rw-p 000b8000 103:0a 16527125 /usr/lib/x86_64-linux-gnu/libzstd.so.1.5.5
7ffff77d1000-7ffff77d3000 r--p 00000000 103:0a 16527124 /usr/lib/x86_64-linux-gnu/libz.so.1.3
7ffff77d3000-7ffff77e5000 r-xp 00002000 103:0a 16527124 /usr/lib/x86_64-linux-gnu/libz.so.1.3
7ffff77e5000-7ffff77eb000 r--p 00014000 103:0a 16527124 /usr/lib/x86_64-linux-gnu/libz.so.1.3
7ffff77eb000-7ffff77ec000 r--p 0001a000 103:0a 16527124 /usr/lib/x86_64-linux-gnu/libz.so.1.3
7ffff77ec000-7ffff77ed000 rw-p 0001b000 103:0a 16527124 /usr/lib/x86_64-linux-gnu/libz.so.1.3
7ffff77ed000-7ffff77f0000 r--p 00000000 103:0a 16526935 /usr/lib/x86_64-linux-gnu/libresolv.so.2
7ffff77f0000-7ffff77fa000 r-xp 00003000 103:0a 16526935 /usr/lib/x86_64-linux-gnu/libresolv.so.2
7ffff77fa000-7ffff77fc000 r--p 0000d000 103:0a 16526935 /usr/lib/x86_64-linux-gnu/libresolv.so.2
7ffff77fc000-7ffff77fd000 r--p 0000f000 103:0a 16526935 /usr/lib/x86_64-linux-gnu/libresolv.so.2
7ffff77fd000-7ffff77fe000 rw-p 00010000 103:0a 16526935 /usr/lib/x86_64-linux-gnu/libresolv.so.2
7ffff77fe000-7ffff7800000 rw-p 00000000 00:00 0
7ffff7800000-7ffff7826000 r--p 00000000 103:0a 16515687 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.21.2.39
7ffff7826000-7ffff78ab000 r-xp 00026000 103:0a 16515687 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.21.2.39
7ffff78ab000-7ffff7b85000 r--p 000ab000 103:0a 16515687 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.21.2.39
7ffff7b85000-7ffff7b8c000 r--p 00385000 103:0a 16515687 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.21.2.39
7ffff7b8c000-7ffff7e7a000 rw-p 0038c000 103:0a 16515687 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.21.2.39
7ffff7e7a000-7ffff7e7f000 rw-p 00000000 00:00 0
7ffff7e80000-7ffff7e86000 rw-p 00000000 00:00 0
7ffff7e86000-7ffff7ea4000 r--p 00000000 103:0a 16551512 /usr/lib/x86_64-linux-gnu/libssl.so.3
7ffff7ea4000-7ffff7f06000 r-xp 0001e000 103:0a 16551512 /usr/lib/x86_64-linux-gnu/libssl.so.3
7ffff7f06000-7ffff7f22000 r--p 00080000 103:0a 16551512 /usr/lib/x86_64-linux-gnu/libssl.so.3
7ffff7f22000-7ffff7f2c000 r--p 0009c000 103:0a 16551512 /usr/lib/x86_64-linux-gnu/libssl.so.3
7ffff7f2c000-7ffff7f30000 rw-p 000a6000 103:0a 16551512 /usr/lib/x86_64-linux-gnu/libssl.so.3
7ffff7f30000-7ffff7f34000 r--p 00000000 103:0a 16526600 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff7f34000-7ffff7f57000 r-xp 00004000 103:0a 16526600 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff7f57000-7ffff7f5b000 r--p 00027000 103:0a 16526600 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff7f5b000-7ffff7f5c000 r--p 0002b000 103:0a 16526600 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff7f5c000-7ffff7f5d000 rw-p 0002c000 103:0a 16526600 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff7f5d000-7ffff7f5f000 rw-p 00000000 00:00 0
7ffff7f5f000-7ffff7f62000 r--p 00000000 103:0a 11424371 /home/yeongjae/Desktop/test/test_server/hiredis/build/libhiredis.so.1.1.0
7ffff7f62000-7ffff7f71000 r-xp 00003000 103:0a 11424371 /home/yeongjae/Desktop/test/test_server/hiredis/build/libhiredis.so.1.1.0
7ffff7f71000-7ffff7f75000 r--p 00012000 103:0a 11424371 /home/yeongjae/Desktop/test/test_server/hiredis/build/libhiredis.so.1.1.0
7ffff7f75000-7ffff7f76000 r--p 00015000 103:0a 11424371 /home/yeongjae/Desktop/test/test_server/hiredis/build/libhiredis.so.1.1.0
7ffff7f76000-7ffff7f77000 rw-p 00016000 103:0a 11424371 /home/yeongjae/Desktop/test/test_server/hiredis/build/libhiredis.so.1.1.0
7ffff7f77000-7ffff7f7f000 r--p 00000000 103:0a 16527048 /usr/lib/x86_64-linux-gnu/libuv.so.1.0.0
7ffff7f7f000-7ffff7fa1000 r-xp 00008000 103:0a 16527048 /usr/lib/x86_64-linux-gnu/libuv.so.1.0.0
7ffff7fa1000-7ffff7faa000 r--p 0002a000 103:0a 16527048 /usr/lib/x86_64-linux-gnu/libuv.so.1.0.0
7ffff7faa000-7ffff7fab000 r--p 00032000 103:0a 16527048 /usr/lib/x86_64-linux-gnu/libuv.so.1.0.0
7ffff7fab000-7ffff7fac000 rw-p 00033000 103:0a 16527048 /usr/lib/x86_64-linux-gnu/libuv.so.1.0.0
7ffff7fbd000-7ffff7fbf000 rw-p 00000000 00:00 0
7ffff7fbf000-7ffff7fc3000 r--p 00000000 00:00 0 [vvar]
7ffff7fc3000-7ffff7fc5000 r-xp 00000000 00:00 0 [vdso]
7ffff7fc5000-7ffff7fc6000 r--p 00000000 103:0a 16526285 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
7ffff7fc6000-7ffff7ff1000 r-xp 00001000 103:0a 16526285 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
7ffff7ff1000-7ffff7ffb000 r--p 0002c000 103:0a 16526285 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
7ffff7ffb000-7ffff7ffd000 r--p 00036000 103:0a 16526285 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
7ffff7ffd000-7ffff7fff000 rw-p 00038000 103:0a 16526285 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
7ffffffde000-7ffffffff000 rw-p 00000000 00:00 0 [stack]
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]
dynamic 링킹으로 빌드한 경우 실행시 map
00400000-00401000 r--p 00000000 103:0a 11419135 /home/yeongjae/Desktop/test/test_server/myser
00401000-00a6a000 r-xp 00001000 103:0a 11419135 /home/yeongjae/Desktop/test/test_server/myser
00a6a000-00e82000 r--p 0066a000 103:0a 11419135 /home/yeongjae/Desktop/test/test_server/myser
00e82000-00eec000 r--p 00a82000 103:0a 11419135 /home/yeongjae/Desktop/test/test_server/myser
00eec000-011e6000 rw-p 00aec000 103:0a 11419135 /home/yeongjae/Desktop/test/test_server/myser
011e6000-011fb000 rw-p 00000000 00:00 0
011fb000-0123e000 rw-p 00000000 00:00 0 [heap]
7ffff7ff9000-7ffff7ffd000 r--p 00000000 00:00 0 [vvar]
7ffff7ffd000-7ffff7fff000 r-xp 00000000 00:00 0 [vdso]
7ffffffde000-7ffffffff000 rw-p 00000000 00:00 0 [stack]
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]
정적 링크로 빌드 한 경우 실행시 map