Oppure

Loading
24/07/13 11:15
MirkoDistefano
Salve a tutti. Sto cercando di imparare a programmare senza usare un IDE.
Ho appena scaricato e installato Gedit e GCC 4.2.1 come compilatore.
Pero mi sono bloccato in un passaggio.
Ho scritto il codice del classico Hello World in C++ e ho salvato come "hello.cpp" sul Desktop.
Per compilare vado sul terminale, mi sposto sul Desktop e scrivo:

gcc hello.cpp -o hello

Ma il terminale mi da questo errore:

cc1plus: error: /usr/local/include: Permission denied

Penso che si riferisca al fatto che non ho i permessi per farlo.
Da premettere che uso Mac OS X, programmo in C++ e di utenti ce ne solo uno, quello amministratore.

Grazie in anticipo :)
aaa
24/07/13 12:21
dmr
Per compilare devi utilizzare g++. Quindi: g++ hello.cpp -o hello.
aaa
24/07/13 12:41
MirkoDistefano
Avevo gia provato a fare così ma mi da sempre lo stesso errore.
Me lo da anche se compilo un programma in C utilizzando:
gcc hello.c -o hello
aaa
24/07/13 13:18
crybot
prova a modificare i permessi sul file da compilare con chmod o, in alternativa, utilizzare sudo.
aaa
24/07/13 13:23
MirkoDistefano
Forse ho risolto.
Ho eseguito il comando "su" e ho inserito la password dell'utente e ora quando compilo non mi da più quell'errore.
Me ne da un altro :)
Apro il terminale, mi metto nella cartella dove ce il file da compilare cioè il Desktop e inserisco il codice:
gcc hello.cpp -o hello
oppure
g++ hello.cpp -o hello
e mi da questo errore in entrambi i casi:
hello.cpp:1:2: error: invalid preprocessing directive #Include
hello.cpp: In function ‘int main()’:
hello.cpp:5: error: ‘cout’ is not a member of ‘std’

Il codice sorgente del file è:
---------------------------------
#Include <iostream>

int main()
{
std::cout << "Ciao, mondo \n";
return 0;
}
---------------------------------
il file si chiama "hello.cpp"

Come posso risolvere??
Posso dirvi che ho disistallato XCode perchè non sopporto gli IDE in generale e ho installato GCC da questo link:
github.com/kennethreitz/…

Grazie in anticipo :)
aaa
24/07/13 14:14
crybot
#include con la 'i' minuscola...
aaa
25/07/13 8:23
HeDo
questo è il prototipo di hello world funzionante C++


#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {

    cout << "Hello world!" << endl;

    return 0;
}

aaa
25/07/13 11:38
MirkoDistefano
Ragazzi ho aggiustato il codice e la compilazione mi è avvenuta con successo con il seguente codice:

g++ hello.cpp -o hello

Ora però ho provato a scrivere il codice di hello world in c:

#include <stdio.h>
int main(void) {
printf ("Hello world!\n";);
return 0;
}

Ho salvato nel Desktop e con il nome "hello.c"
Per compilare uso:

gcc hello.c -o hello

e mi da questo errore:

hello.c:1: error: expected identifier or ‘(’ before ‘{’ token
hello.c:1: error: stray ‘\’ in program
hello.c:1: error: stray ‘\’ in program
hello.c:1: error: stray ‘\’ in program
hello.c:1: error: stray ‘\’ in program
hello.c:1: error: stray ‘\’ in program
hello.c:2: error: stray ‘\’ in program
hello.c:2: error: stray ‘\’ in program
hello.c:2: error: stray ‘\’ in program
hello.c:2: error: stray ‘\’ in program
hello.c:2: error: stray ‘\’ in program
hello.c:2: error: stray ‘\’ in program
hello.c:2: error: stray ‘\’ in program
hello.c:3: error: stray ‘\’ in program
hello.c:3: error: stray ‘\’ in program
hello.c:3: error: stray ‘\’ in program
hello.c:3: error: stray ‘\’ in program
hello.c:4: error: stray ‘\’ in program
hello.c:4: error: stray ‘\’ in program
hello.c:4: error: stray ‘\’ in program
hello.c:4: error: stray ‘\’ in program
hello.c:4: error: stray ‘\’ in program
hello.c:4: error: stray ‘\’ in program
hello.c:4: error: stray ‘\’ in program
hello.c:5: error: stray ‘\’ in program
hello.c:6: error: stray ‘\’ in program
hello.c:6: error: stray ‘\’ in program
hello.c:8: error: stray ‘\’ in program
hello.c:8: error: stray ‘\’ in program
hello.c:8: error: stray ‘\’ in program
hello.c:8: error: stray ‘#’ in program
hello.c:8: error: stray ‘\’ in program
hello.c:8: error: stray ‘\’ in program
hello.c:8: error: stray ‘\’ in program
hello.c:8: error: stray ‘\’ in program
hello.c:13: error: stray ‘\’ in program
hello.c:13: error: stray ‘\’ in program
hello.c:14: error: stray ‘\’ in program
hello.c:14: error: stray ‘\’ in program
hello.c:14:10: warning: backslash-newline at end of file

Non capisco quale sia il problema
aaa