Coming back up to speed on Mac programming, now that I've finally got a shiny new iMac. Their XCode IDE looks like a great tool (Objective C, C++, C, etc., etc.), but I was hacking around building some simple test code. Being a fully-certified Unix operating system, of course that's an easy way to get something done while minimizing the number of known and unknown unknowns that need to be dealt with.
jeffs-imac:Foo jeff$ gcc -I /opt/local/include -I /opt/local/include/cppunit foo.cpp -L /usr/local/lib -lcppunit -o foo ld: in /usr/local/lib, can't map file, errno=22 collect2: ld returned 1 exit status
Hmmm. Maybe the library that's on there is screwed up somehow? Go to Sourceforge, pull down the library source, build it, install it, and try again.
You're right. I figured out the problem is that I was missing the -c switch when building the .o file with gcc. For some reason the linker doesn't complain about it, but when I try to link the shared lib with my main program I get the obscure can't map file error. Now it is working. Thanks.
Hmmm again. Go fiddle some more, this time compiling and linking my trivial proof-of-concept in separate
gcc command lines. Still no joy.
I go back and play with building
libcppunit again, wondering if I've missed some funky option to
configure. Nope. It's pushing 0130, I need to be up at 6-something, and my brain is fried, so I shut down for the night.
(Later) in the morning, something's niggling at the back of my mind, saying I missed something while watching
libcppunit compile, so I do it again. Yep, cue the "you dumb palooka!" moment: it's not using
gcc to compile; it's using
g++. For those who've never had the (dubious) pleasure -
gcc is the "general-purpose" front-end to the GNU Compiler Collection, a set of (numerous) language systems, of which
g++ is the C++-specific toolchain (and standalone front end). All compilers in the Collection produce object code in compatible format (the same back-end is used for almost everything), so usually all you have to do is invoke the One Command to automagically compile your Ada, FORTRAN, Java, PL/I, whatever. And, to be honest, it had been a few months since I'd dealt with C++ on gcc/g++ from the command line. (Thank you, Eclipse!) But I remembered a bit of wisdom lost in the Mists of Time...
They can both compile your C++ (in a single step). But: They're. Not. The. Same.
So, I re-do my (now-) two-step process, substituting
jeffs-imac:Foo jeff$ g++ -c -I /opt/local/include/ -I /usr/local/include/cppunit/ foo.cpp jeffs-imac:Foo jeff$ g++ foo.o -L/opt/local/lib -lcppunit -o foo jeffs-imac:Foo jeff$
Ta-daaaaa! OK, can we go back to a single step? That is, compiling and linking (using
g++) in one go:
jeffs-imac:Foo jeff$ g++ -I /opt/local/include -I /opt/local/include/cppunit foo.cpp -L /usr/local/lib -lcppunit -o foo ld: in /usr/local/lib, can't map file, errno=22 collect2: ld returned 1 exit status jeffs-imac:Foo jeff$
Nope. This is where the MacOSXHints commenter was right on the money. But why? I used to be knee-deep in the (FORTRAN-specific) code, a feeling akin to being knee-deep in the dead on occasion, and the answer doesn't come immediately to mind. Any ideas?