OpenGL, GLUT, SDL, SDL_image Arggg. Please help!

Discussion in 'Mac Programming' started by m3the01, Jun 18, 2007.

  1. m3the01 macrumors member

    Joined:
    Jun 18, 2007
    #1
    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!
     
  2. iSee macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #2
    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.
     
  3. ExoticFish macrumors 6502a

    ExoticFish

    Joined:
    Dec 3, 2002
    Location:
    The inner depths of madness, aka Kent, OH
    #3
    i had a problem like this awhile ago and i figured out that i had to setup the main to accept arguments:

    Code:
    int main(int argc, char *argv[]) {}
     
  4. m3the01 thread starter macrumors member

    Joined:
    Jun 18, 2007
    #4
    lol, i know thats what it looks like, but this is direct from galaxy.cpp

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


    ...
    }
     
  5. m3the01 thread starter macrumors member

    Joined:
    Jun 18, 2007
    #5
    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!
     
  6. m3the01 thread starter macrumors member

    Joined:
    Jun 18, 2007
  7. m3the01 thread starter macrumors member

    Joined:
    Jun 18, 2007
    #7
    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
     
  8. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    You could try using otool -L <your_app> to see where it's trying to find your libs.
     
  9. iSee macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #9
    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...
     
  10. m3the01 thread starter macrumors member

    Joined:
    Jun 18, 2007
    #10
    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
     
  11. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #11
    Have you tried putting an intentional syntax error within main() just to make sure it is being compiled.

    b e n
     
  12. m3the01 thread starter macrumors member

    Joined:
    Jun 18, 2007
    #12
    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.
     
  13. iSee macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #13
    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.
     
  14. m3the01 thread starter macrumors member

    Joined:
    Jun 18, 2007
    #14
    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.
     
  15. savar macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #15
    Install Linux really quickly?
     
  16. m3the01 thread starter macrumors member

    Joined:
    Jun 18, 2007
    #16
    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
     
  17. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #17
    Have you linked to Cocoa? Just had a quick look at SDLmain.m and it uses Cocoa.

    b e n
     
  18. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #18
    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
     
  19. bronxbomber92 macrumors regular

    Joined:
    Nov 23, 2006
    #19
    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.
     
  20. m3the01 thread starter macrumors member

    Joined:
    Jun 18, 2007
    #20
    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!
     
  21. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #21
    Looks like all you need now is to link in the Cocoa framework!

    -framework Cocoa


    b e n
     
  22. m3the01 thread starter macrumors member

    Joined:
    Jun 18, 2007
    #22
    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
     

Share This Page