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

Author Topic: Help automatically specifying LD_LIBRARY_PATH ?  (Read 882 times)

0 Members and 1 Guest are viewing this topic.

kotrunga

  • Newbie
  • *
  • Posts: 6
    • View Profile
Help automatically specifying LD_LIBRARY_PATH ?
« on: March 13, 2018, 03:11:06 pm »
Hello! I'm new to SFML, and am learning how to use it with C++! It's super exciting, and I'm grateful there's a large community!

I did the SFML Mac OS X tutorial here https://www.sfml-dev.org/tutorials/2.4/start-osx.php, and then I just did the one for Linux here https://www.sfml-dev.org/tutorials/2.4/start-linux.php.

I did both on OS X. I like the idea of doing things by hand- not that Xcode is bad, but I am always trying to learn more about how things work under the hood. However, at the end of the linux tutorial, I couldn't run ./sfml-app on OS X, because I needed to do this step:



Once I did that (using only one & on OS X) it worked! But, what if I want to send a game I make to someone to play? I obviously want to share the game, but I don't want them to have to type that export command every time they want to run the game.

The Question:
How can I build the game and share it so that they don't have to type the export LD_LIBRARY_PATH... command? I just want them to be able to double click the .app file and go!


Thanks for the help!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9676
    • View Profile
    • development blog
    • Email
Re: Help automatically specifying LD_LIBRARY_PATH ?
« Reply #1 on: March 13, 2018, 03:30:27 pm »
For macOS the recommended way is to create an bundle which I think only works with Xcode or so... (not a macOS user here).

For your current situation, you could create a shell script that executes the export and starts the game. There should also be some solution with RPATH (somehow).
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

kotrunga

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Help automatically specifying LD_LIBRARY_PATH ?
« Reply #2 on: March 13, 2018, 07:51:55 pm »
Gotcha- thanks for the reply! If nothing else, a shell script is a good idea, like you said!

So if I want to write a game, the only way to do it is through CodeBlocks on Windows and Xcode on OS X ?

If that's the case that's fine, I'm just trying to figure out if I have to use those tools or not. I'm very grateful SFML provides easy tutorials and works with the tools well on all main operating systems- that's huge, and it's amazing! I'm just talking about not using them for learning purposes.

Thanks for the help!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9676
    • View Profile
    • development blog
    • Email
Re: Help automatically specifying LD_LIBRARY_PATH ?
« Reply #3 on: March 13, 2018, 07:57:39 pm »
As I'm said, I'm not a macOS user, so I can't tell you what options you really got. ;)

On Windows you can build any way you want with Code::Blocks, Visual Studio, MinGW, Clang or MSVC directly.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Help automatically specifying LD_LIBRARY_PATH ?
« Reply #4 on: March 17, 2018, 06:29:05 pm »
On mac, you can completely ditch Xcode and do everything it does yourself. You'll might have to play with `install_name_tool` (I don't remember exactly to be honest) when creating the .app folder & its internal components. To ship your app, it's pretty much a matter of copying the dependencies into your app bundle.

If you created an application bundle for SFML project with the Xcode wizard, you can go to your project build phases and have a look at the script created for you to get some inspiration. You can also have a look at all the steps Xcode does to get the full picture.

Or, I guess, you could use cmake on all platforms and not worry about all that. I understand you want to learn how it works, but once you got the idea you probably want to have something easy to maintain. I'll let you judge if it worth it for you or not. ;-)
SFML / OS X developer

Jonny

  • Full Member
  • ***
  • Posts: 113
    • View Profile
    • Email
Re: Help automatically specifying LD_LIBRARY_PATH ?
« Reply #5 on: March 17, 2018, 10:43:15 pm »
I use cmake to create projects for any platform (Specifically, I use VS on windows, Xcode on macOS and vscode on linux)

Although not strictly essential, I would recommend using Xcode on macOS. It's completely free and will manage the app bundle better than manually creating the .app structure. You can also use it entirely from the command line too if that's your preferred way (which is also made significantly easier using cmake)

cmake also has the added advantage that if you ever collaborate, other people can easily set up the project for whatever tool/environment they like to use.

 

kotrunga

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Help automatically specifying LD_LIBRARY_PATH ?
« Reply #6 on: March 19, 2018, 02:17:24 pm »
@Jonny Thank you!

That's great advice. I'll look into using cmake. Any advice / guides on using cmake in conjunction with Xcode for SFML?

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: Help automatically specifying LD_LIBRARY_PATH ?
« Reply #7 on: March 19, 2018, 11:45:08 pm »
Runpath search paths really is the way to go if you want SFML to be automatically found.
You should check https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/RunpathDependentLibraries.html#//apple_ref/doc/uid/TP40008306-SW3 (section "Using Run-Path Dependent Libraries").
With this you can save in your exe where the OS should look for its dependencies (usually inside your application bundle). And the paths to look for can be relative to your executable if you make use of @executable_path or @loader_path.

Note that you don't *HAVE* to create a bundle application, if you set the runpath search paths correctly you'll be able to run your executable without changing LD_LIBRARY_PATH. But bundle applications are what most macOS users expect, because they prefer to see a single "file" (ie. application) rather than an executable and a bunch of files/directories next to it.
Want to play movies in your SFML application? Check out sfeMovie!

kotrunga

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Help automatically specifying LD_LIBRARY_PATH ?
« Reply #8 on: March 23, 2018, 12:33:37 am »
@Ceylo thank you so much! Super helpful!!!