【发布时间】:2016-03-11 00:48:49
【问题描述】:
我正在尝试在 linux 上交叉编译适用于 windows 的程序,但 mingw32 编译器出现 g++ 不存在的错误。
命令:
g++ *.cpp -o game -lGL -lGLU -lglfw -lftgl -lopenal -lalut -I/usr/include/freetype2
完美地编译程序。然而,mingw32 等效项(据我所知)输出以下错误:
/usr/bin/x86_64-w64-mingw32-g++ *.cpp -o game.exe -I /usr/x86_64-w64-mingw32/include -L /usr/x86_64-w64-mingw32/lib -lGL -lglu -lglut -lglfw -lfreetype -lftgl -lopenal -lalut -I/usr/x86_64-w64-mingw32/include/freetype2
In file included from gesplit.cpp:22:0:
text.h:14:45: error: macro "TEXT" passed 6 arguments, but takes just 1
TEXT(string,int=12,int=0,int=0,int=0,int=0);
^
text.h:15:52: error: macro "TEXT" passed 7 arguments, but takes just 1
TEXT(WORLD&,string,int=12,int=0,int=0,int=0,int=0);
^
gesplit.cpp:85:102: error: macro "TEXT" passed 6 arguments, but takes just 1
back(new TEXT("PRESS ENTER TO START",24,(screen.w/2)-250,(screen.h-24)/4,0,0));
^
gesplit.cpp:86:98: error: macro "TEXT" passed 6 arguments, but takes just 1
ush_back(new TEXT("WASD - ARROW KEYS: MOVE",12,40,(screen.h-24)/2+20,0,0));
^
gesplit.cpp:87:96: error: macro "TEXT" passed 6 arguments, but takes just 1
.push_back(new TEXT("P: PAUSE",12,40,(screen.h-24)/2,0,0));
^
gesplit.cpp:88:99: error: macro "TEXT" passed 6 arguments, but takes just 1
sh_back(new TEXT("SPACE: SHOOT",12,40,(screen.h-24)/2-20,0,0));
^
gesplit.cpp:89:118: error: macro "TEXT" passed 6 arguments, but takes just 1
SC: QUIT GAME LIKE A QUITTER",12,40,(screen.h-24)/2-40,0,0));
^
gesplit.cpp:90:98: error: macro "TEXT" passed 6 arguments, but takes just 1
ush_back(new TEXT("SPACE SHOOT",40,(screen.w/2)-220,(screen.h-24)*3/4+20,0,0));
^
gesplit.cpp:91:94: error: macro "TEXT" passed 6 arguments, but takes just 1
xt.push_back(new TEXT("ZAP-ZAP",40,(screen.w/2)-140,(screen.h-24)*3/4-20,0,0));
^
gesplit.cpp:96:100: error: macro "TEXT" passed 7 arguments, but takes just 1
(new TEXT(new_world,("SCORE "+intToString(globalScore)),24,0,screen.h-24,0,0));
^
In file included from gesplit.cpp:22:0:
text.h:14:3: error: declaration does not declare anything [-fpermissive]
TEXT(string,int=12,int=0,int=0,int=0,int=0);
^
text.h:15:3: error: declaration does not declare anything [-fpermissive]
TEXT(WORLD&,string,int=12,int=0,int=0,int=0,int=0);
^
gesplit.cpp: In function ‘int main(int, char**)’:
gesplit.cpp:62:64: error: no matching function for call to ‘TEXT::TEXT(const char [6], int, int, int, int, int)’
TEXT pauseText("PAUSE",24,(screen.w/2)-62,(screen.h-24)/2,0,0);
^
In file included from gesplit.cpp:22:0:
text.h:8:7: note: candidate: TEXT::TEXT()
class TEXT:public OBJECT
^
text.h:8:7: note: candidate expects 0 arguments, 6 provided
text.h:8:7: note: candidate: TEXT::TEXT(const TEXT&)
text.h:8:7: note: candidate expects 1 argument, 6 provided
在我看来,mingw32 不喜欢 TEXT 类使用 OBJECT 构造函数的复制构造函数。我有几个类使用相同的格式并且不会引发错误。这可能是 ftgl.h 的问题,因为 TEXT 是唯一使用它的类,但这看起来太像语法错误了。
文本.cpp:
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <GL/gl.h>
//#include <freetype2/freetype/config/ftheader.h>
//#include <freetype2/ft2build.h>
#include <FTGL/ftgl.h>
#include <FTGL/FTGLPixmapFont.h>
#include "person.h"
#include "object.h"
#include "world.h"
#include "text.h"
#include "coord.h"
#include "globals.h"
using namespace std;
TEXT::TEXT(WORLD& world_a,string text_a,int size_a,int x_a,int y_a,int xvel_a,int yvel_a)
:OBJECT(world_a,x_a,y_a,xvel_a,yvel_a)
{
type="TEXT";
layer=6;
cout<<"begin text constructor"<<endl;
text=text_a;
cout<<"set text"<<endl;
font = new FTPixmapFont("emulogic.ttf");
cout<<"set font"<<endl;
font->FaceSize(size_a);
cout<<"end text constructor"<<endl;
}
TEXT::TEXT(string text_a,int size_a,int x_a,int y_a,int xvel_a,int yvel_a)
:OBJECT(x_a,y_a,xvel_a,yvel_a)
{
type="TEXT";
layer=6;
cout<<"begin text constructor"<<endl;
text=text_a;
cout<<"set text"<<endl;
font = new FTPixmapFont("emulogic.ttf");
cout<<"set font"<<endl;
font->FaceSize(size_a);
cout<<"end text constructor"<<endl;
}
void TEXT::render()
{
glPushMatrix();
glTranslatef(x,y,0);
glPushAttrib(GL_ALL_ATTRIB_BITS);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
/*glBegin(GL_QUADS);
glColor4f(0.0f,0.0f,0.0f,0.3f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(screen.w,0.0f,0.0f);
glVertex3f(screen.w,32.0f,0.0f);
glVertex3f(0.0f,32.0f,0.0f);
glEnd();
*/
glColor4d(1.0,1.0,1.0,1.0);
font->Render(text.c_str(),-1,FTPoint(x,y,0)); //text doesn't transform, so use FTPoint
glPopAttrib();
glPopMatrix();
}
bool TEXT::logic(int step)
{
switch(step)
{
case 0:
break;
default:
return true;
break;
}
return false;
}
void TEXT::setText(string text_a)
{
text=text_a;
}
void TEXT::setFontSize(int size)
{
font->FaceSize(size);
}
感谢任何/所有帮助。
【问题讨论】:
-
"宏 "TEXT"",提示,提示。看起来您包含的某些标头将其定义为宏(IIRC Windows 标头执行此操作)。重命名你的类 - ALLCAPS 无论如何都应该限于宏。