Build error while compiling C file under Linux

Hi, I am trying to compile simple C programs on my computer, and when compiling I get similar messages from under the terminal [see image], indicating some kind of build error. I don’t know if this is a computer / stack memory problem (although I restarted the computer) or something else, but I am sure that I compiled C programs these days in the same way.

the code:

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

Conclusion:

/tmp/cconajAc.s: assembler messages: /tmp/cconajAc.s:9: Error: suffix or operands are not valid for `push '

Please tell me how to fix it!

EDITED: I just switched from a workstation from another computer lab, and everything works fine, without any assembly errors. My guess would be a mistake in the development tools installed on these computers in another laboratory. Probably now it works for me, although it would be interesting to know the source of the problem that I had on another computer.

+6
source share
5 answers

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

+1
source

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

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

Check if the 32-bit glibc headers are set.
Try this on ubuntu to install:
# apt-get install gcc-multilib

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

# gcc Wa,--32 else

# gcc -m32 --32

+1
source

In case this helps someone else, for me it seems to be caused by inconsistent toolchain components - I sometimes have to set up external dotfiles that change my PATH (to satisfy a convoluted build system, sigh). The assembler was /usr/bin/as , but gcc was some kind of ancient version.

0
source

Error: suffix or operands invalid for `push '

Test your sys architecture:

 # arch x86_64 # arch i386 

Or use this:

 #uname -m x86_64 

In the assembly: 32-bit (i386):

 pushl instruction ;notice the suffix is l 

64-bit (x86_64):

 pushq instruction ;notice the suffix is q 

Interestingly, your x86_64 sys-arch, it will raise this error when you use the 32-bit instruction. To solve this problem:

 #gcc -m32 -o test test.c 

Refer to When should the gm gm option be used?

0
source

what shell do you use when starting gcc?

Try switching to tcsh / csh. I got the same error in bash and switched the shell to tcsh.

0
source

All Articles