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

Author Topic: Problem with static linking  (Read 2838 times)

0 Members and 1 Guest are viewing this topic.

bilbosz

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Problem with static linking
« on: January 09, 2018, 05:08:34 pm »
Hi,

I've tried to move from Microsoft Visual Studio 2015 project to CMake. It's a team project so I wanted to make it portable and easy to build as possible. Static linking would be great because I can skip copying DLLs. I'm using 2.4.1 version of SFML. Here is interesting part of CMakeLists.txt:
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML 2.4.1 REQUIRED audio graphics main network system window)
if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(${MAIN_TARGET} ${SFML_DEPENDENCIES} ${SFML_LIBRARIES})
endif()
After building it, I'm getting linker messages:
Code: [Select]
1>sfml-graphics-s-d.lib(ImageLoader.cpp.obj) : error LNK2019: unresolved external symbol _jpeg_std_error referenced in function "private: bool __thiscall sf::priv::ImageLoader::writeJpg(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<unsigned char,class std::allocator<unsigned char> > const &,unsigned int,unsigned int)" (?writeJpg@ImageLoader@priv@sf@@AAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@EV?$allocator@E@std@@@5@II@Z)
1>sfml-graphics-s-d.lib(ImageLoader.cpp.obj) : error LNK2019: unresolved external symbol _jpeg_CreateCompress referenced in function "private: bool __thiscall sf::priv::ImageLoader::writeJpg(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<unsigned char,class std::allocator<unsigned char> > const &,unsigned int,unsigned int)" (?writeJpg@ImageLoader@priv@sf@@AAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@EV?$allocator@E@std@@@5@II@Z)
1>sfml-graphics-s-d.lib(ImageLoader.cpp.obj) : error LNK2019: unresolved external symbol _jpeg_destroy_compress referenced in function "private: bool __thiscall sf::priv::ImageLoader::writeJpg(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<unsigned char,class std::allocator<unsigned char> > const &,unsigned int,unsigned int)" (?writeJpg@ImageLoader@priv@sf@@AAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@EV?$allocator@E@std@@@5@II@Z)
1>sfml-graphics-s-d.lib(ImageLoader.cpp.obj) : error LNK2019: unresolved external symbol _jpeg_stdio_dest referenced in function "private: bool __thiscall sf::priv::ImageLoader::writeJpg(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<unsigned char,class std::allocator<unsigned char> > const &,unsigned int,unsigned int)" (?writeJpg@ImageLoader@priv@sf@@AAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@EV?$allocator@E@std@@@5@II@Z)
1>sfml-graphics-s-d.lib(ImageLoader.cpp.obj) : error LNK2019: unresolved external symbol _jpeg_set_defaults referenced in function "private: bool __thiscall sf::priv::ImageLoader::writeJpg(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<unsigned char,class std::allocator<unsigned char> > const &,unsigned int,unsigned int)" (?writeJpg@ImageLoader@priv@sf@@AAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@EV?$allocator@E@std@@@5@II@Z)
1>sfml-graphics-s-d.lib(ImageLoader.cpp.obj) : error LNK2019: unresolved external symbol _jpeg_set_quality referenced in function "private: bool __thiscall sf::priv::ImageLoader::writeJpg(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<unsigned char,class std::allocator<unsigned char> > const &,unsigned int,unsigned int)" (?writeJpg@ImageLoader@priv@sf@@AAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@EV?$allocator@E@std@@@5@II@Z)
1>sfml-graphics-s-d.lib(ImageLoader.cpp.obj) : error LNK2019: unresolved external symbol _jpeg_start_compress referenced in function "private: bool __thiscall sf::priv::ImageLoader::writeJpg(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<unsigned char,class std::allocator<unsigned char> > const &,unsigned int,unsigned int)" (?writeJpg@ImageLoader@priv@sf@@AAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@EV?$allocator@E@std@@@5@II@Z)
1>sfml-graphics-s-d.lib(ImageLoader.cpp.obj) : error LNK2019: unresolved external symbol _jpeg_write_scanlines referenced in function "private: bool __thiscall sf::priv::ImageLoader::writeJpg(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<unsigned char,class std::allocator<unsigned char> > const &,unsigned int,unsigned int)" (?writeJpg@ImageLoader@priv@sf@@AAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@EV?$allocator@E@std@@@5@II@Z)
1>sfml-graphics-s-d.lib(ImageLoader.cpp.obj) : error LNK2019: unresolved external symbol _jpeg_finish_compress referenced in function "private: bool __thiscall sf::priv::ImageLoader::writeJpg(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<unsigned char,class std::allocator<unsigned char> > const &,unsigned int,unsigned int)" (?writeJpg@ImageLoader@priv@sf@@AAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@EV?$allocator@E@std@@@5@II@Z)
1>freetype.lib(bdf.obj) : error LNK2019: unresolved external symbol _sprintf referenced in function __bdf_parse_properties

In Visual Studio it looks as it should:
Linker - Additional Dependecies:
Code: [Select]
D:\Library\SFML-2.4.1\lib\sfml-audio-s.lib
D:\Library\SFML-2.4.1\lib\sfml-graphics-s.lib
D:\Library\SFML-2.4.1\lib\sfml-main.lib
D:\Library\SFML-2.4.1\lib\sfml-network-s.lib
D:\Library\SFML-2.4.1\lib\sfml-system-s.lib
D:\Library\SFML-2.4.1\lib\sfml-window-s.lib
D:\Library\SFML-2.4.1\lib\freetype.lib
opengl32.lib
winmm.lib
gdi32.lib
ws2_32.lib
D:\Library\SFML-2.4.1\lib\openal32.lib
D:\Library\SFML-2.4.1\lib\flac.lib
D:\Library\SFML-2.4.1\lib\vorbisenc.lib
D:\Library\SFML-2.4.1\lib\vorbisfile.lib
D:\Library\SFML-2.4.1\lib\vorbis.lib
D:\Library\SFML-2.4.1\lib\ogg.lib
There is preprocessor directive:
Code: [Select]
SFML_STATIC
Am I doing it right? Or should I add DLLs anyway.

Thanks

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: Problem with static linking
« Reply #1 on: January 09, 2018, 05:57:09 pm »
You first need to link the SFML libraries and then its dependencies, simply switch the two in your CMake script.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

bilbosz

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Problem with static linking
« Reply #2 on: January 09, 2018, 06:38:18 pm »
It didn't help.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: Problem with static linking
« Reply #3 on: January 09, 2018, 06:40:11 pm »
Ah, I didn't see it, the order that you request the modules also matter. The window module depends on the system module do it has to be placed before the system module.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

bilbosz

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Problem with static linking
« Reply #4 on: January 09, 2018, 06:56:54 pm »
I did as you said, it doesn't change linking message error.

CMakeLists.txt:
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML 2.4.1 REQUIRED window audio graphics main network system)
if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(${MAIN_TARGET} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
endif()

Do you suggest any particular order?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: Problem with static linking
« Reply #5 on: January 09, 2018, 07:32:26 pm »
Just go by the rule of "x depends on y, thus x comes before y".
window depends on system so it comes before, but graphics depends on window, so it has to come before the window module.
Check the official tutorial to see the list of dependency and the suggested order.

Make sure you're actually regenerating the project file after adjusting your CMake script.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

bilbosz

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Problem with static linking
« Reply #6 on: January 09, 2018, 08:19:58 pm »
I've tried sorted topologically (according to https://www.sfml-dev.org/tutorials/2.4/start-vc.php)
find_package(SFML 2.4.1 REQUIRED system window graphics audio main network)
reversed
find_package(SFML 2.4.1 REQUIRED network main audio graphics window system)
was checking both with
target_link_libraries(${MAIN_TARGET} ${SFML_DEPENDENCIES} ${SFML_LIBRARIES})
and
target_link_libraries(${MAIN_TARGET} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
regenerating build each time. If an order would be the reason then linker should complain about reference in the first or last targeted module, not the one in the middle. sf::priv::ImageLoader::writeJpg from ImageLoader.cpp belongs to graphics module. Are you sure order is the reason?
« Last Edit: January 09, 2018, 08:21:40 pm by bilbosz »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: Problem with static linking
« Reply #7 on: January 09, 2018, 09:21:23 pm »
Looking at the full list of errors, it seems like you're potentially not using the correct files for you compiler. What compiler are you using and what SFML package did you download?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

SizzleBae

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Problem with static linking
« Reply #8 on: January 21, 2019, 07:25:44 pm »
Make sure to update SFML to the newest version. We had the exact same linking errors, and this fixed the problem for us.