NayabSD
NayabSD

Reputation: 1120

'Compiler proper' command for C program

This is regarding the compilation steps mentioned in the Linux Journal article.

The C program was compiled using cpp, cc1, as and ld commands in that article. I am able to execute the steps with cpp, as and ld. But the cc1 throws error.

cpp hello_new_world.c -o hello_new_world.i

As I am unable to use cc1:

gcc -S hello_new_world.i -o hello_new_world.s
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -lc -lgcc -lgcc_s /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o hello_new_world.o -o hello_new_world
as hello_new_world.s -o hello_new_world.o

Even though I can do the compilation steps using gcc switches -E, -S and -c switches, is there any command which replaced cc1 in the latest gcc? Or how to do the compiler proper with the dedicated command?

$ cc1 hello_new_world.i -o hello_new_world.s

Command 'cc1' not found, did you mean:

  command 'cct' from deb proj-bin (5.2.0-1)
  command 'ccr' from deb codecrypt (1.8-1)
  command 'ccx' from deb calculix-ccx (2.11-1build2)
  command 'cc' from deb gcc (4:9.2.1-3.1ubuntu1)
  command 'cc' from deb clang (1:9.0-49~exp1)
  command 'cc' from deb pentium-builder (0.21ubuntu1)
  command 'cc' from deb tcc (0.9.27-8)
  command 'ccs' from deb unanimity (3.3.0+dfsg-2.1)

Upvotes: 2

Views: 284

Answers (1)

kaylum
kaylum

Reputation: 14046

cc1 is used internally by gcc and is not typically in your path. You can ask gcc where it is:

$ gcc -print-prog-name=cc1
/usr/lib/gcc/x86_64-linux-gnu/7/cc1

Or the whole command line used by gcc:

$ gcc -v hello.c |& grep cc1
 /usr/lib/gcc/x86_64-linux-gnu/7/cc1 -quiet -v -imultiarch x86_64-linux-gnu hello.c -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello -version -fstack-protector-strong -Wformat -Wformat-security -o /tmp/ccekuiEJ.s

Upvotes: 5

Related Questions