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

Author Topic: Compiling SFML from terminal with g++ on Mac OS X  (Read 3930 times)

0 Members and 1 Guest are viewing this topic.

RainyCats

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Compiling SFML from terminal with g++ on Mac OS X
« on: February 24, 2015, 06:36:19 pm »
Heya,
I want to compile  a simple Main class using  SFML from terminal but I'm getting the no undefined symbols error.
I have put the frame works in the correct places and the include statement isn't giving me any error.

Undefined symbols for architecture x86_64:
  "sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)", referenced from:
      _main in Main-66feaa.o
  "sf::RenderWindow::~RenderWindow()", referenced from:
      _main in Main-66feaa.o
  "sf::String::String(char const*, std::__1::locale const&)", referenced from:
      _main in Main-66feaa.o
  "sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)", referenced from:
      _main in Main-66feaa.o
 


The main class is:

#include <iostream>
#include <vector>
#include "Mechanics.hpp"
#include <SFML/Graphics.hpp>

int main() {
        std::cout << "Hello Elliot" << std::endl;
        Mechanics *mech = new Mechanics();
        int f = 5;
        int m = 10;
       
        double force = (*mech).force(f, m);    
        std:: cout << force << std::endl;
       
        double vel = (*mech).velocityTime(5, 9.81, 30);
        std::cout << vel << std::endl;
       
        sf::RenderWindow window(sf::VideoMode(800, 600), "Pls Wrk");

        return 0;
}

g++ version:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix

It would be a massive help  if anyone could tell how to compile this from terminal,
I'm pretty new to c++.
Thanks,
Rainy

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Compiling SFML from terminal with g++ on Mac OS X
« Reply #1 on: February 24, 2015, 09:51:11 pm »
Quote
Undefined symbols
Ok, that's a linker error. So you code is syntactically fine and compiles - it just does not link.

It seems you are missing the symbol "sf::RenderWindow::RenderWindow" amongst others. That symbol is in the 'Graphics' module, so I think you forgot to link 'sfml-graphics' to your project/executable/whatever...  You need to link the object files or libraries containing symbols you use..

RainyCats

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Compiling SFML from terminal with g++ on Mac OS X
« Reply #2 on: February 25, 2015, 02:41:30 pm »
Thank you yes that was it.

Just for everyone else, if you have put the libraries in the right places then all you need to do is use -c flag when compiling as follows:
    g++ -c <yourfile>
 

Otherwise
g++ <yourfile> -L <path to library folder> -l<libraryname>

For all your libraries. Note is your library is called: libsfml-window.dylib then the command is: -lsfml-window
ignoring the "lib" at the front and the ".dylib" at the end. You must  do this for every every library you use.
Also I THINK the command for for include folder is -I but i haven't had to use it.
Just remember when using -I it should come before <yourfile>
Note: This is for Mac OS X with the g++ compiler.

Thank you everyone,
Rainy