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

Author Topic: Problem finding correct libjpeg  (Read 3824 times)

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Problem finding correct libjpeg
« on: March 23, 2015, 02:18:48 pm »
When I tried to compile Thor with MinGW, I got linker errors in one of SFML's dependencies. Some symbols from libjpeg were not found.

Debugging showed me that during the CMake configuration step, a wrong libjpeg path is found:
find_package(SFML 2 COMPONENTS audio graphics window system)
message(STATUS "Dep: ${SFML_DEPENDENCIES}")
Quote
Dep: ... C:/Program Files (x86)/Java/jre7/bin/jpeg.dll ...

Why does it even find a .dll and not a .lib file? These arguments are supposed to be passed to target_link_libraries in order to be linked (not loaded at runtime like DLLs).

Investigating FindSFML.cmake shows that the call to find_library (through the macro find_sfml_dependency) already returns this wrong path... Which is strange since the library path appears first in the list, and I made sure libjpeg.a is there.

Debugging output used in FindSFML.cmake inside find_sfml_dependency:
message("\nFinding ${output} (${ARGN}) in ${FIND_SFML_PATHS}")
message(" -> ${${output}}")
Quote
Finding JPEG_LIBRARY (jpeg) in C:/C++Libs/mingw;~/Library/Frameworks;/Library/Frameworks;/usr/local;/usr;/sw;/opt/local;/opt/csw;/opt
 -> C:/Program Files (x86)/Java/jre7/bin/jpeg.dll
There is a file C:/C++Libs/mingw/lib/libjpeg.a, but somehow it's not recognized.

Strangely, the NMake toolchain works fine.

By the way, why does SFML not ship a FindJPEG.cmake module?
« Last Edit: March 23, 2015, 02:22:19 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Problem finding correct libjpeg
« Reply #1 on: March 23, 2015, 02:28:30 pm »
Quote
Why does it even find a .dll and not a .lib file?
gcc on Windows can link directly to .dll files for C libraries. So you can expect them to be found as import libraries when trying to locate libraries.

Quote
By the way, why does SFML not ship a FindJPEG.cmake module?
Because there's one in CMake. But I guess your question is more "why don't we use find_package in FindSFML.cmake?", and... that is another story ;D

Back to the problem: you should check the search order used by find_program in the CMake doc.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Problem finding correct libjpeg
« Reply #2 on: March 23, 2015, 02:45:58 pm »
Back to the problem: you should check the search order used by find_program in the CMake doc.
I assume you mean find_library, as this one is invoked by FindSFML.cmake.

I read the documentation, and environment variables (containing the JRE path in my example) are indeed looked up before the passed PATHS argument.

This can be disabled by passing NO_SYSTEM_ENVIRONMENT_PATH to find_library. It works like this. The question is, do we break other cases if we disable lookup in environment variables?

An option (described at the end of the doc) is to call find_library multiple times: first without taking environment variables into account, then -- only if nothing is found -- again with them. That might be unnecessary though.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Problem finding correct libjpeg
« Reply #3 on: March 23, 2015, 02:53:17 pm »
Quote
This can be disabled by passing NO_SYSTEM_ENVIRONMENT_PATH to find_library. It works like this.
That should be a safe fix.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Problem finding correct libjpeg
« Reply #4 on: March 23, 2015, 02:56:21 pm »
Ok, I'll propose a corresponding pull request.
[Edit] Here: #839

Thanks for the quick help! :)
« Last Edit: March 23, 2015, 03:48:10 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: