6

Hi I am trying to compile simple C programs in my computer and I get the similar msgs from under the terminal [see images] when compiling, stating some sort of assembly error. I dont know if this is a computer memory/stack issue (although I have restarted my computer) or anything else, but what I know for sure is that I have been compiling C programs these past days in the same manner.

Code:

   #include <stdio.h>
   main(){
      printf("hello");
   }

Output:

/tmp/cconajAc.s: Assembler messages: /tmp/cconajAc.s:9: Error: suffix or operands invalid for `push'

Please tell me how to fix this!

EDITED: I have just changed from workstation from another computer lab room and it works alright with no assembly errors whatsoever. My guess would be an error in the development tools installed in those computers in the other lab room. I guess for now this works for me although it would be interesting to know the source of the problem that I had in the other computer.

9
  • 1
    What is your command line for compiling? Commented Nov 4, 2012 at 22:22
  • 1
    Try gcc -m32 -o test test.c Commented Nov 4, 2012 at 22:24
  • 1
    Done, exact same error happens :( Commented Nov 4, 2012 at 22:24
  • 1
    From what I am reading, it appears that you were able to compile and run simple C language programs a day or two ago and now suddenly when you try to compile and run simple C language programs, you are now getting this error? What has changed between then and now? Commented Nov 4, 2012 at 22:27
  • 1
    whats the output of uname -a and gcc -v. Please add this (output of these commands) to your question above. Commented Nov 4, 2012 at 22:28

5 Answers 5

1

The error seems strange but try adding a return type to your main(): int main().

Sign up to request clarification or add additional context in comments.

1 Comment

@Ini I think he meant change your main to int main
1

Write in vi editor and save the file as "hello.c":

 #include <stdio.h>
 int main() {   printf("hello");   return 0; }

Check if you have the 32-bit glibc headers installed.
Try this in ubuntu to install:
# apt-get install gcc-multilib

Then try:
# gcc -m32 -o hello hello.c

# gcc Wa,--32 else

# gcc -m32 --32

Comments

0

In case it helps anyone else, for me, this appears to be caused by mismatched toolchain components -- I sometimes have to source external dotfiles that modify my PATH (in order to satisfy a convoluted build system, sigh). The assembler was /usr/bin/as, but gcc was some ancient version.

Comments

0

Error: suffix or operands invalid for `push'

Check your sys's architecture:

# arch
x86_64   

# arch
i386

Or use this:

#uname -m 
x86_64

In assembly: 32bit(i386):

pushl instruction  ;notice the suffix is l

64bit(x86_64):

pushq instruction  ;notice the suffix is q

I wonder your sys's arch is x86_64, It will raise this error when you use 32bit's instruction. To solve this problem:

#gcc -m32 -o test test.c

Refer to When should -m32 option of gcc be used?

Comments

0

which shell are you in while running gcc ?

Try switching to tcsh/csh. i was getting same error in bash and switched shell to tcsh.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.