# dynamic vs static link error, Mac OS X

## Recommended Posts

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!

##### Share on other sites
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.

##### Share on other sites
Whoops! =)

Thanks for pointing out my mistake; always nice when they're simple. Thanks again!

##### Share on other sites
No problem, I hope you're enjoying your new computer. Make sure to pick up QuickSilver and TextMate.

##### Share on other sites
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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627737
• Total Posts
2978873

• 10
• 10
• 21
• 14
• 12