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

Author Topic: Working from sources. Add custom module to SFML  (Read 1052 times)

0 Members and 1 Guest are viewing this topic.

joe5513

  • Newbie
  • *
  • Posts: 11
    • View Profile
Working from sources. Add custom module to SFML
« on: March 05, 2018, 01:17:55 pm »
Hi all.

I am working with SFML for quite some time now, and really enjoy it.

Last couple of months im writing my own simple game library, 100% based on manually builded SFML from master branch.
And i wondering how can i add 'custom' module to SFML? Like sfml-editor.lib for example.
Currently i have typical SFML project where my 'editor' module is. It contains scene, graph, nodes and all that stuff, with ability to save and load it from disk.

So the answer is that i need to build .lib file from my project and then link it alongside core SFML?
What is correct way to create custom module, that will behave like SFML module?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Working from sources. Add custom module to SFML
« Reply #1 on: March 05, 2018, 02:22:49 pm »
You shouldn't be trying to create an "SFML module", because your code isn't part of SFML and thus isn't an SFML module. You can however of course create your own library and link that in whatever way you want.
If you want to use CMake for your project generation you'll probably have to invest some time into learning what needs to be done. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

joe5513

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Working from sources. Add custom module to SFML
« Reply #2 on: March 05, 2018, 02:57:43 pm »
Saying 'SFML module' was a bad choise, but what i mean is that i want to create library which will be based on SFML and can be linked with actual SFML, to extend its functionality. So there is no problem with that, i got it :)
Sorry for been unclear with that.

And a thing about CMake.

(Windows 10)
When generating project files for dinamic linking, there is a flag SFML_USE_STATIC_STD_LIBS. What libs is that? MSVCRT.DLL?
When dinamically linking SFML, MSVCRT.DLL should be next to the executable as well? Or that done automatically?

Thanks!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Working from sources. Add custom module to SFML
« Reply #3 on: March 05, 2018, 03:15:47 pm »
You can't create dynamic SFML libraries with statically linked runtime library. SFML's CMake script will just return an error.

If you create static SFML libraries, SFML_USE_STATIC_STD_LIBS set to true will use /MT or /MTd respectively to the relase/debug mode. Where setting it to false will use /MD or /MDd.

To create a library, you create a library project and make sure to export the symbols you want.
If you use SFML, then you'll just have to link SFML to your dynamic library when building your dynamic library or link SFML to your application when using your static library.

How to concretely work with libraries for your tool chain, you'd be better of asking on StackOverflow or similar as it is unrelated to SFML.
« Last Edit: March 05, 2018, 03:18:28 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

joe5513

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Working from sources. Add custom module to SFML
« Reply #4 on: March 05, 2018, 03:31:30 pm »
You can't create dynamic SFML libraries with statically linked runtime library. SFML's CMake script will just return an error.

Yeah i got it, but what i mean is that when i link SFML dinamically, that means that std libs will be linked dinamically too, right? So i need to put std libs alongside executable or it will be searched and linked automatically under the hood?

Sorry if that question sounds stupid.
Knowledge is power.

Thanks!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Working from sources. Add custom module to SFML
« Reply #5 on: March 05, 2018, 03:44:14 pm »
Yes, if you dynamically link the runtime libs, you need to provide them. If you use VS, then you get the option to install the redist for your runtime libs version or you can grab the various DLLs from your VS installation. Where they are located exactly can be found easily by googling.

Thing you should definitely consider is going either fully dynamic or fully static. Don't use static runtime libs for SFML and then link against dynamic libs in your application, otherwise you might quickly run into issues.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything