我對使用OpenGL很新穎。我試圖運行的程序是由我的教授提供的,所以我實際上沒有寫任何程序,我在運行程序時遇到問題。該程序假設只是在黑色屏幕上製作一個白色正方形。我正在使用mac Sierra 10.12.2。此外,我已經將部署目標更改爲10.8,因爲在晚些時候編譯的錯誤。現在,當我嘗試構建並在xcode中運行時,我得到2個錯誤。未找到架構x86_64的符號(OpenGL with xcode)
這些都是錯誤的即時得到,
Undefined symbols for architecture x86_64:
"exit(int)", referenced from:
myKeyboard(unsigned char, int, int) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
現在,這裏是完全一樣的,我試圖編譯的代碼。
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
const int screenHeight = 480; // window height is 480
const int screenWidth = 640 ; //window width is 640
// <<<<<<<<<<<<<<<<<<<<<Prototypes>>>>>>>>>>>>>>>>>>
void exit(int) ;
// <<<<<<<<<<<<<<<<<<<<<<<myInit>>>>>>>>>>>>>>>>>>>
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0); // set white background color
glColor3f(0.0f, 0.0f, 0.0f); // set the drawing color
glPointSize(4.0); // a ?dot? is 4 by 4 pixels
glLineWidth(4.0); // a ?dot? is 4 by 4 pixels
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
// <<<<<<<<<<<<<<<<<<<<<<<<myDisplay>>>>>>>>>>>>>>>>>
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT); // clear the screen
glBegin(GL_POINTS);
// glBegin(GL_LINE_STRIP) ;
// glBegin(GL_LINE_LOOP) ;
// glBegin(GL_POLYGON);
glVertex2i(289, 190); // Dubhe
glVertex2i(320, 128) ; // Merak
glVertex2i(239, 67) ; // Phecda
glVertex2i(194, 101) ; // Megrez
glVertex2i(129, 83) ; // Alioth
glVertex2i(75, 73) ; // Mizar
glVertex2i(74, 74) ; // Alcor
glEnd();
glFlush(); // send all output to display
}
// <<<<<<<<<<<<<<<<<<<<<<<<myKeyboard>>>>>>>>>>>>>>
void myKeyboard(unsigned char theKey, int mouseX, int mouseY)
{
switch(theKey)
{
case 'Q':
case 'q':
exit(-1); //terminate the program
default:
break; // do nothing
}
}
// <<<<<<<<<<<<<<<<<<<<<<<<main>>>>>>>>>>>>>>>>>>>>>>
int main(int argc, char** argv)
{
glutInit(&argc, argv); // initialize the toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
glutInitWindowSize(640, 480); // set window size
glutInitWindowPosition(100, 150); // set window position on screen
glutCreateWindow("Big Deep - Type Q or q to quit") ; // open the screen window
glutDisplayFunc(myDisplay); // register redraw function
glutKeyboardFunc(myKeyboard); // register the keyboard action function
myInit();
glutMainLoop(); // go into a perpetual loop
}
任何幫助將不勝感激!
我很鬱悶,教授們仍然在這樣教OpenGL。你可能想和你的教授坐下來,提醒他們[他們不應該教Legacy OpenGL](http://gamedev.stackexchange.com/questions/34108/opengl-vbo-or-glbegin-glend),應該堅持到2008年還沒有被棄用的OpenGL函數。我引用的帖子引用了大量的話:「*有些人認爲先學習老東西比較好,因爲它更容易一點,但是你學到的東西大多是無用的,必須忘掉。*「。 – Xirema
僅供參考,你得到的錯誤是鏈接錯誤的結果,特別是與你的教授使用'exit'有關。不知何故,在構建過程中的某個地方,您沒有引用正確的目標文件來鏈接到最終的可執行文件。如果我對您的特定構建環境有所瞭解,我會發布更詳細的診斷說明作爲答案。 – Xirema
他想教2的理由。x是因爲「它更適合教學,它更容易建立到4.x而不是學習4,然後學習更舊的東西」,這對我也沒有任何意義。我可能是錯的,但我認爲退出功能是GLUT庫的一部分,但我不確定。這就是我所能提供的所有幫助,就像我說過的,我今天才開始嘗試使用它。謝謝您的幫助! – csm60