dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-rpath-prev-override.dtest / main.c
1
2 // BUILD: $CC good.c -dynamiclib -install_name @rpath/libtest.dylib -o $BUILD_DIR/good/libtest.dylib
3 // BUILD: $CC bad.c -dynamiclib -install_name @rpath/libtest.dylib -o $BUILD_DIR/bad/libtest.dylib
4 // BUILD: $CC dyn.c -dynamiclib -install_name @rpath/libdynamic.dylib -o $BUILD_DIR/dir/libdynamic.dylib $BUILD_DIR/good/libtest.dylib -rpath @loader_path/../bad
5 // BUILD: $CC main.c $BUILD_DIR/good/libtest.dylib -DRUN_DIR="$RUN_DIR" -o $BUILD_DIR/dlopen-rpath-prev-override.exe -rpath @loader_path/good
6
7 // RUN: ./dlopen-rpath-prev-override.exe
8
9 // Processing of @rpath in dlopen()s always checks existing loaded images before using LC_RPATHs to find images on disk
10 //
11 // main links with @rpath/libtest.dylib found via -rpath @loader_path/good
12 // main dlopen()s libdynamic.dylib which links with @rpath/libtest.dylib and has LR_PATH to find it in bad/,
13 // but since it was already loaded from good/, that one should be re-used.
14
15 #include <stdio.h>
16 #include <dlfcn.h>
17
18 #include "test_support.h"
19
20 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
21 void* handle = dlopen(RUN_DIR "/dir/libdynamic.dylib", RTLD_LAZY);
22 if ( handle == NULL ) {
23 FAIL("dlerror(): %s", dlerror());
24 }
25
26 PASS("Success");
27 }
28