С Compiler For Mac Eclipse



  • Visual Studio for Mac should also provide support for C development, using compilers available on the system (gcc, Clang, etc.) 3. Forum: How do I get c to work on Read more » 0.
  • A compiler is not installed by default with this version of Visual Studio and must be specified while performing a custom installation. See Answer 328432 for more details. Visual Studio 2017 can be downloaded from the Visual Studio documentation. Notes for the Mac Platform. Fortran compilers are supported with Simulink only for creating.
  • Another option is given by Eclipse. Eclipse is a popular IDE for Java. The CDT plugin for Eclipse gives it the ability to compile C programs and become an IDE for C. Details can be found at the CDT page of the Eclipse site. Now that you have a C compiler for your Mac, you can try a.

Installing G++ on a Mac

This section is intended to get you quickly started with C++ programming on your Mac. We'll be installing GCC 4.8.1 and GDB through a tool called Homebrew. If you want an additional guide on all of the following steps (except for installing GCC), the one by Moncef Belyamani is quite helpful. When you follow it, ignore anything about installing Ruby; that is, stop after setting up git.

As @Jaime said, 'In CDT, Cross GCC is a cross-compiler project, one that can build binaries for other platforms/architectures. MacOSX GCC builds only for Mac.' But for guidance on which one to choose, according to this article, Cross GCC won't work in Eclipse, so MacOSX GCC is the way to go: make sure that you select “MacOSX GCC”.

Homebrew

Homebrew 'installs the stuff that you need that Apple don't'. It's like Ubuntu's apt-get, where one can install packages easily from repositories. Instead of having to download, configure, and install something yourself, all you need to do is run one command, and Homebrew will take care of the rest for you.

Eclipse

Pre-requisites

Homebrew requires that you have either Xcode or the Xcode command line tools installed on your Mac. Xcode is a free integrated development environment similar to Eclipse designed by Apple and mainly intended for iOS development or targeting the clang compiler. In this class, we will focus on gcc.

Xcode is quite a big install, so if you do not want to install it, you can get away with just installing the Xcode command line tools. See a Stackoverflow discussion for instructions on how to install the command line tools regardless of whether you have Xcode installed.

Installing Homebrew

You need xcode command line tools to install Homebrew. It is very easy to install Homebrew. Open your terminal, and run the following command:

If this doesn't seem to do anything, try killing it (CTRL C) and running it again. Or checkout homebrew website.

GCC and GDB

Installing GCC

As mentioned before, installing packages with Homebrew is very easy. First, we will add the repository from which the GCC package is available, so that Homebrew knows where to find the package we want. The repository is at https://github.com/Homebrew/homebrew-versions.

We do this by using the brew-tap command. Keep your terminal open, and run the following command. (For more information on how brew-tap works, visit the Homebrew docs):

Next, we will actually install the GCC package. Run the following command:

It might take a while before the installation is complete. When done, run the following:

The result should look like this:

USC Wireless Warning

Many people have had issues running the brew install commands while connected to USC Wireless. If you are having trouble, you can either try using a wired connection, a different wireless connection, or do the following:

С Compiler For Mac EclipseС Compiler For Mac Eclipse
  1. Download a homebrew cache
  2. Open Finder, press CMD (command) + SHIFT + G and type /Library/Caches/Homebrew
  3. Extract the contents of the .zip you downloaded inside of the folder you opened in the previous step. Do not extract any of the .tar.bz2 or .tar.gz inside of the .zip folder.This should look as follows:

  4. Run brew install gcc48 in the Terminal as instructed above.

Using G++

To compile with the newly installed G++ compiler, use g++-4.8.

(Advanced) Aliasing g++

If you prefer calling g++ directly, you can also create a bash alias, as follows:

Put these two lines at the end of the file ~/.bashrc, and run:source ~/.bashrc

For more information on bash alias, take a look at the GNU Docs.

Installing GDB

Here also we use Homebrew. The following instruction has been taken from GDB on OS X Mavericks and Xcode 5 guide. To install, run the following brew command.

Check if it's installed:

The result should be gdb version 7 or higher.

Codesigning gdb

gdb is not going to debug yet. You'll get an error message like 'please check gdb is codesigned'. You need to create a certificate and sign gdb. By doing so you're telling the operating system that gdb is authorized to attach to other processes for debugging purposes. The following instructions have been taken from this Code Signing guide.

  1. Open application 'Keychain Access' (/Applications/Utilities/Keychain Access.app)
  2. In Keychain Access, select the 'login' keychain in the 'Keychains' list in the upper left hand corner of the window.

  3. Open the menu item in /Keychain Access/Certificate Assistant/Create a Certificate...

  4. Choose a name ('lldb_codesign' in the example, but you can use anything you want), set 'Identity Type' to 'Self Signed Root', and set 'Certificate Type' to 'Code Signing'. Click 'Create'.

  5. Click continue, continue and done.

  6. Click on the “My Certificates” category on the left side and double click on the new “lldb_codesign” certificate.

  7. Open the context menu for 'Trust' (click the triangle) and change the following:When using this certificate: Always Trust

  8. Now close this window, and enter your login password to confirm this change.

  9. Option-drag (this meaning holding the option key down and dragging) the new 'lldb_codesign' certificate from the login keychain to the System keychain in the Keychains pane of the main Keychain Access window to make a copy of this certificate in the System keychain. You'll have to authorize a few more times, set it to be 'Always trusted' when asked.

  10. Switch to the 'System' keychain and drag a copy of the 'lldb_codesign' you just made onto the Desktop.

  11. Switch to Terminal and then run the following command (copy paste it!): sudo security add-trust -d -r trustRoot -p basic -p codeSign -k /Library/Keychains/System.keychain ~/Desktop/lldb_codesign.cer

  12. Then right click on the 'lldb_codesign' certificate in the 'System' keychain (not 'Login') and select 'delete' to delete it from the 'System' keychain.

  13. Then reboot your system/computer.

  14. Finally you can sign gdb:codesign -s lldb_codesign /usr/local/bin/gdb

  15. If this command doesn't work...then panic! Just kidding, be sure that you have gdb installed and that gdb is actually installed in /usr/local/bin. You may want to try 'which gdb' in your Terminal to figure out where it is.

  16. Finally, remove the lldb_codesign.cer file that's sitting on your desktop, and gdb should be working at this point. :)

In my last blog I showed how to install and use ARM command line cross compilation tools. In this blog I’ll show you how to install Eclipse for C & C++ development for basic cross compilation. Future blogs will cover using libraries (libsoc & mraa), auto copying executables from a cross compiling machine to a 96Boards target, and remote debugging.

These instructions show how to install the Linux version of Eclipse, either on the latest Debian (Jessie) or Ubuntu (16.04). You will also learn how to install a copy of the Eclipse IDE for C/C++ Developers in your home directory. These instructions do not demonstrate how to install Eclipse system wide.

Once Eclipse is installed, we will set up a project for cross compiling. It is assumed you have already installed and tested the command line cross compile toolchains (Blog: Cross compile using command line). These instructions do not presume to teach you everything about Eclipse, but rather how to get cross compiling working with Eclipse. If you are unsure as to how to use Eclipse, there are tutorials which can teach you how to use both basic and extended functions.

Compiler

Assumptions

  • Knowledge on how to use Eclipse as an Integrated Development Environment (IDE).

  • Previously installed command line cross compilation tools as described in a prior blog entry of mine.

  • Cross compiling host computer is X86 based running Linux, either Ubuntu 16.04, Debian Jessie, or Debian testing with Jessie cross compiling tools installed.

  • You are cross compiling for 96Boards - either 32bit or 64bit ARM.

Update Host System

The image on your host Linux computer might be out of date. This is possible even when using the stock images, recent downloads, or newly flashed versions of any operating system.

A few useful commands will help us make sure everything on the board is current:

  • apt-get update: Downloads package lists from online repositories and “updates” them to get information on the newest versions of packages and their dependencies.

  • apt-get upgrade: Fetches and installs newest package versions which currently exist on the system. APT must know about these new versions by way of ‘apt-get update’

  • apt-get dist-upgrade: In addition to performing the function of upgrade, this option also intelligently handles changing dependencies with new versions of packages

Commands:

$ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get dist-upgrade

Install Eclipse IDE

Before moving on to the next sections, you will need to install the latest version of the Eclipse integrated development environment (IDE). The following steps will walk you through this process.

Eclipse mac c++

Step 1: Download Installer from www.eclipse.org

To do this we will need to dig our way through download buttons. Using your preferred web browser, go to “www.eclipse.org” and click the Download button located at the top-right.

Once again click the yellow Download button.

Finally, you will see a box with download mirror and button. You can change your mirror, or simply download from the suggested mirror by clicking this last Download button.

Once download is complete proceed to next step.

Step 2: Extract your eclipse download and run the installer

  • Open your terminal and change directory to the folder with your download.

  • Use the tar command to untar the downloaded tar file.

  • Change directory to the newly untarred eclipse-installer folder

  • Execute the install script and proceed to the next step

Commands:

$ cd /~/Downloads $ tar zxvf eclipse-inst-linux64.tar.gz $ cd eclipse-installer $ ./eclipse-inst

Step 3: Install and Launch Eclipse

  • The last command from the previous step will launch Eclipse Installer.

  • You will be presented with a easy to understand graphical interface (GUI)

  • Select the “Eclipse IDE for C/C++ Developers” option

  • Select your “Installation Folder”

Note: Default “Installation Folder” is /home/your user name/eclipse/cpp-neon2 - We suggest keeping this default.

  • Click Install button

  • Confirm License and installation will begin.

Note: Installation time for Eclipse is dependent on your internet speed. If you have a poor internet connection, installation may take some time.

  • Check box to indicate you trust the eclipse.org certificates

  • When Install is complete you may start up the IDE by clicking the Launch button

  • Once eclipse launches, it will want you to select a workspace. It is recommend to take the default offered and click OK.

Back up Eclipse IDE - (Optional)

This optional step can be used to create a backup of your Eclipse directories. Doing this will allow you to start from scratch should any files become corrupted, or if your Eclipse IDE is rendered unusable after tampering with defaults.

This section should only be performed in line with the previous sections. Eclipse must first be installed using the downloaded installer.

Step 1: Exit Eclipse by closing the windows

Step 2: Combine all four Eclipse directories into a single reusable tar file

The Eclipse installer creates four separate directories including the workspace. These directories are required in order for Eclipse to work:

/home/your user name/eclipse/cpp-neon2 ** /home/your user name/.p2** ** /home/your user name/.eclipse** ** workspace**

Commands:

$ cd ~ $ tar czvf pristine-eclipse.tar.gz .p2 .eclipse eclipse workspace

Your tar file of a pristine backup of Eclipse is now ready.

First cross compile using Eclipse

Now that we have Eclipse installed it is time to do a cross compile project. Follow the steps below.

Step 1: Open Eclipse with the following command

$ eclipse/cpp-neon/eclipse/eclipse

Step 2: Start a new project

“File” -> “New” -> “C Project”

This will bring up a “C Project” screen. You need to enter the project name and select the project type and Toolchain.

  • Enter “Test1” for project name

  • Select “Hello World ANSI C Project” for project type

  • Select “Cross GCC for toolchains and click “Next”

  • Enter your name for Author and click “Next”

  • Be sure to select both “debug” and “release configuration”, or “Select All” and click “Next” to continue

  • Enter a cross compiler prefix and path to the cross compiler tools

    • 32bit toolchain: “arm-linux-gnueabihf-”

    • 64bit toolchain: “aarch64-linux-gnu-”

  • Enter “/usr/bin” for the cross compiler path and select “Finish”

These steps are the magic that will cause eclipse to use the ARM cross compiler tools you installed from a prior blog entry.

The new project screen will close and you will see in the “Project Explorer” tab a project called “Test1”. You will then see in the source code editor tab a C file called Test1.c, which will have code to generate “!!!Hello World!!!”

In the Project Explorer tab click on the right facing arrow next to the Test1 Project, this will expand the project. You will see an Includes tab and a src tab, if you click on the right facing arrow next to the src tab you will see the Test1.c source file.

Step 3: Build the project

Select “Project” -> “Build Project”

Eclipse Mac C++

Eclipse will run the cross compiler on the source file. You will see two (2) new Tabs in the Test1 Project. Binaries and Debug. These files were created during the build.

Expand the Binaries tab to see Test1 - [arm/le]

Step 4: Access binary file in file system

  • Open Terminal

  • Change directory to the following:

$ cd /workspace/Test1/Debug

  • Test your new Test1 binary file

$ file Test1

Eclipse For Mac C++

This file should be an ARM 32 or 64 bit file depending on which toolchain you used. You can copy this file over to the 96Boards and it will run.

Conclusion

Congratulations, you have successfully used Eclipse to cross compile a C application. Now if you have used Eclipse in the past for building X86 projects, you likely know how to add an external library to a project, but don’t worry if you don’t - my next blog entry will address adding external libraries. I will also show you how to automatically copy your built application over to your 96Boards so it’s ready to run on your ARM system. Thanks for reading!

Please remember, if you get stuck, there are resources to help you through the installation. Feel free to check out the 96Boards forums, 96Boards wiki, or Freenode IRC channel #96Boards (there are many ways to access IRC, this website is one of them). Dig around the wiki, create a new forum thread, and/or post a question in the chat, myself or one of the 96Boards developers would love to help get your 96Boards up and running!

Don’t forget about the Open Hours every Thursday, where we will discuss this blog along with other pressing questions amongst a fun crowd of 96Boards users and developers over coffee. We hope to you see you there!

Mac Eclipse C++

Other Blogs from David Mandala: