tschoonj / xraylib

A library for X-ray matter interaction cross sections for X-ray fluorescence applications
https://github.com/tschoonj/xraylib/wiki
Other
120 stars 55 forks source link

About compiling with gcc #23

Closed tontyoutoure closed 9 years ago

tontyoutoure commented 9 years ago

In wiki it is suggested to compile a C program like this

gcc `pkg-config --cflags libxrl` program.c `pkg-config --libs libxrl`

which makes I view this wiki or use history command literally everytime I compile my program. I think containing this sort of shell script could be helpful for those who compile their program with gcc:

#!/bin/bash
PARAMETERS=""
FILES=""
while [[ $# -gt 0 ]]; do
    if [[ $1 =~ ".c" ]]; then
        FILES=$(echo $FILES $1)
    elif [[ $1 == -o ]]; then
        PARAMETERS=$(echo $PARAMETERS $1)
        shift
        PARAMETERS=$(echo $PARAMETERS $1)
    else
        PARAMETERS=$(echo $PARAMETERS $1)
    fi
    shift
done
#gcc -L /usr/local/lib -I /usr/local/include/xraylib $FILES $PARAMETERS -lxrl
gcc `pkg-config --cflags libxrl` $FILES `pkg-config --libs libxrl` $PARAMETERS
tschoonj commented 9 years ago

There are a lot of ways for someone to compile a program: while your bash script may be suitable for your own purposes, more generally accepted solutions involve (at least on UNIX/Linux systems) the use of Makefiles, which offer interesting features that just cannot be emulated with a simple bash script.

If at some point you plan on distributing your program to a wider audience, I recommend you look into the GNU Autotools (Autoconf, Automake and Libtool, used by xraylib) or CMake. Both solutions have elegant ways to deal with pkg-config files like the one that is installed by xraylib.