Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Makefile Help Mac OSX  (Read 3122 times)

0 Members and 2 Guests are viewing this topic.

sonikbliss

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Makefile Help Mac OSX
« on: March 11, 2014, 12:20:58 am »
Hi all,

So I've built a little battleship game using SFML 2.1 and the provided Xcode 5 Templates as a CLT. Everything runs fine through Xcode but now I'd like to be able to compile the game with a Makefile but I'm running into problems (the main one being that I'm new to this and don't understand Makefiles very well!).

Here's my Makefile:

# paths on MAC OSX
# SFML_LIB = -I/usr/local/lib
# SFML_INCLUDE = -I/usr/local/include
# SFML_FRAMEWORKS = -I/Library/Frameworks

SFML_LIBS = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
CXX = g++
CXXFLAGS = -g -std=c++11

all: battleship_gui

%.o : %.cpp
        $(CXX) -c $< $(CXXFLAGS)

BATTLESHIP_OBJECTS = BattleshipGUI_Driver.o Button.o GameBoard.o Ship.o Battleship_AI.o
battleship_gui: $(BATTLESHIP_OBJECTS)
        $(CXX) -o $@ $(BATTLESHIP_OBJECTS) $(CXXFLAGS) $(SFML_LIBS)

clean:
        $(RM) *.o battleship_gui
 


I'm sure I'm making every noob error in the book so if someone could help me out I'd greatly appreciate it. I originally tried using the commented out paths in place of $(LIBS) but I seemed to get even more errors than below. I just don't really know how to properly include all of the relevant SFML stuff.

After running make all here's the output I get:

g++ -c BattleshipGUI_Driver.cpp -g -std=c++11
g++ -c Button.cpp -g -std=c++11
g++ -c GameBoard.cpp -g -std=c++11
g++ -c Ship.cpp -g -std=c++11
g++ -c Battleship_AI.cpp -g -std=c++11
g++ -o battleship_gui BattleshipGUI_Driver.o Button.o GameBoard.o Ship.o Battleship_AI.o -g -std=c++11 -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
Undefined symbols for architecture x86_64:
  "sf::Font::loadFromFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      _main in BattleshipGUI_Driver.o
  "sf::String::String(char const*, std::locale const&)", referenced from:
      _main in BattleshipGUI_Driver.o
  "sf::String::String(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::locale const&)", referenced from:
      _main in BattleshipGUI_Driver.o
  "sf::Texture::loadFromFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, sf::Rect<int> const&)", referenced from:
      _main in BattleshipGUI_Driver.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [battleship_gui] Error 1
 

Thanks for your time!

sonikbliss

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Makefile Help Mac OSX
« Reply #1 on: March 12, 2014, 04:11:22 pm »
I should have mentioned I'm running Mac OS X 10.8.5 on a 2 Ghz Intel Core 2 Duo Macbook with SFML 2.1. I installed everything related to SFML in the standard locations using the included install.sh script.

In my Xcode project, which runs fine, I've made sure to include the following headers:

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

I tweaked my Makefile based on an example I found here as follows (I'm not actually using the paths as defined on the first 3 lines, do I need to since everything is in the standard location?):

# paths on MAC OSX
SFML_LIB = -I/usr/local/lib
SFML_INCLUDE = -I/usr/local/include
SFML_FRAMEWORKS = -I/Library/Frameworks

LIBS=-lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio -lsfml-network
CXX = g++
CXXFLAGS = -std=c++11

all: battleship

%.o: %.cpp
                $(CXX) -c $< $(CXXFLAGS) -o $@

%.o: %.hpp
                $(CXX) -c $< -o $@

battleship: BattleshipGUI_Driver.o Button.o GameBoard.o Ship.o Battleship_AI.o
                @echo "** Building the game"
                $(CXX) -o battleship BattleshipGUI_Driver.o Button.o GameBoard.o Ship.o Battleship_AI.o $(LIBS)

clean:
                @echo "** Removing object files and executable..."
                rm -f battleship *.o

install:
                @echo '** Installing...'
                cp battleship /usr/bin/

uninstall:
                @echo '** Uninstalling...'
                $(RM) /usr/bin/battleship
 

I'm still getting the following errors when trying to compile my main program. I'm at a loss, can any kind soul point me in the right direction? Is there any obvious reason why sf::Font::loadFromFile, sf::String::String, and sf::Texture::loadFromFile wouldn't be found? I dumped all of my actual fonts and graphics resources right in the same directory as my .cpp, .hpp, and Makefile. Is there a different way I should deal with resources? Thanks

g++ -c BattleshipGUI_Driver.cpp -std=c++11 -o BattleshipGUI_Driver.o
g++ -c Button.cpp -std=c++11 -o Button.o
g++ -c GameBoard.cpp -std=c++11 -o GameBoard.o
g++ -c Ship.cpp -std=c++11 -o Ship.o
g++ -c Battleship_AI.cpp -std=c++11 -o Battleship_AI.o
** Building the game
g++ -o battleship BattleshipGUI_Driver.o Button.o GameBoard.o Ship.o Battleship_AI.o -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio -lsfml-network
Undefined symbols for architecture x86_64:
  "sf::Font::loadFromFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      _main in BattleshipGUI_Driver.o
  "sf::String::String(char const*, std::locale const&)", referenced from:
      _main in BattleshipGUI_Driver.o
  "sf::String::String(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::locale const&)", referenced from:
      _main in BattleshipGUI_Driver.o
  "sf::Texture::loadFromFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, sf::Rect<int> const&)", referenced from:
      _main in BattleshipGUI_Driver.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [battleship] Error 1
 
« Last Edit: March 12, 2014, 04:15:28 pm by sonikbliss »

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Makefile Help Mac OSX
« Reply #2 on: March 15, 2014, 12:28:16 pm »
You have to play with
CXX = g++
CXXFLAGS = -std=c++11

It depends on which version of SFML you have downloaded: if you downloaded the clang version, then use clang, not gcc. Hence CXX=clang++.

There is a note about your issue in the Xcode tutorial. It can also be applied to Makefiles.
SFML / OS X developer

 

anything