我尝试在 MacOS 10.6.8 上编译一个已经在 Linux/Debian 7.0 上运行的应用程序。此代码使用带有 GPU/OPenCL 和 OpenGL 库的 Qt 框架。
但是我在使用这个文件头(GLWidget.hpp)进行编译时遇到了问题(我把原来的 Linux 版本放在这里):
#ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QGLWidget>
#include <GL/glu.h>
#include <QTimer>
#include "NBody.hpp"
#include "Timer.h"
class GLWidget : public QGLWidget
{
Q_OBJECT
public:
GLWidget(QWidget *parent = NULL);
~GLWidget();
...
有了这个版本,我在 MacOS 上编译:
/usr/bin/g++-4.2 -c -pipe -O2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.6 -Wall -W -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/opt/local/include -I/Developer/GPU\ Computing/OpenCL/common/inc -I/opt/local/share/qt4/mkspecs/macx-g++ -I. -I. -I/opt/local/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtOpenGL.framework/Versions/4/Headers -I. -I/opt/local/Library/Frameworks/QtOpenGL.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -I. -F/opt/local/Library/Frameworks -I//Developer/GPU\ Computing/shared/inc -I/System/Library/Frameworks/OpenCL.framework/Headers -o GLWidget.o GLWidget.cpp
GLWidget.cpp: In member function ‘virtual void GLWidget::initializeGL()’:
GLWidget.cpp:82: error: ‘GL_CLAMP_VERTEX_COLOR’ was not declared in this scope
GLWidget.cpp:82: error: ‘glClampColor’ was not declared in this scope
GLWidget.cpp: In function ‘bool loadPngImage(char*, int&, int&, bool&, GLubyte**)’:
GLWidget.cpp:297: error: ‘png_infopp_NULL’ was not declared in this scope
GLWidget.cpp:313: error: ‘png_infopp_NULL’ was not declared in this scope
GLWidget.cpp:347: error: ‘png_voidp_NULL’ was not declared in this scope
GLWidget.cpp:349: error: invalid use of incomplete type ‘struct png_info_def’
/opt/local/include/png.h:739: error: forward declaration of ‘struct png_info_def’
GLWidget.cpp:350: error: invalid use of incomplete type ‘struct png_info_def’
/opt/local/include/png.h:739: error: forward declaration of ‘struct png_info_def’
GLWidget.cpp:351: error: invalid use of incomplete type ‘struct png_info_def’
/opt/local/include/png.h:739: error: forward declaration of ‘struct png_info_def’
GLWidget.cpp:359: error: invalid use of incomplete type ‘struct png_info_def’
/opt/local/include/png.h:739: error: forward declaration of ‘struct png_info_def’
GLWidget.cpp:378: error: ‘png_infopp_NULL’ was not declared in this scope
GLWidget.cpp: In member function ‘void GLWidget::draw()’:
GLWidget.cpp:483: error: ‘GL_VERTEX_PROGRAM_POINT_SIZE_NV’ was not declared in this scope
make: *** [GLWidget.o] Error 1
实际上,glClampColor
函数没有在范围内声明。所以我搜索了这个函数的声明位置,我在这个文件中找到了它:
/Developer/GPU Computing/C/common/inc/GL/glew.h
然后,我将其添加到 PATH 中并将其包含在 GLWidget.hpp 中:
#ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QGLWidget>
#include <GL/glew.h>
#include <QTimer>
#include "NBody.hpp"
#include "Timer.h"
class GLWidget : public QGLWidget
{
Q_OBJECT
public:
GLWidget(QWidget *parent = NULL);
~GLWidget();
但是现在,我收到以下错误:
/opt/local/bin/uic DiskGal_IC.ui -o ui_DiskGal_IC.h
/opt/local/bin/uic YourGalaxy.ui -o ui_YourGalaxy.h
/usr/bin/g++-4.2 -c -pipe -O2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.6 -Wall -W -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/opt/local/include -I/Developer/GPU\ Computing/OpenCL/common/inc -I/opt/local/share/qt4/mkspecs/macx-g++ -I. -I. -I/opt/local/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtOpenGL.framework/Versions/4/Headers -I. -I/opt/local/Library/Frameworks/QtOpenGL.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -I. -F/opt/local/Library/Frameworks -I//Developer/GPU\ Computing/shared/inc -I/System/Library/Frameworks/OpenCL.framework/Headers -o DiskGal_IC.o DiskGal_IC.cpp
In file included from GLWidget.hpp:5,
from YourGalaxy.h:30,
from DiskGal_IC.h:25,
from DiskGal_IC.cpp:1:
//Developer/GPU Computing/shared/inc/GL/glew.h:66:2: error: #error gl.h included before glew.h
//Developer/GPU Computing/shared/inc/GL/glew.h:69:2: error: #error glext.h included before glew.h
In file included from GLWidget.hpp:5,
from YourGalaxy.h:30,
from DiskGal_IC.h:25,
from DiskGal_IC.cpp:1:
//Developer/GPU Computing/shared/inc/GL/glew.h:5855: error: ‘GLint64EXT’ has not been declared
//Developer/GPU Computing/shared/inc/GL/glew.h:5856: error: ‘GLuint64EXT’ has not been declared
//Developer/GPU Computing/shared/inc/GL/glew.h:9020: error: ‘PFNGLCOPYTEXSUBIMAGE3DPROC’ does not name a type
//Developer/GPU Computing/shared/inc/GL/glew.h:9021: error: ‘PFNGLDRAWRANGEELEMENTSPROC’ does not name a type
//Developer/GPU Computing/shared/inc/GL/glew.h:9022: error: ‘PFNGLTEXIMAGE3DPROC’ does not name a type
//Developer/GPU Computing/shared/inc/GL/glew.h:9023: error: ‘PFNGLTEXSUBIMAGE3DPROC’ does not name a type
//Developer/GPU Computing/shared/inc/GL/glew.h:9025: error: ‘PFNGLACTIVETEXTUREPROC’ does not name a type
//Developer/GPU Computing/shared/inc/GL/glew.h:9026: error: ‘PFNGLCLIENTACTIVETEXTUREPROC’ does not name a type
...
我不知道该怎么做,我的 Makefile 是由 qmake 生成的,在我的 .pro 中QT += opengl
。之后,我对其进行了修改以包含其他头文件/库,例如 OpenCL。这是此 Makefile 的顶部:
CC = /usr/bin/gcc-4.2
CXX = /usr/bin/g++-4.2
DEFINES = -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS = -pipe -O2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.6 -Wall -W $(DEFINES)
CXXFLAGS = -pipe -O2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.6 -Wall -W $(DEFINES)
GPU = /Developer/GPU\ Computing
INC_GSL = /opt/local/include
INCPATH = -I$(INC_GSL) -I$(GPU)/OpenCL/common/inc -I/opt/local/share/qt4/mkspecs/macx-g++ -I. -I. -I/opt/local/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtOpenGL.framework/Versions/4/Headers -I. -I/opt/local/Library/Frameworks/QtOpenGL.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -I. -F/opt/local/Library/Frameworks -I/$(GPU)/shared/inc -I/System/Library/Frameworks/OpenCL.framework/Headers
LINK = /usr/bin/g++-4.2
LFLAGS = -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.6
LIBS = $(SUBLIBS) -F/opt/local/Library/Frameworks -F/opt/local/lib -F/System/Library/Frameworks -F/opt/local/Library/Frameworks -F/opt/local/lib -L/opt/local/lib -framework QtOpenGL -framework QtGui -framework QtCore -framework OpenGL -framework AGL -framework OpenCL -lgsl -lgslcblas -lfftw3 -L$(GPU)/shared/lib/darwin -lGLEW