Mac OS 下的 gcc gdb

來源:互聯網
上載者:User

標籤:

好久沒有寫c了,今天和老婆大人一起做了一下微軟的網上編程題。發現忘了好多。

由於有執行階段錯誤,所以想用gdb調試一下,發現沒有gdb,遂使用homebrew安裝,結果安裝出錯。後來發現錯誤的原因應該是找不到gcc!可是我一直用gcc編譯器的啊,好奇怪!

這兩天vpn不穩定,只能百度,好不容易才發現了原因:


從Mac OS 10.9開始,安裝Xcode5時不會再安裝gcc了,而系統中的gcc實際上只是一個別名。

$ gcc -vConfigured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1Apple LLVM version 7.0.0 (clang-700.0.72)Target: x86_64-apple-darwin14.5.0Thread model: posix$ clang -vApple LLVM version 7.0.0 (clang-700.0.72)Target: x86_64-apple-darwin14.5.0Thread model: posix

可以看到gcc實際上就是clang,而clang對應的調試工具是lldb。可是你既然給clang起了別名叫gcc,你就不能好人做到底給lldb也起一個別名嗎?

我自己在/usr/bin下邊建了一個symbol link,以後就可以方便的使用gdb了。

順便也看了下clang,LLVM和gcc的關係,有興趣的各位也可以去搜尋一下clang和gcc的優劣,現在看來,對於C語言的支援上,clang應該是佔有絕對優勢的(當然不是指市場佔有率,而是使用者體驗)。

clang

clang: a C language family frontend for LLVM

The goal of the Clang project is to create a new C, C++, Objective C and Objective C++ front-end for the LLVM compiler. 

也就是說clang是一個編譯器的前端,主要負責文法,詞法分析並產生LLVM可以理解的代碼傳遞給LLVM進行編譯。

LLVM

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. Despite its name, LLVM has little to do with traditional virtual machines, though it does provide helpful libraries that can be used to build them. The name "LLVM" itself is not an acronym; it is the full name of the project.

LLVM began as a research project at the University of Illinois, with the goal of providing a modern, SSA-based compilation strategy capable of supporting both static and dynamic compilation of arbitrary programming languages. Since then, LLVM has grown to be an umbrella project consisting of a number of subprojects, many of which are being used in production by a wide variety of commercial and open source projects as well as being widely used in academic research. Code in the LLVM project is licensed under the "UIUC" BSD-Style license.

LLVM則是主要的編譯併產生機器碼的部分。

gcc

The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Java, Ada, and Go, as well as libraries for these languages (libstdc++, libgcj,...). GCC was originally written as the compiler for theGNU operating system. 

其實gcc並不是一個軟體,而是一套軟體,全稱GNU Compiler Collection。相對於clang和LLVM來說,也會分為前端,後端,回想一下編譯原理,gcc實際上會首先調用cpp對程式進行預先處理,這也就相當於clang所做的工作,然後會調用cc1和ld來進行編譯和連結,這就相當於LLVM所做的工作。

這裡有一篇文章很好的解釋了clang/LLVM的發展曆史,水果公司和gcc之間的合作以及矛盾等:

GCC,LLVM,Clang  作者 肖雨宸 

從這篇文章中可以看到他們的組合并不是絕對的,gcc同樣也可以和LLVM搭配使用。


參考文獻:

1,clang官方網站:

http://clang.llvm.org/index.html

2,LLVM官方網站:

http://www.llvm.org/

3,gcc官方網站:

http://gcc.gnu.org/

Mac OS 下的 gcc gdb

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.