OK so I’m getting close, but I’m at a bit of a stumped point. I’ve never used MakeFiles before (or compiled from the command line) but I’m starting to get the hang of it and most of it makes sense…
The reason I’m compiling OF for OS X first is that I think if I get that going/get a handle on this then it’ll be a lot simpler for me to move over to doing all of this for WebOS. I’m trying to do this in pieces to keep my sanity. I first got an ofxWebOS addon working that essentially compiles an OS X emulator for the Palm PDK (using their custom SDL for windowing and touch events), so now I want to do the opposite and compile OF from command line since I know it should work if it compiles in XCode, I’m just not doing it right. After that I think I should be able to jump in and more or less put the two together and have OF running on the device.
I think the issue I’m having has to do with the linux makefiles using -lopenFrameworksDebug as an included library (and looking for .so files), which doesn’t seem to translate to OS X (or I very possibly am doing something wrong). I’ve got OF compiled through XCode for i386 using XCode4, maybe I should be doing this through command line/makefile as well?
Here is what my makefile looks like, it should be pretty simple to read since I copied/rewrote the Git makefile to target OS X only (again, for sanity…too many uname refs and ifeq…ifneq things were making my brain hurt between linux, android and OS X). It compiles main.cpp and testApp.cpp fine, but there is an issue with the linking that I just can’t figure out.
Thanks to anyone that can help and thanks to Arturo for previous help and creating super good/clear makefiles that I was already able to jump into without knowing anything.
Makefile:
# openFrameworks OS X makefile
#
# make help : shows this message
# make Debug: makes the application with debug symbols
# make Release: makes the app with optimizations
# make: the same as make Release
# make CleanDebug: cleans the Debug target
# make CleanRelease: cleans the Release target
# make clean: cleans everything
#
#
# this should work with any OF app, just copy any example
# change the name of the folder and it should compile
# only .cpp support, don't use .c files
# it will look for files in any folder inside the application
# folder except that in the EXCLUDE_FROM_SOURCE variable
# it doesn't autodetect include paths yet
# add the include paths in the USER_CFLAGS variable
# using the gcc syntax: -Ipath
#
# to add addons to your application, edit the addons.make file
# in this directory and add the names of the addons you want to
# include
#
# edit the following vars to customize the makefile
include config.make
ARCH = i386
COMPILER_OPTIMIZATION = $(USER_COMPILER_OPTIMIZATION)
EXCLUDE_FROM_SOURCE="bin,.xcodeproj,obj"
# you shouldn't modify anything below this line
SHELL = /bin/sh
CXX = LLVM-gcc
LIBSPATH=osx
NODEPS = clean
SED_EXCLUDE_FROM_SRC = $(shell echo $(EXCLUDE_FROM_SOURCE) | sed s/\,/\\\\\|/g)
SOURCE_DIRS = $(shell find . -maxdepth 1 -mindepth 1 -type d | grep -v $(SED_EXCLUDE_FROM_SRC) | sed s/.\\///)
SOURCES = $(shell find $(SOURCE_DIRS) -name "*.cpp" -or -name "*.c")
OBJFILES = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES)))
APPNAME = $(shell basename `pwd`)
CORE_INCLUDES = $(shell find $(OF_ROOT)/libs/openFrameworks/ -type d)
CORE_INCLUDE_FLAGS = $(addprefix -I,$(CORE_INCLUDES))
INCLUDES = $(shell find $(OF_ROOT)/libs/*/include -type d | grep -v glu | grep -v quicktime | grep -v poco)
INCLUDES_FLAGS = $(addprefix -I,$(INCLUDES))
INCLUDES_FLAGS += -I$(OF_ROOT)/libs/poco/include
INCLUDES_FLAGS += -I$(OF_ROOT)/libs/glu/include
LIB_STATIC = $(shell ls $(OF_ROOT)/libs/*/lib/$(LIBSPATH)/*.a | grep -v openFrameworksCompiled | grep -v poco | sed "s/.*\\/lib\([^/]*\)\.a/-l\1/")
LIB_SHARED = $(shell ls $(OF_ROOT)/libs/*/lib/$(LIBSPATH)/*.so | grep -v openFrameworksCompiled| sed "s/.*\\/lib\([^/]*\)\.so/-l\1/")
LIB_STATIC += $(OF_ROOT)/libs/poco/lib/$(LIBSPATH)/PocoNet.a ../../../libs/poco/lib/$(LIBSPATH)/PocoXML.a ../../../libs/poco/lib/$(LIBSPATH)/PocoUtil.a ../../../libs/poco/lib/$(LIBSPATH)/PocoFoundation.a
LIB_PATHS_FLAGS = $(shell ls -d $(OF_ROOT)/libs/*/lib/$(LIBSPATH) | sed "s/\(\.*\)/-L\1/")
CFLAGS += -Wall -fexceptions
CFLAGS += -I.
CFLAGS += $(INCLUDES_FLAGS)
CFLAGS += $(CORE_INCLUDE_FLAGS)
LIBS += $(LIB_SHARED)
LIBS += $(LIB_STATIC)
LDFLAGS = $(LIB_PATHS_FLAGS) -Wl
#LIBS += -lglut -lGL -lGLU -lasound -lopenal -lsndfile -lvorbis -lFLAC -logg -lfreeimage
LIBS += -framework AppKit -framework Cocoa -framework IOKit -framework AGL -framework AudioToolbox -framework Carbon -framework CoreAudio -CoreFoundation -framework CoreServices -framework OpenGL -framework Quicktime
#Targets
ifeq ($(findstring Debug,$(MAKECMDGOALS)),Debug)
TARGET_CFLAGS = -g
TARGET_LIBS = -lopenFrameworksDebug
TARGET_NAME = Debug
endif
ifeq ($(findstring Release,$(MAKECMDGOALS)),Release)
TARGET_CFLAGS = $(COMPILER_OPTIMIZATION)
TARGET_LIBS = -lopenFrameworks
TARGET_NAME = Release
endif
ifeq ($(findstring Debug,$(MAKECMDGOALS)),Debug)
BIN_NAME = $(APPNAME)_debug
TARGET = bin/$(BIN_NAME)
endif
ifeq ($(findstring Release,$(MAKECMDGOALS)),Release)
BIN_NAME = $(APPNAME)
TARGET = bin/$(BIN_NAME)
endif
ifeq ($(MAKECMDGOALS),)
TARGET_NAME = Release
BIN_NAME = $(APPNAME)
TARGET = bin/$(BIN_NAME)
TARGET_LIBS = -lopenFrameworks
endif
ifeq ($(MAKECMDGOALS),clean)
TARGET = bin/$(APPNAME)_debug bin/$(APPNAME)
endif
#Output
OBJ_OUTPUT = obj/$(TARGET_NAME)/
CLEANTARGET = clean$(TARGET_NAME)
OBJS = $(addprefix $(OBJ_OUTPUT), $(OBJFILES))
DEPFILES = $(patsubst %.o,%.d,$(OBJS))
ifeq ($(findstring addons.make,$(wildcard *.make)),addons.make)
ADDONS_OBJS = $(addprefix $(OBJ_OUTPUT), $(ADDONS_OBJFILES))
DEPFILES += $(patsubst %.o,%.d,$(ADDONS_OBJS))
endif
.PHONY: Debug Release all after
Release: $(TARGET) after
Debug: $(TARGET) after
all:
$(MAKE) Release
#This rule does the compilation
#$(OBJS): $(SOURCES)
$(OBJ_OUTPUT)%.o: %.cpp
@echo "compiling object for: " $<
mkdir -p $(@D)
$(CXX) -c $(TARGET_CFLAGS) $(CFLAGS) $(ADDONSCFLAGS) $(USER_CFLAGS) -MMD -MP -MF$(OBJ_OUTPUT)$*.d -MT$(OBJ_OUTPUT)$*.d -o$@ -c $<
$(OBJ_OUTPUT)%.o: %.c
@echo "compiling object for: " $<
mkdir -p $(@D)
$(CXX) -c $(TARGET_CFLAGS) $(CFLAGS) $(ADDONSCFLAGS) $(USER_CFLAGS) -MMD -MP -MF$(OBJ_OUTPUT)$*.d -MT$(OBJ_OUTPUT)$*.d -o$@ -c $<
$(OBJ_OUTPUT)%.o: $(OF_ROOT)/%.cpp
@echo "compiling addon object for" $<
mkdir -p $(@D)
$(CXX) $(TARGET_CFLAGS) $(CFLAGS) $(ADDONSCFLAGS) $(USER_CFLAGS) -MMD -MP -MF$(OBJ_OUTPUT)$*.d -MT$(OBJ_OUTPUT)$*.d -o $@ -c $<
$(OBJ_OUTPUT)%.o: $(OF_ROOT)/%.c
@echo "compiling addon object for" $<
mkdir -p $(@D)
$(CXX) $(TARGET_CFLAGS) $(CFLAGS) $(ADDONSCFLAGS) $(USER_CFLAGS) -MMD -MP -MF$(OBJ_OUTPUT)$*.d -MT$(OBJ_OUTPUT)$*.d -o $@ -c $<
$(TARGET): $(OBJS) $(ADDONS_OBJS)
@echo "linking" $(TARGET) $(GTK)
$(CXX) -arch i386 -Wl,-v -o $@ $(OBJS) $(ADDONS_OBJS) $(USER_CFLAGS) $(LDFLAGS) $(USER_LDFLAGS) $(TARGET_LIBS) $(ADDONSLIBS) $(USER_LIBS) $(LIBS)
-include $(DEPFILES)
.PHONY: clean cleanDebug cleanRelease
clean:
rm -Rf obj
rm -f -v $(TARGET)
rm -Rf -v bin/libs
$(CLEANTARGET):
rm -Rf -v $(OBJ_OUTPUT)
rm -f -v $(TARGET)
after:$(TARGET)
cp -r $(OF_ROOT)/export/$(LIBSPATH)/libs bin/
@echo
@echo " compiling done"
@echo " to launch the application"
@echo
@echo " cd bin"
@echo " ./$(BIN_NAME)"
@echo
.PHONY: help
help:
@echo
@echo openFrameworks universal makefile
@echo
@echo targets:
@echo "make Debug: builds the application with debug symbols"
@echo "make Release: builds the app with optimizations"
@echo "make: = make Release"
@echo "make all: = make Release"
@echo "make CleanDebug: cleans the Debug target"
@echo "make CleanRelease: cleans the Release target"
@echo "make clean: cleans everything"
@echo
@echo this should work with any OF app, just copy any example
@echo change the name of the folder and it should compile
@echo "only .cpp support, don't use .c files"
@echo it will look for files in any folder inside the application
@echo folder except that in the EXCLUDE_FROM_SOURCE variable.
@echo "it doesn't autodetect include paths yet"
@echo "add the include paths editing the var USER_CFLAGS"
@echo at the beginning of the makefile using the gcc syntax:
@echo -Ipath
@echo
@echo to add addons to your application, edit the addons.make file
@echo in this directory and add the names of the addons you want to
@echo include
@echo
Errors (using LLVM-gcc), .o files are created without any errors, this is from linking:
linking bin/graphicsExample_debug
LLVM-gcc -arch i386 -Wl,-v -o bin/graphicsExample_debug obj/Debug/src/main.o obj/Debug/src/testApp.o -arch i386 -L../../../libs/FreeImage/lib/osx -L../../../libs/fmodex/lib/osx -L../../../libs/freetype/lib/osx -L../../../libs/glee/lib/osx -L../../../libs/glut/lib/osx -L../../../libs/openFrameworksCompiled/lib/osx -L../../../libs/poco/lib/osx -L../../../libs/rtAudio/lib/osx -Wl -L../../../libs/openFrameworksCompiled/lib/osx/openFrameworksDebug ../../../libs/FreeImage/lib/osx/freeimage.a ../../../libs/freetype/lib/osx/freetype.a ../../../libs/glee/lib/osx/GLee.a ../../../libs/rtAudio/lib/osx/rtAudio.a ../../../libs/poco/lib/osx/PocoNet.a ../../../libs/poco/lib/osx/PocoXML.a ../../../libs/poco/lib/osx/PocoUtil.a ../../../libs/poco/lib/osx/PocoFoundation.a -framework AppKit -framework Cocoa -framework IOKit -framework AGL -framework AudioToolbox -framework Carbon -framework CoreAudio -CoreFoundation -framework CoreServices -framework OpenGL -framework Quicktime
collect2 version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.9) (i686 Darwin)
/usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin10/4.2.1/ld -dynamic -arch i386 -macosx_version_min 10.6.7 -weak_reference_mismatches non-weak -o bin/graphicsExample_debug -lcrt1.10.6.o -L../../../libs/FreeImage/lib/osx -L../../../libs/fmodex/lib/osx -L../../../libs/freetype/lib/osx -L../../../libs/glee/lib/osx -L../../../libs/glut/lib/osx -L../../../libs/openFrameworksCompiled/lib/osx -L../../../libs/poco/lib/osx -L../../../libs/rtAudio/lib/osx -L../../../libs/openFrameworksCompiled/lib/osx/openFrameworksDebug -L/usr/lib/i686-apple-darwin10/4.2.1 -L/usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/llvm-gcc-4.2/bin/../lib/gcc -L/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin10/4.2.1/../../.. -L/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/../../.. -v obj/Debug/src/main.o obj/Debug/src/testApp.o ../../../libs/FreeImage/lib/osx/freeimage.a ../../../libs/freetype/lib/osx/freetype.a ../../../libs/glee/lib/osx/GLee.a ../../../libs/rtAudio/lib/osx/rtAudio.a ../../../libs/poco/lib/osx/PocoNet.a ../../../libs/poco/lib/osx/PocoXML.a ../../../libs/poco/lib/osx/PocoUtil.a ../../../libs/poco/lib/osx/PocoFoundation.a -framework AppKit -framework Cocoa -framework IOKit -framework AGL -framework AudioToolbox -framework Carbon -framework CoreAudio -framework CoreServices -framework OpenGL -framework Quicktime -lSystem -lgcc -lSystem
ld: warning: directory not found for option '-L../../../libs/openFrameworksCompiled/lib/osx/openFrameworksDebug'
@(#)PROGRAM:ld PROJECT:ld64-123.2
Library search paths:
../../../libs/FreeImage/lib/osx
../../../libs/fmodex/lib/osx
../../../libs/freetype/lib/osx
../../../libs/glee/lib/osx
../../../libs/glut/lib/osx
../../../libs/openFrameworksCompiled/lib/osx
../../../libs/poco/lib/osx
../../../libs/rtAudio/lib/osx
/usr/lib/i686-apple-darwin10/4.2.1
/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1
/usr/llvm-gcc-4.2/lib/gcc
/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1
/usr/lib/gcc/i686-apple-darwin10/4.2.1
/usr/llvm-gcc-4.2/lib
/Developer/usr/llvm-gcc-4.2/lib
/usr/lib
/usr/local/lib
Framework search paths:
/Library/Frameworks/
/System/Library/Frameworks/
Undefined symbols for architecture i386:
"ofAppGlutWindow::ofAppGlutWindow()", referenced from:
_main in main.o
"ofSetupOpenGL(ofAppBaseWindow*, int, int, int)", referenced from:
_main in main.o
"operator new(unsigned long)", referenced from:
_main in main.o
"ofRunApp(ofBaseApp*)", referenced from:
_main in main.o
"std::terminate()", referenced from:
_main in main.o
testApp::setup() in testApp.o
testApp::draw() in testApp.o
"operator delete(void*)", referenced from:
ofBaseApp::~ofBaseApp()in main.o
ofBaseApp::~ofBaseApp()in main.o
ofAppGlutWindow::~ofAppGlutWindow()in main.o
testApp::~testApp()in testApp.o
testApp::~testApp()in testApp.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in main.o
__static_initialization_and_destruction_0(int, int)in testApp.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in main.o
___tcf_0 in testApp.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
ofAppGlutWindow::~ofAppGlutWindow()in main.o
testApp::setup() in testApp.o
testApp::draw() in testApp.o
"vtable for __cxxabiv1::__class_type_info", referenced from:
typeinfo for ofBaseAppin main.o
typeinfo for ofBaseAppin testApp.o
"vtable for ofAppGlutWindow", referenced from:
ofAppGlutWindow::~ofAppGlutWindow()in main.o
"___gxx_personality_v0", referenced from:
Dwarf Exception Unwind Info (__eh_frame) in main.o
Dwarf Exception Unwind Info (__eh_frame) in testApp.o
Dwarf Exception Unwind Info (__eh_frame) in main.o
Dwarf Exception Unwind Info (__eh_frame) in testApp.o
"ofSetCircleResolution(int)", referenced from:
testApp::setup() in testApp.o
"ofBackground(int, int, int)", referenced from:
testApp::setup() in testApp.o
"std::allocator<char>::allocator()", referenced from:
testApp::setup() in testApp.o
testApp::draw() in testApp.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
testApp::setup() in testApp.o
testApp::draw() in testApp.o
"ofSetWindowTitle(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
testApp::setup() in testApp.o
"std::allocator<char>::~allocator()", referenced from:
testApp::setup() in testApp.o
testApp::draw() in testApp.o
"ofSetFrameRate(int)", referenced from:
testApp::setup() in testApp.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
testApp::setup() in testApp.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
testApp::setup() in testApp.o
"ofSetColor(int, int, int)", referenced from:
testApp::draw() in testApp.o
"ofFill()", referenced from:
testApp::draw() in testApp.o
"ofCircle(float, float, float)", referenced from:
testApp::draw() in testApp.o
"ofNoFill()", referenced from:
testApp::draw() in testApp.o
"ofSetColor(int)", referenced from:
testApp::draw() in testApp.o
"ofDrawBitmapString(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float)", referenced from:
testApp::draw() in testApp.o
"ofRandom(float, float)", referenced from:
testApp::draw() in testApp.o
"ofRect(float, float, float, float)", referenced from:
testApp::draw() in testApp.o
"ofEnableAlphaBlending()", referenced from:
testApp::draw() in testApp.o
"ofSetColor(int, int, int, int)", referenced from:
testApp::draw() in testApp.o
"ofDisableAlphaBlending()", referenced from:
testApp::draw() in testApp.o
"ofEnableSmoothing()", referenced from:
testApp::draw() in testApp.o
"ofLine(float, float, float, float)", referenced from:
testApp::draw() in testApp.o
"ofDisableSmoothing()", referenced from:
testApp::draw() in testApp.o
"vtable for __cxxabiv1::__si_class_type_info", referenced from:
typeinfo for testAppin testApp.o
"std::cout", referenced from:
testApp::setup() in testApp.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
testApp::setup() in testApp.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
make: *** [bin/graphicsExample_debug] Error 1