Saturday, October 27, 2007

Linux programming

# gcc
gcc -o cahn cahn.c
gcc -o cahn cahn.c -lm /* mathematical library */

gcc -o p2 p2.cpp -lstdc++
g++ -o p2 p2.cpp
ldd p2

gcc -I/usr/openwin/include cahn.c /* include header files in subdirectories or nonstandard places by the -I flag */

gcc -o x11cahn -L/usr/openwin/lib x11cahn.c -lx11 /* compile and link a program "x11cahn" using the version of the library "libx11" found in the /usr/openwin/lib */

# Make a libaray
ar crv libfoo.a bill.o fred.o /* creat the archive and add object files to it */

ranlib libfoo.a /* no need in Linux */

gcc -o program program.c libfoo.a
gcc -o program program.c -L. -lfoo /* libfoo is in the current directory */

grep EXIT_ *.h /* search all the files in *.h for the string EXIT_ */

man gcc
info gcc


# Install GSL
./configure ; make; make check; make install

# Complie & Link
g++ -Wall -I/usr/local/include -c example.cpp
or
g++ -Wall -c example.cpp


g++ -L/usr/local/lib example.o -lgsl -lgslcblas
or
g++ -o example example.o -lgsl -lgslcblas

g++ -o example example.cpp -lgsl -lgslcblas

# GSL in baobab
gcc -o example -I/afs/isis/pkg/gsl/include example.c
-L/afs/isis/pkg/gsl//lib -lgsl -lgslcblas

export LD_LIBRARY_PATH=/afs/isis/pkg/gsl/lib:${LD_LIBRARY_PATH}
or put "export ~" at ~/public/.kshrc.personal

No comments: