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

Author Topic: How to link to SFML 2.0 statically  (Read 7833 times)

0 Members and 1 Guest are viewing this topic.

mercurio7891

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
How to link to SFML 2.0 statically
« on: October 26, 2011, 07:20:08 am »
Hi I tried linking the code to the sfml static libs but I am still getting a lot of undefined symbols. Am I forgetting to include any libraries or something?

Code: [Select]

g++ -DSFML_STATIC -c -fmessage-length=0 -DDEBUG -O0 -g3 -gdwarf-2 -I/SDKs/Sfml.sdk/sfml-01254d4/include/ -Wall -Wno-missing-braces main.cpp -o debug/main.o

g++ -DSFML_STATIC -c -fmessage-length=0 -DDEBUG -O0 -g3 -gdwarf-2 -I/SDKs/Sfml.sdk/sfml-01254d4/include/ -Wall -Wno-missing-braces -MM -MP -MT debug/main.o main.cpp -o debug/main.d

g++ -framework OpenGL -framework Cocoa -gdwarf-2  -L/SDKs/Sfml.sdk/sfml-01254d4/lib/ -o debug/sfml-test-d debug/main.o -lsfml-graphics-s -lsfml-window-s -lsfml-system-s

Undefined symbols for architecture x86_64:
  "_LMGetKbdType", referenced from:
      sf::priv::HIDInputManager::LoadKey(__IOHIDElement*)     in libsfml-window-s.a(HIDInputManager.mm.o)
  "_IOHIDElementGetUsagePage", referenced from:
      sf::priv::HIDInputManager::LoadMouse(__IOHIDDevice*)     in libsfml-window-s.a(HIDInputManager.mm.o)
      sf::priv::HIDInputManager::LoadKeyboard(__IOHIDDevice*)      in libsfml-window-s.a(HIDInputManager.mm.o)
  "_TISCopyCurrentKeyboardLayoutInputSource", referenced from:
      sf::priv::HIDInputManager::HIDInputManager()in libsfml-window-s.a(HIDInputManager.mm.o)
  "_kTISPropertyUnicodeKeyLayoutData", referenced from:
      sf::priv::HIDInputManager::HIDInputManager()in libsfml-window-s.a(HIDInputManager.mm.o)
  "_TISGetInputSourceProperty", referenced from:
      sf::priv::HIDInputManager::HIDInputManager()in libsfml-window-s.a(HIDInputManager.mm.o)
  "_IOHIDDeviceGetProperty", referenced from:
      sf::priv::HIDInputManager::GetLocationID(__IOHIDDevice*)      in libsfml-window-s.a(HIDInputManager.mm.o)
  "_IOHIDManagerCreate", referenced from:
      sf::priv::HIDJoystickManager::GetInstance()     in libsfml-window-s.a(HIDJoystickManager.cpp.o)
      sf::priv::HIDJoystickManager::HIDJoystickManager()in libsfml-window-s.a(HIDJoystickManager.cpp.o)
      sf::priv::HIDJoystickManager::HIDJoystickManager()in libsfml-window-s.a(HIDJoystickManager.cpp.o)
      sf::priv::HIDInputManager::HIDInputManager()in libsfml-window-s.a(HIDInputManager.mm.o)

.... and more of it

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
How to link to SFML 2.0 statically
« Reply #1 on: October 26, 2011, 08:04:06 am »
Yes. When linking statically, you must also link to all the dependencies of SFML. But static link doesn't make sense on OS X, it's only useful for Windows users. You should forget about it.
Laurent Gomila - SFML developer

mercurio7891

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
How to link to SFML 2.0 statically
« Reply #2 on: October 26, 2011, 08:34:23 am »
But if I don't static link in OS X, wouldn't I have to install or distribute the sfml libraries along with it?

I am build another library that uses SFML as the backend, and if I link to sfml dynamically, wouldn't I need to release the SFML library along with my library?

regards

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
How to link to SFML 2.0 statically
« Reply #3 on: October 26, 2011, 08:43:09 am »
As far as I remember, this is exactly what frameworks and bundles are for. They contain all the necessary dependencies so that you don't have to distribute anything else with them.
Laurent Gomila - SFML developer

mercurio7891

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
How to link to SFML 2.0 statically
« Reply #4 on: October 26, 2011, 09:20:11 am »
As I am not distributing my library as a framework or bundle, but just as a dylib file (a bundle/framework is too much for me now), hence if I am to link statically, what other dependencies do i need to include?

regards

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
How to link to SFML 2.0 statically
« Reply #5 on: October 26, 2011, 09:53:03 am »
I don't know, you need to either look directly in the CMake files or wait for Hiura, the OS X developer.
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
How to link to SFML 2.0 statically
« Reply #6 on: October 26, 2011, 07:42:15 pm »
No need to dig into CMake files if you're using Xcode. The provided templates do exactly that for you if you choose to create an application bundle (.app).

Look at this thread : http://www.sfml-dev.org/forum/viewtopic.php?p=23608#23608 . All information about current SFML 2 development for Mac are describe there.

Of course, if something is not clear enough, go ahead and ask.
SFML / OS X developer

mercurio7891

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
How to link to SFML 2.0 statically
« Reply #7 on: October 27, 2011, 06:16:36 pm »
Hi Hiura, Thanks for the replies.

However, if I am not using xcode, how do I link it?

After running CMake, I only have the libsfml-XXXX.a files installed in the directory which i specified.

Is there a sfml framework or something which i have to include?

I am compiling via the command line using gcc 4.6.1

regards

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
How to link to SFML 2.0 statically
« Reply #8 on: October 28, 2011, 12:57:01 am »
So there is two issues here : 1) finding an alternative to Xcode 2) compiling SFML as a shared library.

For the second one, setting "BUILD_SHARED_LIBS" to TRUE in CMake when compiling SFML should be enough to create .dylib libraries. Are you using cmake GUI or cmake in Terminal ?

Now, for the first issue. There are two good way to provide the end users with libraries : installing the frameworks into */Library/Frameworks/ [1], or to create a bundle application (.app) and add the library as dylibs or as frameworks into myApp.app/Contents/Frameworks/.

To achieve that, you can use some autotool like CMake for compiling your own project. You can also use some basic scripting tool like Makefile to create the application bundle "by hand". I'm pretty sure there's already plenty of script for your favorite autotool on the web.

Using static libraries is a bad solution. I won't go into the details here; there are already so many discussions on the Web explaining why this is bad on Unix like OSes.

Of course, I would be happy to help you more if you need more help. ;-)

[1] : this is only true for API-stable & released libs. Remeber that SFML API will change so it's also not a good idea here.
SFML / OS X developer

mercurio7891

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
How to link to SFML 2.0 statically
« Reply #9 on: October 28, 2011, 03:51:44 am »
Hi Hirua,

the problem I have is that my end product is not an app so I can't bundle as a an application bundle (.app). My end product is another set of library (dylib) that is distributed to the customer to used. The customers are the ones that create the bundle (.app).

For example my final product is XYZ.dylib, where customer then dynamically link to it to use it in their own software.

However XYZ.dylib uses SFML for its backend drawing. If I am to link to SFML shared lib, when distributing the XYZ.dylib, I have to distribute the SFML.dylib together, which I have to tell the customer to install the SFML.dylib in a particular place where the system can find it.

Just an additional note on the XYZ.dylib that we are creating. XYZ.dylib(dll) is cross platform. A goal was to create it with a C API so our customer can place the lib in any location they want and use dlopen/dlsym(on unixes) or LoadLibrary(on windows) to load the contents. However it would defeat the purpose if we have to specifically tell the customers where to place the SFML.dylib so it would run.

We are doing in such a manner to achieve dylib loading via a relative path. Hence if we copy the project folder from one computer to another computer it will still work or compile without the need to place the dylib in the /Library/Frameworks/ folder

This was the reason why we wanted to add SFML as a static lib. I am not sure if there is other way to solve it by including it as a shared lib.

regards

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
How to link to SFML 2.0 statically
« Reply #10 on: October 28, 2011, 06:33:46 pm »
Then I guess the only good option left is creating XYZ as a framework bundle. According to this two pages [1] [2] dlopen doesn't make any difference (except the path) between framework (bundle) and dylib. So you should be able to install SFML frameworks into XYZ.framework/Contents/Frameworks/.


[1] http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/10.5/man3/dlopen.3.html
[2] http://en.wikipedia.org/wiki/Dynamic_loading#Mac_OS_X
SFML / OS X developer

mercurio7891

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
How to link to SFML 2.0 statically
« Reply #11 on: October 29, 2011, 09:35:18 am »
Thanks for the help.

Now I rebuild SFML with the BUILD_FRAMEWORK options checked. However during the linking stage, it seems to be not able to find certain symbols eg. sf::VideoMode etc

Code: [Select]

make -f ./build.makefile config=config.makefile

g++ -c -fmessage-length=0 -DDEBUG -O0 -g3 -gdwarf-2  -Wall -Wno-missing-braces main.cpp -o debug/main.o

g++ -c -fmessage-length=0 -DDEBUG -O0 -g3 -gdwarf-2  -Wall -Wno-missing-braces -MM -MP -MT debug/main.o main.cpp -o debug/main.d

g++ -framework SFML -framework OpenGL -framework Cocoa -gdwarf-2   -o debug/sfml-test-d debug/main.o

Undefined symbols for architecture x86_64:
  "sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)", referenced from:
      _main in main.o
  "sf::Window::Window(sf::VideoMode, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, sf::ContextSettings const&)", referenced from:
      _main in main.o
  "sf::Window::PollEvent(sf::Event&)", referenced from:
      _main in main.o
  "sf::Window::Display()", referenced from:
      _main in main.o
  "sf::Window::~Window()", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [debug/sfml-test-d] Error 1
make: *** [tests] Error 2


edit: if I compile with just the shared libraries it works (i.e with the -l options). How do I get it to compile using the framework option?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
How to link to SFML 2.0 statically
« Reply #12 on: October 29, 2011, 09:45:16 am »
SFML.framework only contains headers files. I know it's weird however, it was the only solution to provide headers to the users.

You have to link against sfml-[system|window|graphics|network|audio] frameworks.
SFML / OS X developer

mercurio7891

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
How to link to SFML 2.0 statically
« Reply #13 on: October 29, 2011, 10:16:35 am »
just curious, is it not possible to include them all in an umbrella framework?

I know the apple page discourages it. But would that work?

regards

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
How to link to SFML 2.0 statically
« Reply #14 on: October 31, 2011, 07:19:37 pm »
It *could* work but it would be different from Linux & Windows structures of SFML for little or no gain. So I prefer stick with something similar to those platforms.

Also, someone can use only the network module if he wants. In this scenario I'm not sure that umbrella framework would work.
SFML / OS X developer