顯示具有 GCC 標籤的文章。 顯示所有文章
顯示具有 GCC 標籤的文章。 顯示所有文章

2015年10月13日 星期二

Linux C dev tips

errno.h strerror (errno) dlfcn.h void *handle; handle = dlopen("libkido.so", RTLD_LAZY); if (!handle) { fprintf(stderr, "%s \n", dlerror()); exit(EXIT_FAILURE); } int (*test)() = dlsym (handle,"test3"); if (!test) { fprintf(stderr, "%s \n", dlerror()); exit(EXIT_FAILURE); } int a; a=(*test)();

Linux C program tips

compile object files gcc -c 1.c --> automatically generate 1.o file link object files and generate binary file gcc -o app 1.o 2.o main.o build archives -- static library ar cr libkido.a 1.o 2.o main.o gcc -L . -lkido -o app build shared library gcc -c -fPIC 1.c --> automatically generate 1.o file gcc -shared -fPIC -o libkido.so main.o 1.o 2.o gcc -o app -L . -lkido -Wl,-rpath,./ <-- if rpath is not defined, LD_LIBRARY_PATH need to be defined in environment variable to have the binary locate library file

2015年1月23日 星期五

gcc object file linking

gcc -c xxx.c --> automatically generate xxx.o gcc yyy.c xxx.o --> automatically generate a.out You can use functions defined in xxx.c without including any header files in yyy.c

2012年8月6日 星期一

GLIBCXX_3.4.9 cannot be found

1:manually download prerequisites
required package info can be found at contrib/download_prerequisites
2:compile prerequisites with static library (enable static and disable shared )
GMP, MPFR, MPC
3:compile gcc with shared library (please refer options to gcc -v command)
4:use LD_PRELOAD to load proper libstdc++ to start program

debug: strings libstdc++ |grep GLIBC