使用makefile在OS X上编译SDL [英] Compiling SDL on OS X with makefile

查看:94
本文介绍了使用makefile在OS X上编译SDL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在OS X上编译使用C ++和SDL编写的tetris程序.首先,我尝试这样做:

I'm trying to compile the tetris program I wrote with C++ and SDL on OS X. First I tried doing this:

`g++ -o tetris main.cpp `sdl-config --cflags --libs` -framework Cocoa`

得到了:

Undefined symbols:
  "Game::startGame()", referenced from:
      _main in ccQMhbGx.o
  "Game::Game()", referenced from:
      _main in ccQMhbGx.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

这是main.cpp文件:

Here is the main.cpp file:

#include <iostream>
#include "Game.h"

int main(int argc, char* argv[]) {
 Game *game = new Game();
 game->startGame();

 return 0;
}

Game.h是游戏类,其中包括所有其他类(Board.h,IO.h,Piece.h,Pieces.h),并且包含了游戏的主要逻辑.

Game.h is the game class where all of the other classes (Board.h, IO.h, Piece.h, Pieces.h) are included and the main logic of the game is contained.

我真的很想能够为此编写一个makefile或找到某种方式将其轻松分发给朋友.

I'd really like to be able to write a makefile for this or find some way to easily distribute it to friends.

这是最终的makefile,以防其他人遇到相同的问题:

here is the final makefile in case anyone else is having the same problem:

CC=g++
CFLAGS=-c -Wall
SDLFLAGS=`sdl-config --cflags --libs` -framework Cocoa
SOURCES=main.cpp Game.cpp IO.cpp Board.cpp Pieces.cpp Piece.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=tetris

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
 $(CC) $(OBJECTS) $(SDLFLAGS) -o $@

.cpp.o:
 $(CC) $(CFLAGS) $< -o $@

clean:
 rm -rf *.o $(EXECUTABLE)

推荐答案

我认为您的编译问题与SDL主要功能有关.

编译失败是因为您缺少对"Game.o"的引用或由于编译Game.cpp而导致的任何目标文件被调用.试试:

The compile failure is because you're missing references to "Game.o" or whatever the object file resulted out of compiling Game.cpp is called. Try:

g++ -o tetris main.cpp Game.o Pieces.o Whateverelse.o `sdl-config --cflags --libs` -framework Cocoa

这篇关于使用makefile在OS X上编译SDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆