dynamic vs static link error, Mac OS X

Started by
3 comments, last by serratemplar 16 years, 10 months ago
I'm new to Mac OS X; picked up a nice new MacBook to do cross platform development on (working with SDL, GTK, etc). For my new, recent project I've run into a link error I've not seen before: /usr/bin/ld: main.o is input for the dynamic link editor, is not relocatable by the static link editor again Googling has given me little understanding of this issue: from what I can tell, by building main.cpp into main.o, g++ in darwin is making it a dynamically linkable library? So it's not allowing me to link it in the way I am accustomed. Here is my (very simple) makefile:


.SUFFIXES = .cpp .o

GTK_INIT = `pkg-config --cflags --libs gtk+-2.0`
BOOST_LIB = -lboost_filesystem -I/opt/local/include -L/opt/local/lib

OBJECT_FILES = main.o

all:		pictview

pictview:	$(OBJECT_FILES)
	g++ $(OBJECT_FILES) -o pictview $(GTK_INIT) $(BOOST_LIB)
	


main.o:		main.cpp
	g++ main.cpp -o main.o $(GTK_INIT) $(BOOST_LIB)
	
clean:
	rm pictview
	rm main.o

Please note that I am able to compile/build if I put it all on one line...but this project (and many others I work on) will end up being quite large, spanning multiple files...so it's necessary to build each object file individually so that modifying only one doesn't require I rebuild the entire project. I'm sure many of you are familiar with this in general. Does anyone have experience with this Mac-side? Any and all help is appreciated =) Thanks!
Advertisement
Like on Linux, g++ main.cpp -o main.o compiles and links a binary.

You need the -c switch to g++ to only compile it. You're trying to link it twice.
Whoops! =)

Thanks for pointing out my mistake; always nice when they're simple. Thanks again!
No problem, I hope you're enjoying your new computer. Make sure to pick up QuickSilver and TextMate.
This thing is great =) I've been using the text-editor portion of XCode, which is a bit rough. I'll definately look into both of those apps.

This topic is closed to new replies.

Advertisement