Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在Mac终端上编译OpenGL程序_C++_Macos_Opengl_Compiler Errors - Fatal编程技术网

C++ 在Mac终端上编译OpenGL程序

C++ 在Mac终端上编译OpenGL程序,c++,macos,opengl,compiler-errors,C++,Macos,Opengl,Compiler Errors,我使用的是Mac Os X 10.9.5,完全更新为XCode版本6.0.1。我还安装了在安装XCode之后必须安装的命令行实用程序。我在openGL库中使用GLFW和GLEW。GLEW是手动安装的,而GLFW是与Macports一起安装的 我想在没有XCode的情况下进行编码,就像我在Windows(使用MingW)和Linux上所做的那样。我在谷歌上搜索了如何编译该程序,还搜索了stackoverflow 因此,当前我的compile命令如下所示 (这是一个C++程序) 我不断发现以下错误:

我使用的是Mac Os X 10.9.5,完全更新为XCode版本6.0.1。我还安装了在安装XCode之后必须安装的命令行实用程序。我在openGL库中使用GLFW和GLEW。GLEW是手动安装的,而GLFW是与Macports一起安装的

我想在没有XCode的情况下进行编码,就像我在Windows(使用MingW)和Linux上所做的那样。我在谷歌上搜索了如何编译该程序,还搜索了stackoverflow

因此,当前我的compile命令如下所示 (这是一个C++程序)

我不断发现以下错误:

Undefined symbols for architecture x86_64:
"_glfwCreateWindow", referenced from:
  _main in main-ba7a57.o
"_glfwInit", referenced from:
  _main in main-ba7a57.o
"_glfwMakeContextCurrent", referenced from:
  _main in main-ba7a57.o
"_glfwTerminate", referenced from:
  _main in main-ba7a57.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
该计划是:

#define GLEW_STATIC
#include <glew.h>
#include <glfw3.h>
#include <iostream>

using namespace std;

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

GLFWwindow* window;
if(!glfwInit()) exit(EXIT_FAILURE);
window = glfwCreateWindow(1024, 768, "glfw", NULL, NULL);
if(!window) {
    glfwTerminate();
    exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);

const GLubyte* version = glGetString(GL_VERSION);
cout << "OpenGL version: " << version << endl;
glfwTerminate();
return 0;
}
#定义GLEW#U静态
#包括
#包括
#包括
使用名称空间std;
int main(int argc,char*argv[]){
GLFWwindow*窗口;
如果(!glfwInit())退出(退出失败);
window=glfwCreateWindow(1024768,“glfw”,NULL,NULL);
如果(!窗口){
glfwTerminate();
退出(退出失败);
}
glfwMakeContextCurrent(窗口);
常量GLubyte*version=glGetString(GL_版本);

这只是一个猜测,但请尝试在命令行末尾添加“-lglfw”。这会告诉g++根据libglfw进行编译。

错误显示
未定义架构x86\u 64的符号这一事实让我认为,您安装的库版本可能是针对64位架构而构建的。记得选择时要安装的g库,您应该根据要针对的体系结构选择32位或64位版本,而不是开发机器使用的体系结构


请参阅以供参考。

您没有链接到glfw lib,只有新的链接目录,但没有lib。使用-L/usr/local/lib可以告诉您glfw lib的可能重复。所有lib都由-L指定。好的,但是,可以告诉g++在编译时使用特定的体系结构。如何做到这一点?如果您说-arch i386或-arch x86\u 64,我使用了它,但仍然出现相同的错误。@rathorsunpret我的意思是问题可能与您安装的库有关,而不是您自己的代码。请重新安装GLFW和GLEW库,确保您安装了32位版本。
#define GLEW_STATIC
#include <glew.h>
#include <glfw3.h>
#include <iostream>

using namespace std;

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

GLFWwindow* window;
if(!glfwInit()) exit(EXIT_FAILURE);
window = glfwCreateWindow(1024, 768, "glfw", NULL, NULL);
if(!window) {
    glfwTerminate();
    exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);

const GLubyte* version = glGetString(GL_VERSION);
cout << "OpenGL version: " << version << endl;
glfwTerminate();
return 0;
}