NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Support Forum » Switching between C compilers on Mac OSX?

February 15, 2010
by Jon
Jon's Avatar

Hi -- I'm just getting started and I am w-a-y over my head right now. I am trying to play with the NK but also trying to learn C progarmming at the same time.

I am using a Mac and the AVRMacPack for the NK.

In going through the NK manual, it had me set the AVR version of the compiler by running "avr-gcc-select". When I do a 'set' in terminal now, I see the AVRMacPack directory in the path:

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/AVRMacPack/bin

I'm not all the way done with my kit in terms of trying out all the downloading, but the makefile for the first NK compile seemed to work without errors.

The problem seems to be that I can't do a simple compile to go back to learning C with simple things like 'Hello World'. I looked at avr-gcc-select and it looks like it uses 'link' (ln) and 'unlink' (rm) to set the path for the AVR version of the gcc compiler (I guess that's redundant, huh?). Do I need to do something to re-set back to the prior settings/path when I want to compile simple C programs using the non-AVR version of gcc? If that is the case, what is the 'undo' for avr-gcc-select?

When I try to compile a regular C file now like this:

gcc samp.c -o samp

I am getting unknown flag errors:

/usr/bin/ld: /usr/lib/gcc/powerpc-apple-darwin8/4.0.0/../../../libSystem.dylib unknown flags (type) of section 9 (TEXT,dof_plockstat) in load command 0 /usr/bin/ld: /usr/lib/libSystem.B.dylib unknown flags (type) of section 9 (TEXT,dof_plockstat) in load command 0 collect2: ld returned 1 exit status

(The double underscores in the error msgs above are being converted to BOLD and I don't know how to quote that so it doesn't do that, sorry.)

Could this be because of the path as set by avr-gcc-select, or running the wrong version of gcc, or do I maybe have some more fundamental problem with my configuration? I did not install the entire Xcode IDE, as all I wanted to do was have a simple edit and compile environment for simple C programs to learn with. And I'm using an older version of Xcode Tools since the new version seems to require Snow Leopard and an Intel processor (I'm still running Leopard 10.5.8 on a G4 PowerBook for this stuff).

I have long since forgotten what little Unix and C I knew years ago, so I am basically starting from scratch here. Any hints/help are really appreciated.

Jon

February 15, 2010
by Jon
Jon's Avatar

Here's a little better version of what the compile errors look like...

/usr/bin/ld: /usr/lib/gcc/powerpc-apple-darwin8/4.0.0/../../../libSystem.dylib unknown flags (type) of section 9 ( _ _ TEXT, _ _ dof_plockstat) in load command 0

/usr/bin/ld: /usr/lib/libSystem.B.dylib unknown flags (type) of section 9 ( _ _ TEXT, _ _ dof_plockstat) in load command 0

collect2: ld returned 1 exit status

February 15, 2010
by pbfy0
pbfy0's Avatar

I don't know... normal GCC still runs fine for me.

February 16, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Jon,

That is quite odd. avr-gcc should be a completely separate executable from gcc, but I am not that familiar with Mac's so that might not be the case here. Are you sure this problem is related to the installation of AvrMacPack? Let us know if you make any progress on this issue.

Humberto

February 16, 2010
by N3Roaster
N3Roaster's Avatar

Yes, the NerdKits downloads should not do anything to alter or make unavailable the usual development tools. There are, however, some oddities with command line compilation on the Mac when it comes to linking in system libraries that can be tricky to figure out. It looks like you probably need to specify an SDK on the command line so that the linker can bring in the appropriate system libraries. Unfortunately, there are some oddities when it comes to compiling Mac applications and XCode really does simplify getting that to just work. You should be able to find a version that will work with your system on the installation discs that came with your computer or with your last OS upgrade. For a G4, that'll probably be on Disc 2 (Extras). Similarly, this install will not interfere with avr-gcc. The normal Mac development tools should be under

/Developer/

and the avr-gcc stuff should be under

/usr/local/AVRMacPack/
February 19, 2010
by Jon
Jon's Avatar

Hi -- Thank you for the suggestions and encouragement to get going here.

After a couple frustrating days of removing and re-installing software, I have gone back and installed the entire Xcode IDE from my Leopard DVD (Xcode 3.0).

After that, a re-install of AVRMacPack seems to work.

It appears the original error was from my attempt to install less-than-a-full-blown IDE to use for learning C. I can now compile and run simple C programs from Terminal.

So now my dumb total newbie question is... How do you just create a C program, compile it and run it in a window, from Xcode, without all the overhead as though you were building a full-blown commercial app?

The Xcode IDE is so confusing, I cannot figure out what to do to just create 'Hello World'.

I assume I'm supposed to launch Xcode.app (from /Developer/Applications), which brings up a navigation and project window.

Seems like I have to create a "project" to get started. Or is there some way to just work with a few source files?

On the assumption I need to create a project ('test') and then create New File... C and C++... C File. Do I delete all the other files that were automatically created for the project (Models, Classes, Other Sources, etc.)?

Do I need to say my "target" is something other than an application (default)?

Is there some basic place that provides a reference for how to get started other than building a full-blown app?

The Xcode User Guide starts with the assumption you want to build commercial apps. Skimming through that I didn't find anything on starting with basic compiles and something like, "Let's get started by writing and compiling 'Hello World'.".

Am I just missing something really basic, or am I just destined to be doing my basic learning/compiling all in Terminal?

Thanks again,

Jon

February 19, 2010
by Jon
Jon's Avatar

Ah... I love the web. Google comes to the rescue with a quick search that hit the nail on the head...

Hello World in Xcode

So, my question is answered and I am now officially crawling along again.

Jon

Post a Reply

Please log in to post a reply.

Did you know that you can input numbers in binary via a DIP switch, and output them to the LCD? Learn more...