编译代码时,我一直收到此错误:
架构x86_64的未定义符号: " _glewInit",引自: _main在main.o中 " _glfwCreateWindow",引自: _main在main.o中 " _glfwGetKey",引自: _main在main.o中 " _glfwInit",引自: _main在main.o中 " _glfwMakeContextCurrent",引自: _main在main.o中 " _glfwPollEvents",引自: _main在main.o中 " _glfwSetInputMode",引自: _main在main.o中 " _glfwSwapBuffers",引自: _main在main.o中 " _glfwTerminate",引自: _main在main.o中 " _glfwWindowHint",引自: _main在main.o中 " _glfwWindowShouldClose",引自: _main在main.o中 ld:找不到架构x86_64的符号 clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)
我尝试用Xcode和终端编译它。我使用以下命令用终端编译它:
$g++ -I/usr/X11R6/include -I/usr/local/include -I/opt/local/include -L/usr/local/lib/ -L/opt/local/lib -lSOIL -framework GLUT -framework OpenGL -framework CoreFoundation -w -o main tutorial01.cpp
我也尝试过堆栈溢出的所有方法。但是我仍然可以重试其中任何一个(也许尝试它们的顺序可以改变结果)
我的代码已附上。这是一个在opengl中打开窗口的非常简单的代码。
// Include standard headers
#include <stdio.h>
#include <stdlib.h>
// Include GLEW
#include <GL/glew.h>
// Include GLFW
#include <glfw3.h>
GLFWwindow* window;
// Include GLM
#include <glm/glm.hpp>
using namespace glm;
int main( void )
{
// Initialise GLFW
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
getchar();
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Open a window and create its OpenGL context
window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
getchar();
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
// Initialize GLEW
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
getchar();
glfwTerminate();
return -1;
}
// Ensure we can capture the escape key being pressed below
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
// Dark blue background
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
do{
// Clear the screen. It's not mentioned before Tutorial 02, but it can cause flickering, so it's there nonetheless.
glClear( GL_COLOR_BUFFER_BIT );
// Draw nothing, see you in tutorial 2 !
// Swap buffers
glfwSwapBuffers(window);
glfwPollEvents();
} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0 );
// Close OpenGL window and terminate GLFW
glfwTerminate();
return 0;
}