分类: 嵌入式
2010-01-26 17:37:21
$ gcc -Wall -c file1.c file2.c file3.c |
$ ar rv libNAME.a file1.o file2.o file3.o |
$ gcc -Wall -c -fpic file1.c file2.c file3.c |
$ gcc -shared -o libNAME.so file1.o file2.o file3.o |
$ gcc -Wall -shared -fpic -o libNAME.so file1.c file2.c file3.c |
error while loading shared libraries: libhello.so: cannot open shared object file: No such file or directory |
export LD_LIBRARY_PATH= 动态库所在目录:$LD_LIBRARY_PATH |
$ ar tv archiveNAME |
int main(int argc, char *argv[]) { hello(); bye(); return 0; } |
void hello(void) { printf("hello!\n"); } |
void bye(void) { printf("good bye!\n"); } |
main.o: U bye U hello 00000000 T main hello.o: 00000000 T hello U puts bye.o: 00000000 T bye U puts |
$ file hello.o hello |
$ objcopy -O srec hello hello_srec $ file hello.o hello |
$ objdump -f hello hello_srec |
$ objdump -d hello.o |
$ readelf -h hello |
#include /* Computes the length of Collatz sequences */ unsigned int step (unsigned int x) { if (x % 2 == 0) { return (x / 2); } else { return (3 * x + 1); } } unsigned int nseq (unsigned int x0) { unsigned int i = 1, x; if (x0 == 1 || x0 == 0) return i; x = step (x0); while (x != 1 && x != 0) { x = step (x); i++; } return i; } int main (void) { unsigned int i, m = 0, im = 0; for (i = 1; i < 500000; i++) { unsigned int k = nseq (i); if (k > m) { m = k; im = i; printf ("sequence length = %u for %u\n", m, im); } } return 0; } |
$ gcc -Wall -c -pg collatz.c |
$ gcc -Wall -pg -o collatz collatz.o |
$ gprof ./collatz |