mac、netbeans 6.8、c++、sdl、opengl:编译问题

发布于 2024-08-27 14:31:51 字数 14376 浏览 11 评论 0原文

我正在尝试在 Snow Leopard 64 位下使用 netbeans 6.8 正确编译 c++ opengl+sdl 应用程序。

我使用 macports 安装了 libSDL 1.2.14。

我尝试编译的脚本如下:

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#if defined(__APPLE__) && defined(__MACH__)
#include <OpenGL/gl.h>  // Header File For The OpenGL32 Library
#include <OpenGL/glu.h> // Header File For The GLu32 Library
#else
#include <GL/gl.h>  // Header File For The OpenGL32 Library
#include <GL/glu.h> // Header File For The GLu32 Library
#endif
#include "sdl/SDL.h"
#include <stdio.h>
#include <unistd.h>
#include "SDL/SDL_main.h"

SDL_Surface *screen=NULL;

GLfloat     rtri;                       // Angle For The Triangle ( NEW )
GLfloat     rquad;                      // Angle For The Quad     ( NEW )


void InitGL(int Width, int Height)          // We call this right after our OpenGL window is created.
{
glViewport(0, 0, Width, Height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);       // This Will Clear The Background Color To Black
glClearDepth(1.0);              // Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS);               // The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST);            // Enables Depth Testing
glShadeModel(GL_SMOOTH);            // Enables Smooth Color Shading

glMatrixMode(GL_PROJECTION);
glLoadIdentity();               // Reset The Projection Matrix

gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);   // Calculate The Aspect Ratio Of The Window

glMatrixMode(GL_MODELVIEW);
}

/* The main drawing function. */
int DrawGLScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     // Clear The Screen And The Depth Buffer
glLoadIdentity();               // Reset The View

glTranslatef(-1.5f,0.0f,-6.0f);     // Move Left 1.5 Units And Into The Screen 6.0
glRotatef(rtri,0.0f,1.0f,0.0f);             // Rotate The Triangle On The Y axis ( NEW )

// draw a triangle
    glBegin(GL_TRIANGLES);                  // Begin Drawing Triangles
glColor3f(1.0f,0.0f,0.0f);          // Red
glVertex3f( 0.0f, 1.0f, 0.0f);          // Top Of Triangle (Front)
glColor3f(0.0f,1.0f,0.0f);          // Green
glVertex3f(-1.0f,-1.0f, 1.0f);          // Left Of Triangle (Front)
glColor3f(0.0f,0.0f,1.0f);          // Blue
glVertex3f( 1.0f,-1.0f, 1.0f);          // Right Of Triangle (Front)
glColor3f(1.0f,0.0f,0.0f);          // Red
glVertex3f( 0.0f, 1.0f, 0.0f);          // Top Of Triangle (Right)
glColor3f(0.0f,0.0f,1.0f);          // Blue
glVertex3f( 1.0f,-1.0f, 1.0f);          // Left Of Triangle (Right)
glColor3f(0.0f,1.0f,0.0f);          // Green
glVertex3f( 1.0f,-1.0f, -1.0f);         // Right Of Triangle (Right)
glColor3f(1.0f,0.0f,0.0f);          // Red
glVertex3f( 0.0f, 1.0f, 0.0f);          // Top Of Triangle (Back)
glColor3f(0.0f,1.0f,0.0f);          // Green
glVertex3f( 1.0f,-1.0f, -1.0f);         // Left Of Triangle (Back)
glColor3f(0.0f,0.0f,1.0f);          // Blue
glVertex3f(-1.0f,-1.0f, -1.0f);         // Right Of Triangle (Back)
glColor3f(1.0f,0.0f,0.0f);          // Red
glVertex3f( 0.0f, 1.0f, 0.0f);          // Top Of Triangle (Left)
glColor3f(0.0f,0.0f,1.0f);          // Blue
glVertex3f(-1.0f,-1.0f,-1.0f);          // Left Of Triangle (Left)
glColor3f(0.0f,1.0f,0.0f);          // Green
glVertex3f(-1.0f,-1.0f, 1.0f);          // Right Of Triangle (Left)
glEnd();
glLoadIdentity();                   // Reset The Current Modelview Matrix
glTranslatef(1.5f,0.0f,-7.0f);              // Move Right 1.5 Units And Into The Screen 6.0
glRotatef(rquad,1.0f,0.0f,0.0f);            // Rotate The Quad On The X axis ( NEW )
glBegin(GL_QUADS);                  // Start Drawing Quads
glColor3f(0.0f,1.0f,0.0f);          // Set The Color To Green
glVertex3f( 1.0f, 1.0f,-1.0f);          // Top Right Of The Quad (Top)
glVertex3f(-1.0f, 1.0f,-1.0f);          // Top Left Of The Quad (Top)
glVertex3f(-1.0f, 1.0f, 1.0f);          // Bottom Left Of The Quad (Top)
glVertex3f( 1.0f, 1.0f, 1.0f);          // Bottom Right Of The Quad (Top)
glColor3f(1.0f,0.5f,0.0f);          // Set The Color To Orange
glVertex3f( 1.0f,-1.0f, 1.0f);          // Top Right Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f, 1.0f);          // Top Left Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f,-1.0f);          // Bottom Left Of The Quad (Bottom)
glVertex3f( 1.0f,-1.0f,-1.0f);          // Bottom Right Of The Quad (Bottom)
glColor3f(1.0f,0.0f,0.0f);          // Set The Color To Red
glVertex3f( 1.0f, 1.0f, 1.0f);          // Top Right Of The Quad (Front)
glVertex3f(-1.0f, 1.0f, 1.0f);          // Top Left Of The Quad (Front)
glVertex3f(-1.0f,-1.0f, 1.0f);          // Bottom Left Of The Quad (Front)
glVertex3f( 1.0f,-1.0f, 1.0f);          // Bottom Right Of The Quad (Front)
glColor3f(1.0f,1.0f,0.0f);          // Set The Color To Yellow
glVertex3f( 1.0f,-1.0f,-1.0f);          // Bottom Left Of The Quad (Back)
glVertex3f(-1.0f,-1.0f,-1.0f);          // Bottom Right Of The Quad (Back)
glVertex3f(-1.0f, 1.0f,-1.0f);          // Top Right Of The Quad (Back)
glVertex3f( 1.0f, 1.0f,-1.0f);          // Top Left Of The Quad (Back)

glColor3f(0.0f,0.0f,1.0f);          // Set The Color To Blue
glVertex3f(-1.0f, 1.0f, 1.0f);          // Top Right Of The Quad (Left)
glVertex3f(-1.0f, 1.0f,-1.0f);          // Top Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f,-1.0f);          // Bottom Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f, 1.0f);          // Bottom Right Of The Quad (Left)
glColor3f(1.0f,0.0f,1.0f);          // Set The Color To Violet
glVertex3f( 1.0f, 1.0f,-1.0f);          // Top Right Of The Quad (Right)
glVertex3f( 1.0f, 1.0f, 1.0f);          // Top Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f, 1.0f);          // Bottom Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f,-1.0f);          // Bottom Right Of The Quad (Right)

glEnd();                        // Done Drawing A Quad
rtri+=0.02f;                        // Increase The Rotation Variable For The Triangle ( NEW )
rquad-=0.015f;                      // Decrease The Rotation Variable For The Quad     ( NEW )


// swap buffers to display, since we're double buffered.
SDL_GL_SwapBuffers();
return true;
}


int main(int argc,char* argv[])
{
int done;
/*variable to hold the file name of the image to be loaded
 *In real world error handling code would precede this
 */

/* Initialize SDL for video output */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
    exit(1);
}

atexit(SDL_Quit);

/* Create a 640x480 OpenGL screen */
if ( SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL ) {
    fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError());
    SDL_Quit();
    exit(2);
}
SDL_WM_SetCaption("another example",NULL);
InitGL(640,480);
done=0;
while (! done) {
    DrawGLScene();
    SDL_Event event;
    while ( SDL_PollEvent(&event) ) {
        if ( event.type == SDL_QUIT ) {
            done = 1;
        }
        if ( event.type == SDL_KEYDOWN ) {
            if ( event.key.keysym.sym == SDLK_ESCAPE ) {
                done = 1;
            }
        }
    }
}
}

在 netbeans 项目属性下,我配置了以下内容:

C++ 编译器:添加了 /usr/X11/include/opt/local/include > 到包含目录。 链接器:我添加了以下库:

/usr/X11/lib/libGL.dylib
/usr/X11/lib/libGLU.dylib
/opt/local/lib/libSDL.dylib
/opt/local/lib/libSDLmain.a

现在...在将 SDL_main.h 和 libSDLMain.a 包含到项目中之前,我收到错误对 _main 的未知引用

然后我在这里阅读:http://www.libsdl.org/faq.php?action=listentries&category =7#55

我需要包含 SDL_Main.h 并将 libSDLMain.so 链接到我的项目。

这样做之后,该项目仍然无法编译。这是 Netbeans 的输出:

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .clean-conf

rm -f -r build/Debug

rm -f dist/Debug/GNU-MacOSX/opengl2

CLEAN SUCCESSFUL (total time: 79ms)


/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf

/usr/bin/make  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/opengl2

mkdir -p build/Debug/GNU-MacOSX

rm -f build/Debug/GNU-MacOSX/main.o.d

g++    -c -g -I/usr/X11/include -I/opt/local/include -MMD -MP -MF build/Debug/GNU-MacOSX/main.o.d -o build/Debug/GNU-MacOSX/main.o main.cpp

mkdir -p dist/Debug/GNU-MacOSX

g++     -o dist/Debug/GNU-MacOSX/opengl2 build/Debug/GNU-MacOSX/main.o /opt/local/lib/libIL.dylib /opt/local/lib/libILU.dylib /opt/local/lib/libILUT.dylib /usr/X11/lib/libGL.dylib /usr/X11/lib/libGLU.dylib /opt/local/lib/libSDL.dylib /opt/local/lib/libSDLmain.a 

Undefined symbols:

"_OBJC_CLASS_$_NSMenu", referenced from:
  __objc_classrefs__DATA@0 in libSDLmain.a(SDLMain.o)
"__objc_empty_cache", referenced from:
  _OBJC_METACLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
  _OBJC_CLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
"_CFBundleGetMainBundle", referenced from:
  -[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
"_CFURLGetFileSystemRepresentation", referenced from:
  -[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_NSApp", referenced from:
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSProcessInfo", referenced from:
  __objc_classrefs__DATA@0 in libSDLmain.a(SDLMain.o)
"_CFURLCreateCopyDeletingLastPathComponent", referenced from:
  -[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_NSAllocateMemoryPages", referenced from:
  -[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
"___CFConstantStringClassReference", referenced from:
  cfstring=CFBundleName in libSDLmain.a(SDLMain.o)
  cfstring= in libSDLmain.a(SDLMain.o)
  cfstring=About  in libSDLmain.a(SDLMain.o)
  cfstring=Hide  in libSDLmain.a(SDLMain.o)
  cfstring=h in libSDLmain.a(SDLMain.o)
  cfstring=Hide Others in libSDLmain.a(SDLMain.o)
  cfstring=Show All in libSDLmain.a(SDLMain.o)
  cfstring=Quit  in libSDLmain.a(SDLMain.o)
  cfstring=q in libSDLmain.a(SDLMain.o)
  cfstring=Window in libSDLmain.a(SDLMain.o)
  cfstring=m in libSDLmain.a(SDLMain.o)
  cfstring=Minimize in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSAutoreleasePool", referenced from:
  __objc_classrefs__DATA@0 in libSDLmain.a(SDLMain.o)
"_CPSEnableForegroundOperation", referenced from:
  _main in libSDLmain.a(SDLMain.o)
"_CPSGetCurrentProcess", referenced from:
  _main in libSDLmain.a(SDLMain.o)
"_CFBundleCopyBundleURL", referenced from:
  -[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_NSDeallocateMemoryPages", referenced from:
  -[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSApplication", referenced from:
  l_OBJC_$_CATEGORY_NSApplication_$_SDLApplication in libSDLmain.a(SDLMain.o)
  __objc_classrefs__DATA@0 in libSDLmain.a(SDLMain.o)
"_CPSSetFrontProcess", referenced from:
  _main in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSString", referenced from:
  l_OBJC_$_CATEGORY_NSString_$_ReplaceSubString in libSDLmain.a(SDLMain.o)
  __objc_classrefs__DATA@0 in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSObject", referenced from:
  _OBJC_CLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
"_CFBundleGetInfoDictionary", referenced from:
  _main in libSDLmain.a(SDLMain.o)
"_CFRelease", referenced from:
  -[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
  -[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"__objc_empty_vtable", referenced from:
  _OBJC_METACLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
  _OBJC_CLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSMenuItem", referenced from:
  __objc_classrefs__DATA@0 in libSDLmain.a(SDLMain.o)
"_objc_msgSend", referenced from:
  -[SDLMain application:openFile:] in libSDLmain.a(SDLMain.o)
  -[SDLMain applicationDidFinishLaunching:] in libSDLmain.a(SDLMain.o)
  -[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
  -[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
  -[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
  -[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
"_OBJC_METACLASS_$_NSObject", referenced from:
  _OBJC_METACLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
  _OBJC_METACLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
"_objc_msgSend_fixup", referenced from:
  l_objc_msgSend_fixup_objectForKey_ in libSDLmain.a(SDLMain.o)
  l_objc_msgSend_fixup_length in libSDLmain.a(SDLMain.o)
  l_objc_msgSend_fixup_alloc in libSDLmain.a(SDLMain.o)
  l_objc_msgSend_fixup_release in libSDLmain.a(SDLMain.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-MacOSX/opengl2] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 263ms)

有什么想法吗?

多谢!

I'm trying to properly compile a c++ opengl+sdl application using netbeans 6.8 under Snow Leopard 64-bit.

I have libSDL 1.2.14 installed using macports.

The script that I try to compile is the following:

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#if defined(__APPLE__) && defined(__MACH__)
#include <OpenGL/gl.h>  // Header File For The OpenGL32 Library
#include <OpenGL/glu.h> // Header File For The GLu32 Library
#else
#include <GL/gl.h>  // Header File For The OpenGL32 Library
#include <GL/glu.h> // Header File For The GLu32 Library
#endif
#include "sdl/SDL.h"
#include <stdio.h>
#include <unistd.h>
#include "SDL/SDL_main.h"

SDL_Surface *screen=NULL;

GLfloat     rtri;                       // Angle For The Triangle ( NEW )
GLfloat     rquad;                      // Angle For The Quad     ( NEW )


void InitGL(int Width, int Height)          // We call this right after our OpenGL window is created.
{
glViewport(0, 0, Width, Height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);       // This Will Clear The Background Color To Black
glClearDepth(1.0);              // Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS);               // The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST);            // Enables Depth Testing
glShadeModel(GL_SMOOTH);            // Enables Smooth Color Shading

glMatrixMode(GL_PROJECTION);
glLoadIdentity();               // Reset The Projection Matrix

gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);   // Calculate The Aspect Ratio Of The Window

glMatrixMode(GL_MODELVIEW);
}

/* The main drawing function. */
int DrawGLScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     // Clear The Screen And The Depth Buffer
glLoadIdentity();               // Reset The View

glTranslatef(-1.5f,0.0f,-6.0f);     // Move Left 1.5 Units And Into The Screen 6.0
glRotatef(rtri,0.0f,1.0f,0.0f);             // Rotate The Triangle On The Y axis ( NEW )

// draw a triangle
    glBegin(GL_TRIANGLES);                  // Begin Drawing Triangles
glColor3f(1.0f,0.0f,0.0f);          // Red
glVertex3f( 0.0f, 1.0f, 0.0f);          // Top Of Triangle (Front)
glColor3f(0.0f,1.0f,0.0f);          // Green
glVertex3f(-1.0f,-1.0f, 1.0f);          // Left Of Triangle (Front)
glColor3f(0.0f,0.0f,1.0f);          // Blue
glVertex3f( 1.0f,-1.0f, 1.0f);          // Right Of Triangle (Front)
glColor3f(1.0f,0.0f,0.0f);          // Red
glVertex3f( 0.0f, 1.0f, 0.0f);          // Top Of Triangle (Right)
glColor3f(0.0f,0.0f,1.0f);          // Blue
glVertex3f( 1.0f,-1.0f, 1.0f);          // Left Of Triangle (Right)
glColor3f(0.0f,1.0f,0.0f);          // Green
glVertex3f( 1.0f,-1.0f, -1.0f);         // Right Of Triangle (Right)
glColor3f(1.0f,0.0f,0.0f);          // Red
glVertex3f( 0.0f, 1.0f, 0.0f);          // Top Of Triangle (Back)
glColor3f(0.0f,1.0f,0.0f);          // Green
glVertex3f( 1.0f,-1.0f, -1.0f);         // Left Of Triangle (Back)
glColor3f(0.0f,0.0f,1.0f);          // Blue
glVertex3f(-1.0f,-1.0f, -1.0f);         // Right Of Triangle (Back)
glColor3f(1.0f,0.0f,0.0f);          // Red
glVertex3f( 0.0f, 1.0f, 0.0f);          // Top Of Triangle (Left)
glColor3f(0.0f,0.0f,1.0f);          // Blue
glVertex3f(-1.0f,-1.0f,-1.0f);          // Left Of Triangle (Left)
glColor3f(0.0f,1.0f,0.0f);          // Green
glVertex3f(-1.0f,-1.0f, 1.0f);          // Right Of Triangle (Left)
glEnd();
glLoadIdentity();                   // Reset The Current Modelview Matrix
glTranslatef(1.5f,0.0f,-7.0f);              // Move Right 1.5 Units And Into The Screen 6.0
glRotatef(rquad,1.0f,0.0f,0.0f);            // Rotate The Quad On The X axis ( NEW )
glBegin(GL_QUADS);                  // Start Drawing Quads
glColor3f(0.0f,1.0f,0.0f);          // Set The Color To Green
glVertex3f( 1.0f, 1.0f,-1.0f);          // Top Right Of The Quad (Top)
glVertex3f(-1.0f, 1.0f,-1.0f);          // Top Left Of The Quad (Top)
glVertex3f(-1.0f, 1.0f, 1.0f);          // Bottom Left Of The Quad (Top)
glVertex3f( 1.0f, 1.0f, 1.0f);          // Bottom Right Of The Quad (Top)
glColor3f(1.0f,0.5f,0.0f);          // Set The Color To Orange
glVertex3f( 1.0f,-1.0f, 1.0f);          // Top Right Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f, 1.0f);          // Top Left Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f,-1.0f);          // Bottom Left Of The Quad (Bottom)
glVertex3f( 1.0f,-1.0f,-1.0f);          // Bottom Right Of The Quad (Bottom)
glColor3f(1.0f,0.0f,0.0f);          // Set The Color To Red
glVertex3f( 1.0f, 1.0f, 1.0f);          // Top Right Of The Quad (Front)
glVertex3f(-1.0f, 1.0f, 1.0f);          // Top Left Of The Quad (Front)
glVertex3f(-1.0f,-1.0f, 1.0f);          // Bottom Left Of The Quad (Front)
glVertex3f( 1.0f,-1.0f, 1.0f);          // Bottom Right Of The Quad (Front)
glColor3f(1.0f,1.0f,0.0f);          // Set The Color To Yellow
glVertex3f( 1.0f,-1.0f,-1.0f);          // Bottom Left Of The Quad (Back)
glVertex3f(-1.0f,-1.0f,-1.0f);          // Bottom Right Of The Quad (Back)
glVertex3f(-1.0f, 1.0f,-1.0f);          // Top Right Of The Quad (Back)
glVertex3f( 1.0f, 1.0f,-1.0f);          // Top Left Of The Quad (Back)

glColor3f(0.0f,0.0f,1.0f);          // Set The Color To Blue
glVertex3f(-1.0f, 1.0f, 1.0f);          // Top Right Of The Quad (Left)
glVertex3f(-1.0f, 1.0f,-1.0f);          // Top Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f,-1.0f);          // Bottom Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f, 1.0f);          // Bottom Right Of The Quad (Left)
glColor3f(1.0f,0.0f,1.0f);          // Set The Color To Violet
glVertex3f( 1.0f, 1.0f,-1.0f);          // Top Right Of The Quad (Right)
glVertex3f( 1.0f, 1.0f, 1.0f);          // Top Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f, 1.0f);          // Bottom Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f,-1.0f);          // Bottom Right Of The Quad (Right)

glEnd();                        // Done Drawing A Quad
rtri+=0.02f;                        // Increase The Rotation Variable For The Triangle ( NEW )
rquad-=0.015f;                      // Decrease The Rotation Variable For The Quad     ( NEW )


// swap buffers to display, since we're double buffered.
SDL_GL_SwapBuffers();
return true;
}


int main(int argc,char* argv[])
{
int done;
/*variable to hold the file name of the image to be loaded
 *In real world error handling code would precede this
 */

/* Initialize SDL for video output */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
    exit(1);
}

atexit(SDL_Quit);

/* Create a 640x480 OpenGL screen */
if ( SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL ) {
    fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError());
    SDL_Quit();
    exit(2);
}
SDL_WM_SetCaption("another example",NULL);
InitGL(640,480);
done=0;
while (! done) {
    DrawGLScene();
    SDL_Event event;
    while ( SDL_PollEvent(&event) ) {
        if ( event.type == SDL_QUIT ) {
            done = 1;
        }
        if ( event.type == SDL_KEYDOWN ) {
            if ( event.key.keysym.sym == SDLK_ESCAPE ) {
                done = 1;
            }
        }
    }
}
}

Under netbeans project properties I configured the following:

C++ Compiler: added /usr/X11/include and /opt/local/include to the include directories.
Linker: I added the following libraries:

/usr/X11/lib/libGL.dylib
/usr/X11/lib/libGLU.dylib
/opt/local/lib/libSDL.dylib
/opt/local/lib/libSDLmain.a

Now... before I included SDL_main.h and libSDLMain.a to the project I got an error unknown reference to _main

then I read here: http://www.libsdl.org/faq.php?action=listentries&category=7#55

that I need to include SDL_Main.h and to link libSDLMain.so to my project.

after doing so, the project still won't compile. this is the Netbeans output:

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .clean-conf

rm -f -r build/Debug

rm -f dist/Debug/GNU-MacOSX/opengl2

CLEAN SUCCESSFUL (total time: 79ms)


/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf

/usr/bin/make  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/opengl2

mkdir -p build/Debug/GNU-MacOSX

rm -f build/Debug/GNU-MacOSX/main.o.d

g++    -c -g -I/usr/X11/include -I/opt/local/include -MMD -MP -MF build/Debug/GNU-MacOSX/main.o.d -o build/Debug/GNU-MacOSX/main.o main.cpp

mkdir -p dist/Debug/GNU-MacOSX

g++     -o dist/Debug/GNU-MacOSX/opengl2 build/Debug/GNU-MacOSX/main.o /opt/local/lib/libIL.dylib /opt/local/lib/libILU.dylib /opt/local/lib/libILUT.dylib /usr/X11/lib/libGL.dylib /usr/X11/lib/libGLU.dylib /opt/local/lib/libSDL.dylib /opt/local/lib/libSDLmain.a 

Undefined symbols:

"_OBJC_CLASS_$_NSMenu", referenced from:
  __objc_classrefs__DATA@0 in libSDLmain.a(SDLMain.o)
"__objc_empty_cache", referenced from:
  _OBJC_METACLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
  _OBJC_CLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
"_CFBundleGetMainBundle", referenced from:
  -[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
"_CFURLGetFileSystemRepresentation", referenced from:
  -[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_NSApp", referenced from:
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSProcessInfo", referenced from:
  __objc_classrefs__DATA@0 in libSDLmain.a(SDLMain.o)
"_CFURLCreateCopyDeletingLastPathComponent", referenced from:
  -[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_NSAllocateMemoryPages", referenced from:
  -[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
"___CFConstantStringClassReference", referenced from:
  cfstring=CFBundleName in libSDLmain.a(SDLMain.o)
  cfstring= in libSDLmain.a(SDLMain.o)
  cfstring=About  in libSDLmain.a(SDLMain.o)
  cfstring=Hide  in libSDLmain.a(SDLMain.o)
  cfstring=h in libSDLmain.a(SDLMain.o)
  cfstring=Hide Others in libSDLmain.a(SDLMain.o)
  cfstring=Show All in libSDLmain.a(SDLMain.o)
  cfstring=Quit  in libSDLmain.a(SDLMain.o)
  cfstring=q in libSDLmain.a(SDLMain.o)
  cfstring=Window in libSDLmain.a(SDLMain.o)
  cfstring=m in libSDLmain.a(SDLMain.o)
  cfstring=Minimize in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSAutoreleasePool", referenced from:
  __objc_classrefs__DATA@0 in libSDLmain.a(SDLMain.o)
"_CPSEnableForegroundOperation", referenced from:
  _main in libSDLmain.a(SDLMain.o)
"_CPSGetCurrentProcess", referenced from:
  _main in libSDLmain.a(SDLMain.o)
"_CFBundleCopyBundleURL", referenced from:
  -[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_NSDeallocateMemoryPages", referenced from:
  -[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSApplication", referenced from:
  l_OBJC_$_CATEGORY_NSApplication_$_SDLApplication in libSDLmain.a(SDLMain.o)
  __objc_classrefs__DATA@0 in libSDLmain.a(SDLMain.o)
"_CPSSetFrontProcess", referenced from:
  _main in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSString", referenced from:
  l_OBJC_$_CATEGORY_NSString_$_ReplaceSubString in libSDLmain.a(SDLMain.o)
  __objc_classrefs__DATA@0 in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSObject", referenced from:
  _OBJC_CLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
"_CFBundleGetInfoDictionary", referenced from:
  _main in libSDLmain.a(SDLMain.o)
"_CFRelease", referenced from:
  -[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
  -[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"__objc_empty_vtable", referenced from:
  _OBJC_METACLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
  _OBJC_CLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSMenuItem", referenced from:
  __objc_classrefs__DATA@0 in libSDLmain.a(SDLMain.o)
"_objc_msgSend", referenced from:
  -[SDLMain application:openFile:] in libSDLmain.a(SDLMain.o)
  -[SDLMain applicationDidFinishLaunching:] in libSDLmain.a(SDLMain.o)
  -[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
  -[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
  -[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
  -[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
  _main in libSDLmain.a(SDLMain.o)
"_OBJC_METACLASS_$_NSObject", referenced from:
  _OBJC_METACLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
  _OBJC_METACLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
"_objc_msgSend_fixup", referenced from:
  l_objc_msgSend_fixup_objectForKey_ in libSDLmain.a(SDLMain.o)
  l_objc_msgSend_fixup_length in libSDLmain.a(SDLMain.o)
  l_objc_msgSend_fixup_alloc in libSDLmain.a(SDLMain.o)
  l_objc_msgSend_fixup_release in libSDLmain.a(SDLMain.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-MacOSX/opengl2] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 263ms)

any ideas?

thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

朦胧时间 2024-09-03 14:31:51

将“-framework Cocoa”添加到编译器的命令行中。

Add "-framework Cocoa" to the compiler's command line.

得不到的就毁灭 2024-09-03 14:31:51

为什么不尝试使用 pkg-config ,如下所示:
'pkg-config --cflags --libs sdl' (这些应该是重音符号,但它们已从答案中删除。)
将该行的输出放在您的输出之后,或者执行以下操作:
g++ -o dist/Debug/GNU-MacOSX/opengl2 build/Debug/GNU-MacOSX/main.o 'pkg-config --cflags --libs ilut' 'pkg-config --cflags --libs glu' 'pkg- config --cflags --libs sdl'

(请替换 '')
不确定 ilut 命名约定。
您可能需要也可能不需要在最后添加一个 OpenGL 框架。
(抱歉回复晚了=p)

Why dont you try to use pkg-config as in:
'pkg-config --cflags --libs sdl' (these are suposed to be accents but those are removed from the answer.)
Place the output of that line after yours, or do something like:
g++ -o dist/Debug/GNU-MacOSX/opengl2 build/Debug/GNU-MacOSX/main.o 'pkg-config --cflags --libs ilut' 'pkg-config --cflags --libs glu' 'pkg-config --cflags --libs sdl'

(do replace the '')
not sure about the ilut naming convention.
you may or may not need to add a -framework OpenGL there at the end.
(Sorry for the late answer =p)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文