Sunday, October 14, 2012

Working with the console: Part 2 - Mac compiling

When compiling on my program on my Macbook I had a few problems. The first thing I ran into was the entire program would not compile using the terminal compiler. When I complied I would receive this error:

cio_test.cpp:959: error: cast from 'const char*' to 'int' loses precision

Well compiler, I think that's fine! Why did you not just do it? So, I thought to myself: what could be the problem? The only thing I could think of is the architecture (being x86_64) doesn't like that happening. Thus, I looked in the c++ manual file. lo and behold there is an option for architecture in it. It says there are only four different variables that it could be: ppc, ppc64, i386, and x86_64. Well, I know my current architecture is x86_64, so let's try i386 which is for 32-bit applications:

c++ cio_test.cpp bconsole.cpp console.cpp -lcurses -arch i386

 It worked!

Okay now how do I get Xcode to work? I know I can select i386 to my compile in the drop down box in the top left; however, when I compile, I receive 13 errors. Uh oh, what now? I know the program requires the lcurses library. If I could find the location of this library maybe I could add it to my project.

A quick Google search later tells me that all the library files are located in /usr/lib/. Thats great, but according to Finder the /usr directory doesn't exist, so I can't just drag and drop it in to my project. Another Google search tells me that /usr and a few other folders are considered hidden files in finder. So, by using the following command in the terminal you can unhide them:

sudo chflags nohidden /usr

Now I can see the files in finder. After looking in /usr/lib I find what I'm looking for, it is a file called libcurses.dylib. That file is then dragged into the source for my project and bam! No more compile errors. To run the file you have to click on the terminal application created under Products, but everything seems to work!

Huzzah!

No comments: