简体   繁体   English

Mac + Netbeans C ++ OpenGL问题

[英]Mac + Netbeans C++ OpenGL problem

I am trying to develop OpenGL programs with C++ on Mac using Netbeans, and there are some compilation errors: 我正在尝试使用Netbeans在Mac上使用C ++开发OpenGL程序,并且存在一些编译错误:

"/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf "/usr/bin/make" -f nbproject/Makefile-Release.mk dist/Release/GNU-MacOSX/sdl_test mkdir -p build/Release/GNU-MacOSX rm -f build/Release/GNU-MacOSX/main.od g++ -c -O2 -MMD -MP -MF build/Release/GNU-MacOSX/main.od -o build/Release/GNU-MacOSX/main.o main.cpp main.cpp:9:41: warning: OpenGL.framework/Headers/gl.h: No such file or directory “ / usr / bin / make” -f nbproject / Makefile-Release.mk QMAKE = SUBPROJECTS = .build-conf“ / usr / bin / make” -f nbproject / Makefile-Release.mk dist / Release / GNU-MacOSX / sdl_test mkdir -p build / Release / GNU-MacOSX rm -f build / Release / GNU-MacOSX / main.od g ++ -c -O2 -MMD -MP -MF build / Release / GNU-MacOSX / main.od -o build /Release/GNU-MacOSX/main.o main.cpp main.cpp:9:41:警告:OpenGL.framework / Headers / gl.h:没有此类文件或目录

my code is as simple as this: 我的代码很简单:

#include <iostream>
#include <OpenGL.framework/Headers/gl.h>

/*
 * 
 */
int main(int argc, char** argv) {
    std::cout << glGetString(GL_VERSION) << std::endl;

    return 0;
}

the compiler cannot find OpenGL header file even if I have added the including path and lib file in the project settings. 即使我在项目设置中添加了include路径和lib文件,编译器也找不到OpenGL头文件。 This is really confusing.. 这真是令人困惑。

In your project properties go to C++ Compiler . 在项目属性中,转到C++ Compiler Under Include Directories add /System/Library/Frameworks . 在“ Include Directories添加/System/Library/Frameworks Under Linker at the bottom under Additional Options add -framework OpenGL . 在“ Additional Options ”底部的“ Linker ”下,添加-framework OpenGL

Change your include directive to #include <OpenGL/gl.h> 将您的include指令更改为#include <OpenGL/gl.h>

Now you should be able to compile your program. 现在您应该可以编译您的程序了。 But I seem to be missing something, because I get a segmentation fault, when I call glGetString ... 但是我似乎丢失了一些东西,因为当我调用glGetString时遇到了段错误。

#include <iostream>
#include <OpenGL/gl.h>

int main(int argc, char** argv) {
    const GLubyte* version = glGetString(GL_VERSION); // segmentation fault

    return 0;
}

Your compiler can't Find the referenced header file in it's search path. 您的编译器在其搜索路径中找不到引用的头文件。 Try to find the file manually on your hard disk, then ensure your compiler has that location in it's search path. 尝试在硬盘上手动查找文件,然后确保编译器在搜索路径中具有该位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM