我试图在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是唯一使用它的类,但这看起来太像语法错误了。
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);
}
感谢任何/所有帮助。
答案 0 :(得分:1)
在Windows上,TEXT是一个宏函数,它告诉编译器在定义UNICODE时使用传递给它的字符串为UTF-16,否则为ANSI字符串。由于预处理器在实际编译之前执行,因此它不知道您定义的类。它认为你正在调用宏函数,它只接受一个参数。这就是它给你错误的原因。重命名您的课程以解决问题。