x86_64-w64-mingw32-g++ 编译失败,g++ 工作正常

x86_64-w64-mingw32-g++ fails to compile, g++ works fine

我正在尝试在 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 class 使用 OBJECT 构造函数的复制构造函数。我有几个 classes 使用相同的格式并且不会引发错误。 ftgl.h 可能有问题,因为 TEXT 是唯一使用它的 class,但这看起来太像语法错误了。

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);
}

any/all 感谢帮助。

在 windows 上,TEXT 是一个宏函数,它告诉编译器在定义 UNICODE 时将传递给它的字符串用作 UTF-16,否则用作 ANSI 字符串。由于预处理器在实际编译之前执行,因此它对您定义的 class 一无所知。它认为您正在调用仅接受一个参数的宏函数。这就是它给你错误的原因。重命名您的 class 以解决问题。