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

Author Topic: Embed binary files into the compiled executable file?  (Read 3199 times)

0 Members and 1 Guest are viewing this topic.

MaTachi

  • Newbie
  • *
  • Posts: 5
    • View Profile
Embed binary files into the compiled executable file?
« on: October 11, 2012, 12:07:47 am »
Hi!

When I want to load an image into a Texture in SFML I need to specify the path to the image. For an example:

texture.loadFromFile("res/logo.png");

The problem when running the compiled executable then is that it needs to accompanied with the res folder. I would like to find a way to embed images into the compiled file, so I only need 1 file to be able to run the program.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Embed binary files into the compiled executable file?
« Reply #1 on: October 11, 2012, 12:12:40 am »
This is not really related to SFML and is very specific to the compiler.
With Visual Studio it should be possible to include the file in the binary and have a path that will point to the file inside the binary.
Then again I haven't tested this...

As I said it's not related to SFML so you should explicitly search solutions for your compiler on how to embed files and retrieve them. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MaTachi

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Embed binary files into the compiled executable file?
« Reply #2 on: October 11, 2012, 12:45:34 am »
Ah, okey. I thought the library needed to have some support for it, like a method in Texture.

And I'm a Linux user. :P

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Embed binary files into the compiled executable file?
« Reply #3 on: October 11, 2012, 12:54:13 am »
And I'm a Linux user. :P
Well on Linux I've even less knowledge on that topic, but that's why we got our friend Google and look what I just ran into: Embedding a File in an Executable

So after you've got a pointer or similar to the data you probably will have to load it with loadFromMemory() ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Embed binary files into the compiled executable file?
« Reply #4 on: October 11, 2012, 09:57:46 am »
You can transform your resource file to an array of char, include it to your sources, and load it with loadFromMemory.

You don't have to bother with OS specific resource handling.
Laurent Gomila - SFML developer