#!/bin/sh # program # # dlopen(): # liba.so # # Expected: Undefined symbol in liba.so resolve to symbol in program. . ./test_setup # create liba.so cat > liba.c << EOI extern int b(); int a() { return b(); } EOI # build compile_lib -o liba.so liba.c # create program cat > program.c << EOI #include #include #include int b() { return 1; } int main() { void* liba; int (*a)(); liba = dlopen("./liba.so", RTLD_NOW | RTLD_GLOBAL); if (liba == NULL) { /* Fails expectedly. */ /* fprintf(stderr, "Error opening liba.so: %s\n", dlerror()); */ exit(117); } a = (int (*)())dlsym(liba, "a"); if (a == NULL) { fprintf(stderr, "Error getting symbol a: %s\n", dlerror()); exit(116); } return a(); } EOI # build compile_program_dl -o program program.c # run test_run_ok ./program 1