Codice sorgente
Da LinuxPedia.
Il codice sorgente o comunemente chiamato anche sorgente è definito come l'insieme delle istruzioni utilizzate per creare un programma. Il codice sorgente di un linguaggio di programmazione ha lo scopo di essere eseguito e far compiere al computer le azioni da esso descritte. Questo viene fatto in modo diverso a seconda che il linguaggio sia interpretato o compilato.
Se il linguaggio è interpretato il codice sorgente viene letto, interpretato ed eseguito dall'apposito interprete del linguaggio.
Quando un linguaggio di programmazione è compilato, il codice sorgente viene trasformato in un file eseguibile attraverso alcune fasi. Le fasi che portano da un codice sorgente ad un file eseguibile vengono solitamente suddivise tra vari strumenti, a grandi linee: il preprocessore, il compilatore e il linker.
Il software, per essere definito software libero deve mettere a disposizione dei propri utenti i sorgenti in modo da garantire le libertà previste dalla licenza GPL.
Contents |
Esempio di Codice Sorgente
Esempio di codice sorgente
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
Installazione di un programma dal Codice Sorgente
La quasi totalità dei programmi GNU/Linux è distribuito sotto forma di codice sorgente. L'installazione di questi programmi avviene attraverso la compilazione e successiva installazione di tutti i files eseguibili. Vediamo come fare per installare tali programmi.
Una volta scaricato il Codice sogente dobbiamo procedere alla sua decompressione, possiamo procedere sia per via grafica con Ark e programmi simili, ormai di default in ogni distribuzione oppure tramite shell con tar.
Una volta che l'archivo è stato decompresso dobbiamo aprire una shell e digitare quanto segue:
$ cd /percorso/del/codice/sorgente/ $ ./configure $ make $ sudo make install
l'ultimo comando può essere sostituito con
$ su # make install
Note
Quando si configura un sorgente con il comando ./configure si assisterà ad un elenco di questo genere:
12:37 linux-pc:~/Desktop/msn > ./configure
checking for prefix by checking for wish... /usr/bin/wish
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking tcl build dir... ./configure: line 2842: locate: command not found
using tcl library in /usr/lib
checking tk build dir... using tk library in /usr/lib
checking for main in -lstdc++... yes
checking how to run the C preprocessor... gcc -E
checking for X... libraries , headers
checking for gethostbyname... yes
checking for connect... yes
checking for remove... yes
checking for shmat... yes
checking for IceConnectionNumber in -lICE... yes
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for png_read_info in -lpng... yes
checking png.h usability... yes
checking png.h presence... yes
checking for png.h... yes
checking for jpeg_CreateDecompress in -ljpeg... yes
checking jpeglib.h usability... yes
checking jpeglib.h presence... yes
checking for jpeglib.h... yes
checking jerror.h usability... yes
checking jerror.h presence... yes
checking for jerror.h... yes
checking for ftello... yes
checking for fseeko... yes
checking for getpt... yes
checking for strcasestr... yes
checking for memmem... yes
checking for dlopen... no
checking for pthread_create in -lpthread... yes
checking if mmx should be used... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating ./utils/linux/capture/config.h
compile time options summary
============================
X11 : yes
Tcl : 8.4
TK : 8.4
DEBUG : no
STATIC : no
In cui vengono verificate tutte le dipendenze di cui il programma ha bisogno, le dipendenze più importanti necessaria per la compilazione sono i compilatori, la cui mancanza viene segnalata durante questo controllo. Ecco un esempio:
12:43 linux-pc:~/Desktop/msn > ./configure checking for prefix by checking for wish... /usr/bin/wish checking for gcc... no checking for cc... no checking for cc... no checking for cl... no configure: error: no acceptable C compiler found in $PATH See `config.log' for more details.
In ogni caso in cui è mancante una dipendenza il ./configure si bloccherà impedendo di compilare, sarà quindi necessario procedere all'installzione dei programmi mancanti necessari, in questo caso:
- gcc
- cc
- cl
Questi compilatori si possono facilmente installare. Su Ubuntu, Debian e derivate con il comando:
$ sudo apt-get install build-essential
Su OpenSUSE attraverso Yast, selezionando il modello: Sviluppo di base

