Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

m3the01

macrumors member
Original poster
Jun 18, 2007
70
0
Very new to mac, very old to programming.

Searched for a while but can't come up with a solution.

I have a program which was developed under linux and it works very well, i now have troubles on the new mac book pro 2.4ghz nvidia notebook i picked up last week.

Ive grabbed the needed frameworks and installed per instruction. Ive also downloaded the xcode developer kit and installed.

Here is the makefile, modified as per internet instruction for compilation on a mac.

In the actual source ive only changed the opengl, glut and cg header files as per new instruction when compilation is on a mac.

Anyway this is the makefile and the error is below.

CC = g++
########################################################
# LIBRARY/FRAMEWORK INCLUDES -lXi-lXmu
#cgc -profile arbfp1 -o shader.pso shader.cg
#cgc -profile arbvp1 -o temp.vp test.cg
#glxinfo |grep programs
########################################################

# libraries required to compile for the labs
INCLUDE =
LIBDIR =
GLULIBDIR =
FRAMEWORK = -framework OpenGL -framework GLUT -framework SDL_image -framework SDL -framework Cg
LIBRARIES = -lm
ALLOFEM = $(FRAMEWORK) $(INCLUDE) $(LIBDIR) $(LIBRARIES) $(GLULIBDIR)

########################################################
# COMPILE FLAGS & OBJECT LIST
########################################################
DEBUG =
TOPS = galaxy.o SolidEntity.o
SOLID_OBJS = Stars.o Planets.o Earth.o Mars.o Venus.o Mercury.o Jupiter.o Saturn.o Uranus.o Neptune.o Pluto.o
UTILITY = Vec3.o Frustum.o FileReader.o Matrix4x4.o Camera.o Texture.o Shaders.o Utility.o
OBJECTS = $(TOPS) $(UTILITY) $(SOLID_OBJS)

########################################################
# DEPENDENCIES -Wall warnings
########################################################
all: galaxy

run: all
./galaxy 1

big: all
./galaxy 2

stereo: all
./galaxy 3

debug: all
gdb ./galaxy

%.o: %.cpp %.h
$(CC) -O3 -c -o $@ $< $(DEBUG) $(INCLUDE)

galaxy: $(OBJECTS)
$(CC) $(INCLUDE) $(OBJECTS) $(ALLOFEM) $(DEBUG) -O3 -o galaxy

tar:
tar -czvf proj497.tgz *.cpp *.h *.txt makefile

clean:
rm -rf *.o galaxy proj497.tgz


And the error message, it has to do with the final linking

g++ -O3 -c -o galaxy.o galaxy.cpp
g++ -O3 -c -o SolidEntity.o SolidEntity.cpp
g++ -O3 -c -o Vec3.o Vec3.cpp
g++ -O3 -c -o Frustum.o Frustum.cpp
g++ -O3 -c -o FileReader.o FileReader.cpp
g++ -O3 -c -o Matrix4x4.o Matrix4x4.cpp
g++ -O3 -c -o Camera.o Camera.cpp
g++ -O3 -c -o Texture.o Texture.cpp
g++ -O3 -c -o Shaders.o Shaders.cpp
g++ -O3 -c -o Utility.o Utility.cpp
g++ -O3 -c -o Stars.o Stars.cpp
g++ -O3 -c -o Planets.o Planets.cpp
g++ -O3 -c -o Earth.o Earth.cpp
g++ -O3 -c -o Mars.o Mars.cpp
g++ -O3 -c -o Venus.o Venus.cpp
g++ -O3 -c -o Mercury.o Mercury.cpp
g++ -O3 -c -o Jupiter.o Jupiter.cpp
g++ -O3 -c -o Saturn.o Saturn.cpp
g++ -O3 -c -o Uranus.o Uranus.cpp
g++ -O3 -c -o Neptune.o Neptune.cpp
g++ -O3 -c -o Pluto.o Pluto.cpp
g++ galaxy.o SolidEntity.o Vec3.o Frustum.o FileReader.o Matrix4x4.o Camera.o Texture.o Shaders.o Utility.o Stars.o Planets.o Earth.o Mars.o Venus.o Mercury.o Jupiter.o Saturn.o Uranus.o Neptune.o Pluto.o -framework OpenGL -framework GLUT -framework SDL_image -framework SDL -framework Cg -lm -O3 -o galaxy
/usr/bin/ld: Undefined symbols:
_main
collect2: ld returned 1 exit status
make: *** [galaxy] Error 1

Thanks guys for any and all help!
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
In my experience, that error means there is no main() function getting linked in. I guess look in the .cpps and see where the main function is (in galaxy.cpp?), and see if there's something wrong, somehow.
 

m3the01

macrumors member
Original poster
Jun 18, 2007
70
0
lol, i know thats what it looks like, but this is direct from galaxy.cpp

int main(int argc, char **argv) {


...
}
 

m3the01

macrumors member
Original poster
Jun 18, 2007
70
0
PS if i comment out most of the code in galaxy.cpp and drop all the include files except three of the vec3.cpp, cvert.cpp and camera.cpp everything works compiles doesnt do anything but works.

I tried to find the difference between these files but nothing sticks out, at the top of all .h files i always include the old

#ifndef Shaders_h
#define Shaders_h
....

#endif

Like i said though i never changed anything in the code except for
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#include <OpenGL/glext.h>
//#include <GL/gl.h>
//#include <GL/glu.h>
//#include <GL/glut.h>
//#include <GL/glext.h>

I now have it changed to the old ifmacos than include 'this' else include 'that' jargon.

Arggg.

PS the code works perfectly in every flavor of linux besides my new mac which i also know is based of freebsd unix;-)

Thanks guys,

Appreciate the help!
 

m3the01

macrumors member
Original poster
Jun 18, 2007
70
0
Sorry for so many post, but i hate filling lots in one post.

Someone suggested using -dynamiclib flag g++. However from my experience using this in the past we only need this when were actually making direct calls from a lib internally and need it loaded on the fly.

This works for compile time, understandably because were telling the compiler that everything will be loaded dynamically during runtime so dont worry about it.

However its not loaded dynamically and segfaults when this flag is used, -dynamiclib

Steven
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
You could try using otool -L <your_app> to see where it's trying to find your libs.
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
This is strange. Perhaps you should examine the results of preprocessing galaxy.cpp to make sure none of the included headers are interfering. From your experiment they are having some affect.

I can't remember the option to get the the results of preprocessing...
 

m3the01

macrumors member
Original poster
Jun 18, 2007
70
0
Yeah its pretty strange,

I get no warning or anything from -Wall -ansi

Ive done this type of thing so many times, i actually wrote some dummy apps with internal linking just to verify it does work under a mac. It does, but this setup doesnt seem to.

Any suggestions let me know,

thanks
 

m3the01

macrumors member
Original poster
Jun 18, 2007
70
0
I guess there are some setup issues i need to take care of


Q: What is SDLMain.m? Do I need it? Why is _main undefined?
A: Just like main() is the entry point for C programs (inc. C++, Objective-C, and Objective-C++), SDL_main() is the main entry point for SDL programs. However, you don't actually write an SDL_main() function. The header file "SDL_main.h" remaps your main() function to the SDL_main() function with a function macro. Your SDL_main() function is called after the code in SDLMain.m has performed the required "bootstrap" initializations to support the SDL runtime.

There are three things you have to do:

1. You must include either SDLMain.m/.h or libSDLmain in your application, because this is the code that defines SDL's entry point. If you fail to do this, it is likely that "_main undefined" will be thrown by the linker.
2. You must give your main() procedure the following prototype:

int main(int argc, char*argv[]);

3. You must make sure the file containing your main() procedure #includes SDL.h.

Otherwise, the macro will not remap main() to SDL_main(), you will get an undefined _main error, or the bootstrap process will not run, and SDL will behave strangely or your application will crash or hang.
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
Ah, so SDL is "hooking" the main function with the preprocessor.

That's pretty ugly. It looks like it has dependencies on Cocoa/Objective-C and this was the scheme for including and initializing the Objective-C runtime.
 

m3the01

macrumors member
Original poster
Jun 18, 2007
70
0
Still doesnt work though,

Tried and tried to include those files in galaxy.cpp and it just give me a whole wack of errors.

Arggg,

I need to show some people this app on thursday, its a n-body simulator running off the GPU.

Any help would be appreciated.
 

savar

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
Still doesnt work though,

Tried and tried to include those files in galaxy.cpp and it just give me a whole wack of errors.

Arggg,

I need to show some people this app on thursday, its a n-body simulator running off the GPU.

Any help would be appreciated.

Install Linux really quickly?
 

m3the01

macrumors member
Original poster
Jun 18, 2007
70
0
I have another computer i could use but damn,

Ive got everything working on the mac and luv it, its fast, pretty need help.

Steven
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
Hi
I've not used SDL but I had a quick look at ReadMeDevLite.txt it mentions:-

An SDL/OpenGL based application might look like:

gcc -I/Library/Frameworks/SDL.framework/Headers -I/System/Library/Frameworks/OpenGL.framework/Headers MyProgram.c SDLmain.m -framework SDL -framework Cocoa -framework OpenGL

I notice you're not compiling SDLmain.m or linking to Cocoa… though you are linking to SDL_image whatever that is.

Hope this helps

b e n
 

bronxbomber92

macrumors regular
Nov 23, 2006
109
0
Have you tried using an Xcode project, instead of compiling from command line using a makefile? It might be a lot easier. Just use the SDL OpenGL template, delete the files, add your source [and any framework besides Cocoa, OpenGL and SDL which are all ready added], and compile.
 

m3the01

macrumors member
Original poster
Jun 18, 2007
70
0
After much help from everyone this is where im at,

Not including anything in main/galaxy.cpp except
#include <sdl/sdl.h>

make
g++ -c -O3 -o galaxy.o galaxy.cpp
g++ -c -O3 -o SolidEntity.o SolidEntity.cpp
g++ -c -O3 -o Vec3.o Vec3.cpp
g++ -c -O3 -o Frustum.o Frustum.cpp
g++ -c -O3 -o FileReader.o FileReader.cpp
g++ -c -O3 -o Matrix4x4.o Matrix4x4.cpp
g++ -c -O3 -o Camera.o Camera.cpp
g++ -c -O3 -o Texture.o Texture.cpp
g++ -c -O3 -o Shaders.o Shaders.cpp
g++ -c -O3 -o Utility.o Utility.cpp
g++ -c -O3 -o Stars.o Stars.cpp
g++ -c -O3 -o Planets.o Planets.cpp
g++ -c -O3 -o Earth.o Earth.cpp
g++ -c -O3 -o Mars.o Mars.cpp
g++ -c -O3 -o Venus.o Venus.cpp
g++ -c -O3 -o Mercury.o Mercury.cpp
g++ -c -O3 -o Jupiter.o Jupiter.cpp
g++ -c -O3 -o Saturn.o Saturn.cpp
g++ -c -O3 -o Uranus.o Uranus.cpp
g++ -c -O3 -o Neptune.o Neptune.cpp
g++ -c -O3 -o Pluto.o Pluto.cpp
g++ -O3 -o galaxy SDLMain.m galaxy.o SolidEntity.o Vec3.o Frustum.o FileReader.o Matrix4x4.o Camera.o Texture.o Shaders.o Utility.o Stars.o Planets.o Earth.o Mars.o Venus.o Mercury.o Jupiter.o Saturn.o Uranus.o Neptune.o Pluto.o -lm -framework OpenGL -framework GLUT -framework SDL_image -framework SDL -framework Cg
/usr/bin/ld: Undefined symbols:
.objc_class_name_NSApplication
.objc_class_name_NSAutoreleasePool
.objc_class_name_NSMenu
.objc_class_name_NSMenuItem
.objc_class_name_NSObject
.objc_class_name_NSProcessInfo
.objc_class_name_NSString
_CFBundleCopyBundleURL
_CFBundleGetInfoDictionary
_CFBundleGetMainBundle
_CFRelease
_CFURLCreateCopyDeletingLastPathComponent
_CFURLGetFileSystemRepresentation
_CPSEnableForegroundOperation
_CPSGetCurrentProcess
_CPSSetFrontProcess
_NSAllocateMemoryPages
_NSApp
_NSDeallocateMemoryPages
___CFConstantStringClassReference
_objc_msgSend
collect2: ld returned 1 exit status
make: *** [galaxy] Error 1

PS i will eventually use xcode, really new to the mac development suite. I noticed there was no opengl tutorials and just attempted to get it working.

Its really the only thing ive had troubles with.

Thanks for the help everyone its really appreciated!
 

m3the01

macrumors member
Original poster
Jun 18, 2007
70
0
Just for reference purposes if anyone uses this thread in the future,

I added -Framework cocoa in the makefile to get rid of those errors on the previous post.


Everything works perfect,

here is the final makefile,

############
MACHINE= $(shell uname -s)
########################################################
# LIBRARY/FRAMEWORK INCLUDES -lXi-lXmu
#cgc -profile arbfp1 -o shader.pso shader.cg
#cgc -profile arbvp1 -o temp.vp test.cg
#glxinfo |grep programs
########################################################

ifeq ($(MACHINE),Darwin)
OPENGL_INC=
OPENGL_LIB= -framework Cocoa -framework OpenGL -framework GLUT -framework SDL_image -framework SDL -framework Cg
SDL_INC=
SDL_LIB=

else
OPENGL_INC=
OPENGL_LIB=
SDL_INC=
SDL_LIB=
endif
CC = g++
# libraries required to compile for the labs
INCLUDE= $(SDL_INC) $(OPENGL_INC)
LIBRARIES = -lm $(SDL_LIB) $(OPENGL_LIB)
ALLOFEM = $(INCLUDE) $(LIBRARIES)
########################################################
# COMPILE FLAGS & OBJECT LIST
########################################################
DEBUG =
OTHERS = SDLMain.m
TOPS = galaxy.o SolidEntity.o
SOLID_OBJS = Stars.o Planets.o Earth.o Mars.o Venus.o Mercury.o Jupiter.o Saturn.o Uranus.o Neptune.o Pluto.o
UTILITY = Vec3.o Frustum.o FileReader.o Matrix4x4.o Camera.o Texture.o Shaders.o Utility.o
OBJECTS = $(OTHERS) $(TOPS) $(UTILITY) $(SOLID_OBJS)
EXECUTABLE = galaxy
########################################################
# DEPENDENCIES -Wall warnings
########################################################
all: galaxy

run: all
./galaxy 1

big: all
./galaxy 2

stereo: all
./galaxy 3

debug: all
gdb ./galaxy

%.o: %.cpp %.h
$(CC) -c -O3 -o $@ $< $(INCLUDE)

$(EXECUTABLE): $(OBJECTS)
$(CC) -O3 -o $(EXECUTABLE) $(OBJECTS) $(LIBRARIES)

tar:
tar -czvf proj497.tgz *.cpp *.h *.txt makefile

clean:
rm -rf *.o galaxy proj497.tgz
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.