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

Author Topic: How to avoid linking my static lib to SFML's?  (Read 4201 times)

0 Members and 1 Guest are viewing this topic.

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
How to avoid linking my static lib to SFML's?
« on: March 16, 2014, 10:46:32 am »
I've created a static library and added some of my generic game systems for reuse on future projects.  However, when I link SFML I get a few warnings.

Quote
warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined...
warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library

Searching around I got plenty of hits.

Quote
Never link static libraries to your library! It can be painful, but you have to require that your applications link to your dependencies.

Quote
You don't need to add any dependencies when creating a static library. If your library uses d3d9.lib, then let the build of the EXE/DLL link it in.

It's clear I shouldn't be linking a static library to my static library.  However, I don't understand the solution.  Are they suggesting my game, that uses my static library, should link SFML?  If so this is already the case, and I don't see how this would give my static library access to SFML functionality.
« Last Edit: March 16, 2014, 10:52:16 am by Kanefa »

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: How to avoid linking my static lib to SFML's?
« Reply #1 on: March 16, 2014, 01:56:40 pm »
I  forward declared all SFML references in my static library and that work.  I think this what they meant by allowing the application to link the dependencies.  However, I am not sure it will always be possible, or painful as they mentioned.
« Last Edit: March 16, 2014, 01:58:26 pm by Kanefa »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: How to avoid linking my static lib to SFML's?
« Reply #2 on: March 16, 2014, 08:47:06 pm »
Your description is a bit vague, thus it's hard to tell what exactly the problem was.
If you create a static lib you don't need to link against other static libraries, instead link all the static libraries in the final application.
If you were talking about mixing dynamic and static linkage, you shouldn't, except you know and understand what you're doing. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: How to avoid linking my static lib to SFML's?
« Reply #3 on: March 17, 2014, 02:04:55 pm »
I was linking a static library to SFML.  I am trying to move some generic game systems into a static library for reuse on other projects.  However, I ran into this problem. 

As my second post says I stopped linking my my static library and used forward declares (linking to SFML in my game).  However, I just ran into the situation where I am inheriting a SFML class and a forward declare will not work (incomplete type is not allowed) in my static library.

...instead link all the static libraries in the final application.

I may just not understand, but I don't see how this solves the problem.  If my static library needs definitions from SFML how does linking my static library and SFML in my game fix this?
« Last Edit: March 17, 2014, 02:14:36 pm by Kanefa »

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: How to avoid linking my static lib to SFML's?
« Reply #4 on: March 17, 2014, 02:13:01 pm »
You seem to be thinking including a header would link a library; thats wrong. A header normally does only contain declarations that the compiler can use.
Library building and linking is a separate concept that depends on how you use the library archiver or linker program and only uses object files and library files.

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: How to avoid linking my static lib to SFML's?
« Reply #5 on: March 17, 2014, 02:32:10 pm »
You seem to be thinking including a header would link a library; thats wrong. A header normally does only contain declarations that the compiler can use.
Library building and linking is a separate concept that depends on how you use the library archiver or linker program and only uses object files and library files.

I linked SFML to my static library just as I would link my game project to SFML.  The only difference being the librarian.  I thought that was what I needed to do.  I got the warnings and realized I was doing something wrong. 


Now I am trying to figure out how to get access to SFML from my static library.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to avoid linking my static lib to SFML's?
« Reply #6 on: March 17, 2014, 02:38:49 pm »
Static libraries must not be linked from other static libraries -- they are all linked from the final executable.

You get access to SFML simply by including it. The symbols will be resolved when you link the executable.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: How to avoid linking my static lib to SFML's?
« Reply #7 on: March 17, 2014, 06:47:55 pm »
Static libraries must not be linked from other static libraries -- they are all linked from the final executable.

You get access to SFML simply by including it. The symbols will be resolved when you link the executable.

Now I understand, thanks.

 

anything