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

Author Topic: [XCODE] Command Line Tool template doesn't work?  (Read 3905 times)

0 Members and 1 Guest are viewing this topic.

Roggie

  • Newbie
  • *
  • Posts: 8
    • View Profile
[XCODE] Command Line Tool template doesn't work?
« on: April 01, 2013, 11:22:17 am »
Hi,

I've been scrolling through Google and this forum for days now, but SFML just seems to be refusing to work in my Macbook Air, even though it works well on my PC with Visual Studio 2012. According to the template topic in General, the Xcode templates have been updated to what would be Xcode 4.6. However, they just won't work with me. Whenever I try to compile a SFML program (either normal program, or program with console command), I get the following linker error:
ld: library not found for -lsfml-system-d
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It calls itself an Apple Mach-O Linker (Id) Error. Whenever I add the framework in the project wizard, it gives me the well-known SFML/Graphics.hpp not found error.

I've also tried compiling from scratch with CMake, but this gives some errors and I can't seem to find a proper fix. If anybody knows how to get this templates working, or has got some recent instructions (the ones I didn't seem to be able to find) could you please give them? :3

By the way, I'm using SFML 2.0. I do not know whether I'm using static or dynamic, I just compiled the template without even touching the code.

Roggie
« Last Edit: April 02, 2013, 12:13:05 pm by Roggie »

Roggie

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: [XCODE] Those Templates Are Driving Me Crazy!
« Reply #1 on: April 01, 2013, 04:38:48 pm »
I just noticed that when installing sfml on linux, you have to download a package called lsfml. Does this mean the installer didn't install lsfml properly?

Roggie

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: [XCODE] SFML Command Line Tool template doesn't work?
« Reply #2 on: April 02, 2013, 11:53:11 am »
I'm sorry for triple-posting, but I guess this is worth a new post c:

It turned out that the search path for the dylib was missing. This is the first time I'm doing this kind of stuff, so I forgot to look there. :x Anyways, the application doesn't give any linker errors anymore!

Thing is, the error now changed to an error with 64-bit architecture from what I can read. The full error:
Undefined symbols for architecture x86_64:
  "sf::RenderWindow::RenderWindow(sf::VideoMode, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int, sf::ContextSettings const&)", referenced from:
      _main in main.o
  "sf::Font::loadFromFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      _main in main.o
  "sf::Music::openFromFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      _main in main.o
  "sf::String::String(char const*, std::__1::locale const&)", referenced from:
      _main in main.o
  "sf::Texture::loadFromFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, sf::Rect<int> const&)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
 
The code I'm using:
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>

/* Resources :
 * ===========
 *
 * In order to load the resources like cute_image.png, you have to set up
 * your target scheme :
 *
 * - Select "Edit Scheme…" in the "Product" menu;
 * - Check the box "use custom working directory";
 * - Fill the text field with the folder path containing your resources;
 *        (e.g. your project folder)
 * - Click OK.
 */

 

int main (int argc, const char * argv[])
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

    // Load a sprite to display
    sf::Texture texture;
    if (!texture.loadFromFile("cute_image.jpg"))
        return EXIT_FAILURE;
    sf::Sprite sprite(texture);

    // Create a graphical text to display
    sf::Font font;
    if (!font.loadFromFile("sansation.ttf"))
        return EXIT_FAILURE;
    sf::Text text("Hello SFML", font, 50);
    text.setColor(sf::Color::Black);

    // Load a music to play
    sf::Music music;
    if (!music.openFromFile("nice_music.ogg"))
        return EXIT_FAILURE;

    // Play the music
    music.play();
       

    // Start the game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
                // Close window : exit
                if (event.type == sf::Event::Closed)
                        window.close();
           
                // Escape pressed : exit
                if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
                        window.close();
        }

        // Clear screen
        window.clear();
       
        // Draw the sprite
        window.draw(sprite);
       
        // Draw the string
        window.draw(text);

        // Update the window
        window.display();
    }

        return EXIT_SUCCESS;
}
 
(just the template)

Edit:

Whenever I change C++11 to C++98, I get a whole new set of errors that might be worth looking at. It doesn't stop the program, but it does give some nice output:

dyld: lazy symbol binding failed: Symbol not found: __ZN2sf12RenderWindowC1ENS_9VideoModeERKSsjRKNS_15ContextSettingsE
  Referenced from: /Users/matthijs/Library/Developer/Xcode/DerivedData/SFML_Command_Edited_Linkers-czmimcgihsgwemdzuixoxdhtjwmt/Build/Products/Release/SFML Command Edited Linkers
  Expected in: /Library/Frameworks/sfml-graphics.framework/Versions/2.0.0/sfml-graphics

dyld: Symbol not found: __ZN2sf12RenderWindowC1ENS_9VideoModeERKSsjRKNS_15ContextSettingsE
  Referenced from: /Users/matthijs/Library/Developer/Xcode/DerivedData/SFML_Command_Edited_Linkers-czmimcgihsgwemdzuixoxdhtjwmt/Build/Products/Release/SFML Command Edited Linkers
  Expected in: /Library/Frameworks/sfml-graphics.framework/Versions/2.0.0/sfml-graphics

Edit 2:

When I switch to the non-commandline tool SFML template and I change the C++11 compiler to the C++98 compiler it does work? It leaves me with two problems:
objc[8081]: Class SFApplication is implemented in both /Users/matthijs/Library/Developer/Xcode/DerivedData/SFML_Take_3-gxmsbcnyicaawxebvcbqdrugleup/Build/Products/Release/SFML Take 3.app/Contents/Frameworks/sfml-window.framework/Versions/2.0.0/sfml-window and /usr/local/lib/libsfml-window.2.dylib. One of the two will be used. Which one is undefined.
objc[8081]: Class SFOpenGLView is implemented in both /Users/matthijs/Library/Developer/Xcode/DerivedData/SFML_Take_3-gxmsbcnyicaawxebvcbqdrugleup/Build/Products/Release/SFML Take 3.app/Contents/Frameworks/sfml-window.framework/Versions/2.0.0/sfml-window and /usr/local/lib/libsfml-window.2.dylib. One of the two will be used. Which one is undefined.
objc[8081]: Class SFWindow is implemented in both /Users/matthijs/Library/Developer/Xcode/DerivedData/SFML_Take_3-gxmsbcnyicaawxebvcbqdrugleup/Build/Products/Release/SFML Take 3.app/Contents/Frameworks/sfml-window.framework/Versions/2.0.0/sfml-window and /usr/local/lib/libsfml-window.2.dylib. One of the two will be used. Which one is undefined.
objc[8081]: Class SFWindowController is implemented in both /Users/matthijs/Library/Developer/Xcode/DerivedData/SFML_Take_3-gxmsbcnyicaawxebvcbqdrugleup/Build/Products/Release/SFML Take 3.app/Contents/Frameworks/sfml-window.framework/Versions/2.0.0/sfml-window and /usr/local/lib/libsfml-window.2.dylib. One of the two will be used. Which one is undefined.
objc[8081]: Class SFViewController is implemented in both /Users/matthijs/Library/Developer/Xcode/DerivedData/SFML_Take_3-gxmsbcnyicaawxebvcbqdrugleup/Build/Products/Release/SFML Take 3.app/Contents/Frameworks/sfml-window.framework/Versions/2.0.0/sfml-window and /usr/local/lib/libsfml-window.2.dylib. One of the two will be used. Which one is undefined.
 
This is the output I get when I compile it as a default SFML program. It seems like it has something to do with the fact that I've got like two or three copies of the dylibs. Will this cause problems in the future?

And my second problem: does anybody have a solution to the problems I'm facing with he command-line tool template? I really want to use it...
« Last Edit: April 02, 2013, 12:12:45 pm by Roggie »

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: [XCODE] Command Line Tool template doesn't work?
« Reply #3 on: April 02, 2013, 05:35:44 pm »
I don't really know what you did or not but I guess you was really close to success with the «Undefined symbols for architecture x86_64:» errors. You simply needed to set CMAKE_OSX_ARCHITECTURES to "i386;x86_64" and rebuild SFML.

So, what you can do is :

 - 1/ get rid of everything you previously installed.
 - 2/ clone SFML from github
 - 3/ set up CMake according to the CMake tutorial (and setting CMAKE_OSX_ARCHITECTURES to "i386;x86_64"). At this point I encourage you to opt for the framework solution over the dylib one.
 - 4/ if you need C++11 features in your app, configure CMake as explained in the OS X tutorial
 - 5/ compile SFML (make)
 - 6/ install SFML (with the templates, of course)
 - 7/ create your new project.

That should work.
SFML / OS X developer