clang이나 gcc를 사용하여 컴파일할 수 있는 바이너리가 있는데, 애플리케이션 디렉터리는 다음과 같습니다.
/app root dir
/bin
/<application>
/lib
/<application specific libs>
/syslib
/<system libs, e.g. boost libraries>
바이너리는 두 컴파일러 모두에 대해 다음 옵션을 사용하여 컴파일됩니다.
-Wl,-rpath,../syslib -ljansson -lsqlite3 -lboost_date_time -lboost_filesystem -lboost_log -lboost_program_options -lboost_thread -lboost_system
따라서 실행 중에 애플리케이션은 제공된 시스템 라이브러리를 찾을 수 있어야 합니다. 그런데 g++로 컴파일된 바이너리를 사용하면 특정 라이브러리를 찾을 수 없습니다. syslib 디렉토리에서 사용 가능한 라이브러리는 다음과 같습니다.
- libboost_date_time.so -> libboost_date_time.so.1.65.1
- libboost_date_time.so.1.65.1 libboost_filesystem.so ->
- libboost_filesystem.so.1.65.1 libboost_filesystem.so.1.65.1
- libboost_log.so -> libboost_log.so.1.65.1 libboost_log.so.1.65.1
- libboost_program_options.so -> libboost_program_options.so.1.65.1
- libboost_program_options.so.1.65.1 libboost_system.so ->
- libboost_system.so.1.65.1 libboost_system.so.1.65.1
- libboost_thread.so -> libboost_thread.so.1.65.1
- libboost_thread.so.1.65.1 libjansson.so -> libjansson.so.4.10.0
- libjansson.so.4 -> libjansson.so.4.10.0 libjansson.so.4.10.0
- libsqlite3.so -> libsqlite3.so.0.8.6 libsqlite3.so.0 ->
- libsqlite3.so.0.8.6 libsqlite3.so.0.8.6 libstdc++.so ->
- libstdc++.so.6.0.24 libstdc++.so.6 -> libstdc++.so.6.0.24
- libstdc++.so.6.0.24
g++ 컴파일된 바이너리를 실행하면 libboost_thread 라이브러리를 찾을 수 없습니다. clang++ 컴파일된 바이너리를 사용하는 동안에는 정상적으로 작동합니다. 바이너리 오류 출력:
./DGM: error while loading shared libraries: libboost_thread.so.1.65.1: cannot open shared object file: No such file or directory
g++ 컴파일된 바이너리에 대한 ldd 출력:
linux-vdso.so.1 => (0x00007fff7c90c000)
libjansson.so.4 => ../syslib/libjansson.so.4 (0x00007fea61f7b000)
libboost_date_time.so.1.65.1 => ../syslib/libboost_date_time.so.1.65.1 (0x00007fea61d69000)
libboost_filesystem.so.1.65.1 => ../syslib/libboost_filesystem.so.1.65.1 (0x00007fea61b4d000)
libboost_log.so.1.65.1 => ../syslib/libboost_log.so.1.65.1 (0x00007fea6186c000)
libboost_program_options.so.1.65.1 => ../syslib/libboost_program_options.so.1.65.1 (0x00007fea615e9000)
libboost_system.so.1.65.1 => ../syslib/libboost_system.so.1.65.1 (0x00007fea613e3000)
libstdc++.so.6 => ../syslib/libstdc++.so.6 (0x00007fea6105d000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fea60d51000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fea60b39000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fea6091b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fea60556000)
libnetsnmpagent.so.30 => /usr/lib/x86_64-linux-gnu/libnetsnmpagent.so.30 (0x00007fea602ec000)
libnetsnmp.so.30 => /usr/lib/x86_64-linux-gnu/libnetsnmp.so.30 (0x00007fea60012000)
libsqlite3.so.0 => ../syslib/libsqlite3.so.0 (0x00007fea5fd09000)
--> libboost_thread.so.1.65.1 => not found <--
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fea5fb01000)
/lib64/ld-linux-x86-64.so.2 (0x00007fea639f3000)
libwrap.so.0 => /lib/x86_64-linux-gnu/libwrap.so.0 (0x00007fea5f8f6000)
libperl.so.5.18 => /usr/lib/libperl.so.5.18 (0x00007fea5f56d000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007fea5f193000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fea5ef8e000)
libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fea5ed74000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007fea5eb3b000)
clang++ 컴파일된 바이너리에 대한 ldd 출력:
linux-vdso.so.1 => (0x00007fff0cdc5000)
libjansson.so.4 => ../syslib/libjansson.so.4 (0x00007fca078f9000)
libsqlite3.so.0 => ../syslib/libsqlite3.so.0 (0x00007fca075f1000)
libboost_date_time.so.1.65.1 => ../syslib/libboost_date_time.so.1.65.1 (0x00007fca073de000)
libboost_filesystem.so.1.65.1 => ../syslib/libboost_filesystem.so.1.65.1 (0x00007fca071c3000)
libboost_log.so.1.65.1 => ../syslib/libboost_log.so.1.65.1 (0x00007fca06ee2000)
libboost_program_options.so.1.65.1 => ../syslib/libboost_program_options.so.1.65.1 (0x00007fca06c5e000)
--> libboost_thread.so.1.65.1 => ../syslib/libboost_thread.so.1.65.1 (0x00007fca06a38000) <--
libboost_system.so.1.65.1 => ../syslib/libboost_system.so.1.65.1 (0x00007fca06832000)
libstdc++.so.6 => ../syslib/libstdc++.so.6 (0x00007fca064ac000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fca061a0000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fca05f89000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fca05d6a000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fca059a5000)
libnetsnmpagent.so.30 => /usr/lib/x86_64-linux-gnu/libnetsnmpagent.so.30 (0x00007fca0573b000)
libnetsnmphelpers.so.30 => /usr/lib/x86_64-linux-gnu/libnetsnmphelpers.so.30 (0x00007fca05539000)
libnetsnmp.so.30 => /usr/lib/x86_64-linux-gnu/libnetsnmp.so.30 (0x00007fca0525f000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fca0505a000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fca04e52000)
/lib64/ld-linux-x86-64.so.2 (0x00007fca08a94000)
libwrap.so.0 => /lib/x86_64-linux-gnu/libwrap.so.0 (0x00007fca04c47000)
libperl.so.5.18 => /usr/lib/libperl.so.5.18 (0x00007fca048be000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007fca044e4000)
libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fca042c9000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007fca04090000)
g++로 컴파일된 바이너리는 동일한 디렉토리에서 다른 부스트 라이브러리를 찾을 수 있기 때문에 이것이 매우 이상하다고 생각합니다.
요청에 따라 libboost_thread.so의 g++ 컴파일 바이너리의 strace 출력을 libboost_program_options.so와 비교했습니다.
libboost_program_options.so:
getcwd("/opt/dap/apps/DGM/bin", 128) = 22
mmap(NULL, 3016424, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f0a5558d000
mprotect(0x7f0a55666000, 2097152, PROT_NONE) = 0
mmap(0x7f0a55866000, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xd9000) = 0x7f0a55866000
close(3) = 0
open("../lib/tls/x86_64/libboost_program_options.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("../lib/tls/libboost_program_options.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("../lib/x86_64/libboost_program_options.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("../lib/libboost_program_options.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("../syslib/tls/x86_64/libboost_program_options.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("../syslib/tls/libboost_program_options.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("../syslib/x86_64/libboost_program_options.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("../syslib/libboost_program_options.so.1.65.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\233\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=667552, ...}) = 0
libboost_thread.so:
getcwd("/opt/dap/apps/DGM/bin", 128) = 22
mmap(NULL, 3175320, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f0a53a34000
mprotect(0x7f0a53b36000, 2097152, PROT_NONE) = 0
mmap(0x7f0a53d36000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x102000) = 0x7f0a53d36000
mmap(0x7f0a53d3b000, 920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f0a53d3b000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/tls/x86_64/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu/tls/x86_64", 0x7fffc0976a60) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/tls/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu/tls", 0x7fffc0976a60) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/x86_64/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu/x86_64", 0x7fffc0976a60) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
open("/usr/lib/x86_64-linux-gnu/tls/x86_64/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu/tls/x86_64", 0x7fffc0976a60) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu/tls", 0x7fffc0976a60) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/x86_64/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu/x86_64", 0x7fffc0976a60) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
open("/lib/tls/x86_64/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/tls/x86_64", 0x7fffc0976a60) = -1 ENOENT (No such file or directory)
open("/lib/tls/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/tls", 0x7fffc0976a60) = -1 ENOENT (No such file or directory)
open("/lib/x86_64/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64", 0x7fffc0976a60) = -1 ENOENT (No such file or directory)
open("/lib/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/lib/tls/x86_64/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/tls/x86_64", 0x7fffc0976a60) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/tls", 0x7fffc0976a60) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64", 0x7fffc0976a60) = -1 ENOENT (No such file or directory)
open("/usr/lib/libboost_thread.so.1.65.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
writev(2, [{"./DGM", 5}, {": ", 2}, {"error while loading shared libra"..., 36}, {": ", 2}, {"libboost_thread.so.1.65.1", 25}, {": ", 2}, {"cannot open shared object file", 30}, {": ", 2}, {"No such file or directory", 25}, {"\n", 1}], 10./DGM: error while loading shared libraries: libboost_thread.so.1.65.1: cannot open shared object file: No such file or directory
) = 130
exit_group(127) = ?
+++ exited with 127 +++