Skip to content

Instantly share code, notes, and snippets.

@Keith-S-Thompson
Created March 10, 2012 18:48
Show Gist options
  • Save Keith-S-Thompson/2012465 to your computer and use it in GitHub Desktop.
Save Keith-S-Thompson/2012465 to your computer and use it in GitHub Desktop.
dlsym test

This small test program is linked from a comment on this question on stackoverflow.com.

The program should compile and link without error, but dies with a segmentation fault if you try to run it.

Compile with

gcc -c dlsym_test.c

If you want to try running it (it will crash):

gcc dlsym_test.c -o dlsym_test -ldl && ./dlsym_test
#include <dlfcn.h>
#include <stddef.h>
int main(void) {
void *dl = dlsym(NULL, NULL);
return 0;
}
@vartikasingh
Copy link

➜ /Developer gcc -c c.c
➜ /Developer gcc -c c.c -o c -ldl
i686-apple-darwin11-llvm-gcc-4.2: -ldl: linker input file unused because linking not done
➜ /Developer

@Keith-S-Thompson
Copy link
Author

Fixed, thanks (dropped the -c)

@vartikasingh
Copy link

So, what do I need to do in my code to get rid of this error? I am building through Xcode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment