PDA

View Full Version : [C] Problema con GCC su Ubuntu


Vincenzo1968
29-12-2012, 18:50
Ho il classico hello world in C:

http://img59.imageshack.us/img59/8858/helloworldr.jpg

Se lo compilo/linko con CodeBlocks è tutto OK. Mi crea l'eseguibile e, lanciandolo da terminale, mi stampa a video "Hello World".

Se tento una build con GCC da terminale ottengo il seguente errore del linker:

"/usr/local/bin/ld: this linker was not configured to use sysroots"

http://img854.imageshack.us/img854/7622/erroregcc.jpg

Why? :confused:


http://img405.imageshack.us/img405/1582/impostazionicodeblocks.jpg

Braccop
29-12-2012, 19:11
hai installato build essentials dal package manager? pare cmq che quel compilatore in /usr/local non debba stare li', che sia stato installato a mano o da altro che non sono i repository ubuntu (codeblocks forse?)

fonte: http://ubuntuforums.org/showthread.php?p=11897544

Vincenzo1968
29-12-2012, 19:32
Si si ho installato build essentials ma il problema rimane.

Tutti i programmi(compreso CodeBlocks) li ho installati attraverso "Ubuntu Software Center" o apt-get dal terminale.
Non ho installato niente a mano.

:confused:

Vincenzo1968
29-12-2012, 19:44
ld fa parte del pacchetto binutils che ho installato tramite apt-get.


ld --version
ld di GNU (GNU Binutils) 2.23.1
Copyright 2012 Free Software Foundation, Inc.
Questo programma è software libero; siete liberi di ridistribuirlo secondo i termini
della GNU General Public License versione 3 o (a scelta) una versione più recente.
Questo programma non ha assolutamente alcuna garanzia.


LD(1) GNU Development Tools LD(1)



NAME
ld - The GNU linker

SYNOPSIS
ld [options] objfile ...

DESCRIPTION
ld combines a number of object and archive files, relocates their data
and ties up symbol references. Usually the last step in compiling a
program is to run ld.

ld accepts Linker Command Language files written in a superset of
AT&T's Link Editor Command Language syntax, to provide explicit and
total control over the linking process.

This man page does not describe the command language; see the ld entry
in "info" for full details on the command language and on other aspects
of the GNU linker.

This version of ld uses the general purpose BFD libraries to operate on
object files. This allows ld to read, combine, and write object files
in many different formats---for example, COFF or "a.out". Different
formats may be linked together to produce any available kind of object
file.

Aside from its flexibility, the GNU linker is more helpful than other
linkers in providing diagnostic information. Many linkers abandon
execution immediately upon encountering an error; whenever possible, ld
continues executing, allowing you to identify other errors (or, in some
cases, to get an output file in spite of the error).

The GNU linker ld is meant to cover a broad range of situations, and to
be as compatible as possible with other linkers. As a result, you have
many choices to control its behavior.

OPTIONS
The linker supports a plethora of command-line options, but in actual
practice few of them are used in any particular context. For instance,
a frequent use of ld is to link standard Unix object files on a
standard, supported Unix system. On such a system, to link a file
"hello.o":

ld -o <output> /lib/crt0.o hello.o -lc

This tells ld to produce a file called output as the result of linking
the file "/lib/crt0.o" with "hello.o" and the library "libc.a", which
will come from the standard search directories. (See the discussion of
the -l option below.)

...
CUT
...

SEE ALSO
ar(1), nm(1), objcopy(1), objdump(1), readelf(1) and the Info entries
for binutils and ld.

COPYRIGHT
Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free
Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the section entitled "GNU
Free Documentation License".



binutils-2.23.1 2012-11-13 LD(1)


:confused:

VICIUS
29-12-2012, 20:24
/usr/local/bin/ld? Ti sei compilato a mano binutils? Il messaggio di errore parla di una opzione sysroots che credo vada abilitata a compile time.

Vincenzo1968
29-12-2012, 21:03
Ciao Vicius,

ho provato a ricompilare binutils con l'opzione --sysroot ma non riesco a compilare perché mi da sempre quell'errore.

Ma come m'è saltato in mente di installare binutils dai sorgenti? Ubuntu Software Center è tanto comodo!

Adesso cancello manualmente i file da /usr/local/bin. Poi tramite il Software Center mi disinstallo e reinstallo GCC 4.7.2.

Se incasino tutto pazienza: formatto e reinstallo sistema operativo e cavoli vari.

Che bel sabato sera!

Braccop
29-12-2012, 21:10
ecco ora capisci perche' era superfluo farsi troppi problemi sui requisiti dei vari software sotto linux? :asd:

Vincenzo1968
29-12-2012, 21:33
Risoltoooooooooooooooooooooooooooooooooooooo!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

http://img802.imageshack.us/img802/708/risoltogcc.jpg

:yeah: :winner: :yeah:

Vincenzo1968
29-12-2012, 21:36
ecco ora capisci perche' era superfluo farsi troppi problemi sui requisiti dei vari software sotto linux? :asd:

Naaaaaaaaaa!!!!!!!

Si è trattato di un mio errore dovuto alla niubbaggine su Linux. D'ora in poi invece di smanettare sui sorgenti utilizzerò sempre Ubuntu Software Center o apt-get con i repository ufficiali di Ubuntu.

:D

Vincenzo1968
29-12-2012, 21:45
Per il moderatore: è possibile aggiunge "[RISOLTO]" al titolo del thread in modo da agevolare la ricerca della soluzione agli utenti in rete?

Spiego come ho fatto:

Da terminale ci si connette come superutente. Ci si sposta nella cartella /usr/local/bin":


cd /usr/local/bin


Si eliminano con il comando rm i seguenti file:


rm addr2line
rm ar
rm as
rm c++filt
rm elfedit
rm gold
rm gprof
rm ld
rm ld.bfd
rm ld.gold
rm nm
rm objcopy
rm ranlib
rm readelf
rm size
rm strings
rm strip


Tramite Ubuntu Software Center si disinstalla GCC 4.7
Sempre tramite Ubuntu Software Center si reinstalla GCC 4.7.

Fine :D

Vincenzo1968
30-12-2012, 16:47
ti consiglio altresì di installarti kate come editor...codeblocks a volte è proprio controintuitivo...

http://www.hwupgrade.it/forum/showpost.php?p=38783036&postcount=1

http://img59.imageshack.us/img59/8858/helloworldr.jpg

;) :D