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

Author Topic: [Mac] Precompiled OpenAL in CMake  (Read 7435 times)

0 Members and 2 Guests are viewing this topic.

magicpen

  • Newbie
  • *
  • Posts: 4
    • View Profile
[Mac] Precompiled OpenAL in CMake
« on: August 24, 2011, 08:09:58 pm »
I'm trying to integrate SFML2 into my own CMake process on Mac/OSX Lion with the latest XCode. Here is my CMakeLists.txt:

Code: [Select]
# SFML
add_subdirectory(${SFML_ROOT_PATH})
include_directories(${SFML_ROOT_PATH}/include)

# MyProject
...
add_executable(myproject WIN32 MACOSX_BUNDLE ${MYPROJECT_FILES} )
target_link_libraries(myproject sfml-system sfml-window sfml-audio)


I am using static compilation.

MyProject then has a Main.cpp that includes <SFML/system.hpp> and makes the SFML timer work reliably. It is awesome and clean.
However, using <SFML/audio.hpp> compilation fails because it can't use or find some proper library (OpenAL or libsndfile?) and complains about unreferenced symbols.

Here is the error Message XCode throws at me:

Code: [Select]
Ld /Users/myusername/Documents/Awesome_CMake/bin/Debug/myexecutable.app/Contents/MacOS/myexecutable normal x86_64
    cd /Users/myusername/Dropbox/Awesome_Trunk
    setenv MACOSX_DEPLOYMENT_TARGET 10.7
    /Developer/usr/bin/llvm-g++-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/myusername/Documents/Awesome_CMake/bin/Debug -F/Users/myusername/Documents/Awesome_CMake/bin/Debug -F/Applications -filelist /Users/myusername/Documents/Awesome_CMake/Awesome.build/Debug/myexecutable.build/Objects-normal/x86_64/myexecutable.LinkFileList -mmacosx-version-min=10.7 -Wl,-search_paths_first -Wl,-headerpad_max_install_names  /Users/myusername/Documents/Awesome_CMake/libs/SFML-b9b3888/lib/Debug/libsfml-system-s-d.a /Users/myusername/Documents/Awesome_CMake/libs/SFML-b9b3888/lib/Debug/libsfml-window-s-d.a /Users/myusername/Documents/Awesome_CMake/libs/SFML-b9b3888/lib/Debug/libsfml-audio-s-d.a /Users/myusername/Documents/Awesome_CMake/libs/SFML-b9b3888/lib/Debug/libsfml-system-s-d.a -o /Users/myusername/Documents/Awesome_CMake/bin/Debug/myexecutable.app/Contents/MacOS/myexecutable

Undefined symbols for architecture x86_64:
  "_alGetError", referenced from:
      sf::priv::ALCheckError(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)in libsfml-audio-s-d.a(ALCheck.o)
  "_alGetEnumValue", referenced from:
      sf::priv::AudioDevice::GetFormatFromChannelsCount(unsigned int)in libsfml-audio-s-d.a(AudioDevice.o)
  "_alcIsExtensionPresent", referenced from:
      sf::priv::AudioDevice::IsExtensionSupported(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in libsfml-audio-s-d.a(AudioDevice.o)
...


To fix this on Windows, I'd probably just have to copy the needed .dlls somewhere and be done with it. But I have no idea what to do on a Mac. Do I have to tell CMake something special so that it finds the precompiled libraries you provide? I'd rather not manually copy libraries/frameworks around on my harddrive because I work with multiple Macs that are not mine and I have to keep it portable.

Thank you in advance for any help. :) I'm really stumped here.  :oops:

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[Mac] Precompiled OpenAL in CMake
« Reply #1 on: August 24, 2011, 09:50:46 pm »
Quote
I am using static compilation.
You should rather not use static libraries on Unix|BSD-like. There is no benefit in using them because you can include pretty much any resources in an application bundle (.app). See how the Xcode 4 templates works with dylibs or frameworks version of SFML libraries.

Quote
OpenAL or libsndfile?
Both. You can see how SFML link them in src/Audio/CMakeLists.txt (I think). OpenAL is by default installed on a Mac but sndfile isn't. So you'll have to ship a copy of sndfile.framework with your application (or rebuild it and link it statically but its license might not be compatible with your application's license – you should check that out).
SFML / OS X developer

magicpen

  • Newbie
  • *
  • Posts: 4
    • View Profile
[Mac] Precompiled OpenAL in CMake
« Reply #2 on: August 25, 2011, 08:27:38 am »
Thank you for the help Hiura.

Quote
OpenAL or libsndfile?

Both. You can see how SFML link them in src/Audio/CMakeLists.txt (I think). OpenAL is by default installed on a Mac but sndfile isn't. So you'll have to ship a copy of sndfile.framework with your application (or rebuild it and link it statically but its license might not be compatible with your application's license – you should check that out).


:( I was trying to avoid including too much fluff to keep things simple and one-click-compilable. I guess I might as well just use a precompiled SFML 1.6 then.

Are there any tutorials/ressources on how to create a cross-platform CMake file that uses a precompiled 1.6 and its dependencies? I guess I want to automate the step "Integrating the libraries / frameworks into your application" via CMake for OSX, Windows and Linux. I suppose FindSFML.cmake can be used for this somehow.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[Mac] Precompiled OpenAL in CMake
« Reply #3 on: August 25, 2011, 01:38:03 pm »
Quote from: "magicpen"
I guess I might as well just use a precompiled SFML 1.6 then.
SFML 1.6 also uses sndfile and is generally more buggy than 2.0. So why would you roll back to 1.6 ? (I might have missed something but I don't see what.)

Quote from: "magicpen"
Are there any tutorials/ressources on how to create a cross-platform CMake file that uses a precompiled 1.6 and its dependencies? I guess I want to automate the step "Integrating the libraries / frameworks into your application" via CMake for OSX, Windows and Linux. I suppose FindSFML.cmake can be used for this somehow.
I don't know if FindSFML.cmake works with 1.6. I guess it doesn't.

Anyway, if you want to copy resources to your application bundle, you can do something like what I do to copy headers to SFML.framework (see root/CMakeLists.txt, at the end of the file). It should work pretty much the same.
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Mac] Precompiled OpenAL in CMake
« Reply #4 on: August 25, 2011, 01:45:48 pm »
Quote
I don't know if FindSFML.cmake works with 1.6. I guess it doesn't.

I've written it so that it should work with SFML 1. It's probably not tested though :D
Laurent Gomila - SFML developer

magicpen

  • Newbie
  • *
  • Posts: 4
    • View Profile
[Mac] Precompiled OpenAL in CMake
« Reply #5 on: August 31, 2011, 11:15:18 pm »
Thank you for the help. I got a precompiled SFML 1.6 to work, but not in the way I want. The reason for switching to 1.6 from 2.0 was that 1.6 comes precompiled and is labeled 'stable'.

My folder layout is this:

Code: [Select]

project/libs/SFML-1.6/include/SFML/Audio.hpp
project/libs/SFML-1.6/lib-mac/sfml-audio.framework/...
project/libs/SFML-1.6/lib-mac/sndfile.framework/...
project/libs/SFML-1.6/lib-win/sfml-audio.dll
project/libs/SFML-1.6/lib-win/sfml-audio.lib
project/libs/SFML-1.6/lib-win/libsndfile-1.dll
project/src/main.cpp


Here is my new CMakeList.txt
Code: [Select]
# SFML
set(SFML_PATH ${PROJECT_ROOT}/libs/SFML-1.6)
FIND_LIBRARY(SFML_AUDIO_LIBRARY NAMES sfml-audio sfml-audio.dll PATHS ${SFML_PATH}/lib-mac ${SFML_PATH}/lib-win DOC "SFML-audio library")
FIND_LIBRARY(SFML_SNDFILE_LIBRARY NAMES sndfile sndfile.dll PATHS ${SFML_PATH}/lib-mac ${SFML_PATH}/lib-win DOC "SFML-sndfile library")
include_directories(${SFML_PATH}/include)
set(SFML_LIBRARY ${SFML_AUDIO_LIBRARY} ${SFML_SNDFILE_LIBRARY})

...

add_executable(myapp ... )
target_link_libraries(myapp glfw ${SFML_LIBRARY} )


CMake correctly finds the library on my Mac when I compile the CMake file -
SFML_SNDFILE_LIBRARY = "/Users/username/Project/libs/SFML-1.6/lib-mac/sndfile.framework" and Compiling the project on XCode throws no linker errors.

When starting this compiled project now though, it crashes because the executable can't actually find the library/framework (Library not loaded ... image not found - exactly like this old post).

The way I got it to work was to copy all the libs to /System/Library/Frameworks - but I'd rather CMake took care of this somehow. Why doesn't it find those Frameworks when it can see the correct folder?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[Mac] Precompiled OpenAL in CMake
« Reply #6 on: September 01, 2011, 10:37:40 am »
Quote from: "magicpen"
When starting this compiled project now though, it crashes because the executable can't actually find the library/framework (Library not loaded ... image not found - exactly like this old post).

The way I got it to work was to copy all the libs to /System/Library/Frameworks - but I'd rather CMake took care of this somehow. Why doesn't it find those Frameworks when it can see the correct folder?
Framework search path is not the same at compilation time and at run time.

You can workaround this installation-thing by creating an application bundle instead of a classic executable and copying the .framework to youexe.app/Contents/Frameworks/ .

You could do something relatively similar to what I do here to copy the frameworks.
SFML / OS X developer