I am not able to compile a simple program using gcc

5,195

Solution 1

The options for gcc is '-m32' or '-m64' to generate code for a 32-bit or 64-bit environment. Not '--64'

Solution 2

There was a problem with my assembler.

When I run as --version

GNU assembler (GNU Binutils for Ubuntu) 2.22 Copyright 2011 Free Software Foundation, Inc. 
This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or later. 
This program has absolutely no warranty. This assembler was configured for a target of `arm-linux-gnueabi'.

My assembler target is mistakenly pointing towards the arm-linux-gnueabi (which was a cross compiler in my case). So, by re-installing binutils my problem was solved.

Share:
5,195

Related videos on Youtube

Aqib Butt
Author by

Aqib Butt

Updated on September 18, 2022

Comments

  • Aqib Butt
    Aqib Butt over 1 year

    Wrongly I have install ia32-libs but my host system is 64 bit. Now whenever i try to compile c file i get a message

    as: unrecognized option '--64'
    

    I have uninstall th ia32-libs but I am getting same error. then I have uninstall the gcc,g++,multilib and build-essenstial using purge command. again install these packages using apt-get command but again same error. When i run "which gcc" command on terminal i get "/usr/bin/gcc " and "which ld" output is "/usr/bin/ld". I guess both outputs are correct.

    When i run this command

    g++ -v hello hello.c
    

    then output is

    Using built-in specs.
    COLLECT_GCC=g++
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
    Target: x86_64-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
    Thread model: posix
    gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 
    COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
     /usr/lib/gcc/x86_64-linux-gnu/4.6/cc1plus -quiet -v -imultilib . -imultiarch x86_64-linux-gnu -D_GNU_SOURCE he.c -quiet -dumpbase he.c -mtune=generic -march=x86-64 -auxbase he -version -fstack-protector -o /tmp/ccIQSmoy.s
    GNU C++ (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (x86_64-linux-gnu)
        compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
    ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/include"
    include "..." search starts here:
    include <...> search starts here:
     /usr/include/c++/4.6
     /usr/include/c++/4.6/x86_64-linux-gnu/.
     /usr/include/c++/4.6/backward
     /usr/lib/gcc/x86_64-linux-gnu/4.6/include
     /usr/local/include
     /usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
     /usr/include/x86_64-linux-gnu
     /usr/include
    End of search list.
    GNU C++ (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (x86_64-linux-gnu)
        compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    Compiler executable checksum: 65b5171ac1bd7b3f07dbea6bdb24be3d
    COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
     as --64 -o /tmp/ccXDnoi3.o /tmp/ccIQSmoy.s
    **as: unrecognized option '--64'**
    

    Can you tell me how to solve this problem??

    • steeldriver
      steeldriver almost 10 years
      Can you add the outputs of which as and as --version as well please. Also your OS version (I'm guessing 12.04 based on the gcc version?)
    • Aqib Butt
      Aqib Butt almost 10 years
      which as output: "/usr/bin/as" as --version output: GNU assembler (GNU Binutils for Ubuntu) 2.22 Copyright 2011 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or later. This program has absolutely no warranty. This assembler was configured for a target of `arm-linux-gnueabi'. why target is pointing towards my cross compiler?? if this is a error how to correct it?? and, yes, OS is 12.04.
    • jhilmer
      jhilmer almost 10 years
      You could try to re install 'as' on your system with 'sudo apt-get install --reinstall binutils'
    • steeldriver
      steeldriver almost 10 years
      Please edit your question to add the new information. Yes somehow the arm-linux-gnueabi version of as has got installed as the default /usr/bin/as. How to fix it will depend why that occurred - if you don't actually use/need the ARM toolchain you could simply re-install the binutils package, which should overwrite it with the regular version. Otherwise you will need to do some more investigating - starting with whether /usr/bin/as is a simple file or a symbolic link.
  • Aqib Butt
    Aqib Butt almost 10 years
    How can i solve my problem?
  • Aqib Butt
    Aqib Butt almost 10 years
    i am not running --64 or -m64 as an option.
  • imbaer
    imbaer almost 10 years
    You probably have set it somewhere in your environmet. Check that with printenv | grep "\-\-64"
  • Aqib Butt
    Aqib Butt almost 10 years
    i got nothing on terminal when i run your command. I run printenv command and check all environments. --64 is not written anywhere.
  • Aqib Butt
    Aqib Butt almost 10 years
    There is a problem with my assembler. By re-installing binutils my problem is SOlved
  • Yves
    Yves almost 6 years
    remove all of paths containing the key word arm from the environment variable $PATH works for me too