Holidays and Hobbies
  • Home
  • Brasil
  • Rome
  • Paris
  • Fabio
    • Data Science Blog
    • Music
    • Rubiks Cube
    • Astronomy
    • Art
    • Unicycle
    • English Pope
    • Flying
    • If I Ruled The World
    • Fusion
  • Local
  • Tenby
  • Keswick
  • Mark
  • Store
  • Contact
  • cplusplus

C++ On a Mac

8/26/2018

 

The Mac Environment

So we are using macOS 10.13.6 (High Sierra).
We tried Xcode and found it was so complicated and too set up for iphone/ipad/apple apps as to get in the way. We have switched to Eclipse.
So, our envirnoment is:
  • Compiler : c++ that comes with the macOS (clang++)
  • IDE: Eclipse (photon)
  • Debugger: gdb
  • Java 8 JDK (is required for Eclipse)

We are also going to have a second environment using the Terminal shell (bash) and use a Makefile. The idea being we can get use the command line and IDE.


Notes on Gnu Debugger (gdb) on Higher Sierra

So we had to  install  gdb 8.01 using brew.

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c3128a5c335bd2fa75ffba9d721e9910134e4644/Formula/gdb.rb

Essentially gdb needs signing or else the debugger won't work.
We followed these  helpful pages:
  • https://danisfermi.github.io/tech/2018/01/16/setting-up-gdb.html
  • https://www.thomasvitale.com/how-to-setup-gdb-and-eclipse-to-debug-c-files-on-macos-sierra/


Our First Progam


#include <iostream>
using namespace std;
int main(){
  cout << "Hello" << endl;
}

# From your Terminal
cd
mkdir LearningCpp
cd LearningCpp
vim myfirstprog.cpp
i
:wq


So we are using the editor vim in bash (terminal shell). You might want to look at a UNIX command line cheet sheet to brush up.

And we compile by typing:
 make myfirstprog
Which runs:
c++  myfirstprog.cpp -o myfirstprog

See make , but with no file called Makefile present to take detailed instructions, make  looks for a relevant source files and compiles it.

First Look at gdb


We have to compile like this  with "-g" so :
    cc -g myfirstprog.cpp -o myfirstprog
and so we create our first Makefile

DEBUG="-g"
myfirstprog:     myfirsrprog.cpp
        c++    $(DEBUG).   -o    $<.   -o   $@


Notes:
  • $< is the dependency "myfirstprog.cpp"
  • $@ is the output of the compilation


Comments are closed.

    Author

    A look at C++ From scratch.

    RSS Feed

    Archives

    August 2018

    Categories

    All

    RSS Feed