C compiler for mac?

折月煮酒 提交于 2019-11-27 06:32:18

问题


I'm working through a text on linking, and wanted to work along with some examples in said text.

To better understand whats going on when I invoke the gcc driver, I was looking into doing all the compilation old-school by hand;

  • preprocessing using cpp
  • compiling with cc1
  • assembling with as
  • linking using ld

Unfortunately, on my Mac I don't seem to be able to reference cc1directly (no listing of cc1 in man). What are my options?


回答1:


Read some material about GCC internals. First the wikipage on GCC. Then, you could play with the MELT probe (you may want a Linux system to use it). Then read the GCC manual. And the GCC resource center

Use gcc -v -Wall to compile, it will show what cc1 is running (and -Wall is always useful). So try compiling with gcc -v -Wall hello.c -o helloworld.bin

the cc1 program don't sit in your PATH or in /usr/bin/ but -on my system- in /usr/lib/gcc/x86_64-linux-gnu/4.8/cc1

The command gcc -print-prog-name=cc1 will tell you which cc1 is used by your gcc. See GCC debugging options for more.

The preprocessing is now inside cc1.

The gcc program is just a driver, starting cc1 (which does most of the compiling work), then as, ld etc...

The MELT site contains some documentation, and some slides explaining GCC, which you could find interesting. MELT is a domain specific language to extend GCC.

See also the picture on http://starynkevitch.net/Basile/gcc-melt/cc1-internals.svg and the below picture

picture from http://starynkevitch.net/Basile/gcc-melt/gcc-MELT-inside.png, done by me, CC BY SA

The cc1 is producing a .s assembly file; the as (started by gcc) is transforming it into .o. The ld linker (started by gcc) will produce a library or an executable.

PS. I have a Linux system, but things are very similar on MacOSX.

reference on linking

A good book about linking is Levine's Linkers & loaders book.



来源:https://stackoverflow.com/questions/16694600/c-compiler-for-mac

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!