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

Author Topic: Help with static linking  (Read 3081 times)

0 Members and 1 Guest are viewing this topic.

Kooekrus

  • Newbie
  • *
  • Posts: 5
    • View Profile
Help with static linking
« on: October 01, 2015, 12:58:41 am »
I'm trying to create a staticly linked executable. I've been searching and trying for two hours with no success, and I can't find anything to help me anywhere. I have proper code, it will compile and run when dynamicly linked, and I have all the static libraries, I just can't get my program to compile staticly, it just throws a ton of errors saying "undefined reference". The command I'm using to compile is below

Code: [Select]
g++ -DSFML_STATIC -I/usr/local/./include/SFML -L/usr/local/lib main.cpp -lsfml-graphics-s -lsfml-window-s -lsfml-system-s

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Help with static linking
« Reply #1 on: October 01, 2015, 01:02:49 am »
Maybe if you posted the specific errors you get people would have a chance to suggest what libraries (or whatever) you are not linking correctly.
Remember this though: when linking statically, SFML itself must have been built for static linking and you must explicitly link all of its dependencies.

Kooekrus

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with static linking
« Reply #2 on: October 01, 2015, 01:08:36 am »
Maybe if you posted the specific errors you get people would have a chance to suggest what libraries (or whatever) you are not linking correctly.
Remember this though: when linking statically, SFML itself must have been built for static linking and you must explicitly link all of its dependencies.
Then it's probably my build of SFML, I didn't link its dependencies. Is there any place that explains how to do that?

Kooekrus

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with static linking
« Reply #3 on: October 01, 2015, 01:12:43 am »
I'm trying to create a staticly linked executable. I've been searching and trying for two hours with no success, and I can't find anything to help me anywhere. I have proper code, it will compile and run when dynamicly linked, and I have all the static libraries, I just can't get my program to compile staticly, it just throws a ton of errors saying "undefined reference". The command I'm using to compile is below

Code: [Select]
g++ -DSFML_STATIC -I/usr/local/./include/SFML -L/usr/local/lib main.cpp -lsfml-graphics-s -lsfml-window-s -lsfml-system-s
The errors I get are below (spoiler because it's long)
(click to show/hide)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Help with static linking
« Reply #4 on: October 01, 2015, 01:25:37 am »
You searched everywhere? Except for the most obvious place, that is the official tutorial? And all the other hundred threads about static linking? ;)

As has been said link SFML's dependencies as explained in the official "setup" tutorials.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Help with static linking
« Reply #5 on: October 01, 2015, 01:47:17 am »
it seems like you didn't added some libraries which is used in the code

Kooekrus

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with static linking
« Reply #6 on: October 01, 2015, 03:51:04 pm »
You searched everywhere? Except for the most obvious place, that is the official tutorial? And all the other hundred threads about static linking? ;)

As has been said link SFML's dependencies as explained in the official "setup" tutorials.
I looked there, I didn't understand it that well

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Help with static linking
« Reply #7 on: October 01, 2015, 04:21:07 pm »
If you've been reading the "SFML & Linux" tutorial, then it's not explained. (why?)
You have to link SFML dependencies for each module you're using, I don't know where to find the list of dependencies for Linux (I haven't searched) but you can find one for Windows in the FAQ or in the codeblocks and Visual Studio tutorials.
And I've read here that it's recommended to link dynamically on Linux and mac.

Kooekrus

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with static linking
« Reply #8 on: October 02, 2015, 01:41:48 pm »
If you've been reading the "SFML & Linux" tutorial, then it's not explained. (why?)
You have to link SFML dependencies for each module you're using, I don't know where to find the list of dependencies for Linux (I haven't searched) but you can find one for Windows in the FAQ or in the codeblocks and Visual Studio tutorials.
And I've read here that it's recommended to link dynamically on Linux and mac.
Okay, thank you!