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

Author Topic: Linker misses flac.lib when linking SFML dynamically  (Read 2310 times)

0 Members and 1 Guest are viewing this topic.

Nimelrian

  • Newbie
  • *
  • Posts: 3
    • View Profile
Linker misses flac.lib when linking SFML dynamically
« on: July 30, 2015, 10:14:10 am »
Hi everyone,

we are using CMake to generate the build files for our project and make use of the findSFML module to use SFML.

Here's our CMakeLists file:

cmake_minimum_required(VERSION 3.0)

# forbid in-source build configurations
if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
  message(FATAL_ERROR "Insource builds are forbidden, use another build directory")
endif()

project(Project-Onyx LANGUAGES CXX)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(ONYX_INSTALL_DIR "${CMAKE_BINARY_DIR}/install/${CMAKE_BUILD_TYPE}")

include(${CMAKE_MODULE_PATH}/cotire.cmake)

set(SFML_ROOT "" CACHE PATH "SFML root directory")
set(BOOST_ROOT "" CACHE PATH "Boost root directory")

find_package(Boost 1.58.0 EXACT REQUIRED)
find_package(SFML 2.3 COMPONENTS system window graphics audio EXACT REQUIRED)

include_directories(${SFML_INCLUDE_DIR} ${BOOST_INCLUDE_DIR})

file(GLOB_RECURSE SIMULATION_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/Simulation/*)
file(GLOB_RECURSE VISUALISATION_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/Visualisation/*)

add_library(Simulation ${SIMULATION_SOURCE})
add_executable(Project-Onyx ${VISUALISATION_SOURCE})
target_link_libraries(Project-Onyx Simulation ${SFML_LIBRARIES})
set_property(TARGET Simulation Project-Onyx PROPERTY CXX_STANDARD 11)

install(TARGETS Project-Onyx DESTINATION "${ONYX_INSTALL_DIR}")

if(WIN32)
  # get the SFML-DLLs
  file(GLOB SFML_DEBUG_DLLS ${SFML_ROOT}/bin/*.dll)
  install(FILES ${SFML_DEBUG_DLLS} DESTINATION "${ONYX_INSTALL_DIR}")
endif()

file(GLOB TEXTURE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/res/data)
install(DIRECTORY ${TEXTURE_DIR} DESTINATION "${ONYX_INSTALL_DIR}")

set_target_properties(Project-Onyx PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT ${CMAKE_CURRENT_SOURCE_DIR}/src/Visualisation/stdafx.h)
set_target_properties(Project-Onyx PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
set_target_properties(Simulation PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT ${CMAKE_CURRENT_SOURCE_DIR}/src/Simulation/stdafx.h)
set_target_properties(Simulation PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
cotire(Project-Onyx)
cotire(Simulation)

Generating the build files works fine. Building the project itself however (VS 2013) throws a Linker error:
LINK : fatal error LNK1104: cannot open file 'flac.lib' [C:\ProgramData\Jenkins\jobs\Project Onyx - Win - CMake - Release\workspace\build\Project-Onyx.vcxproj]

As far as I know, you don't have to link the SFML dependencies when linking SFML dynamically. Why do we still get this error?
« Last Edit: July 30, 2015, 10:16:27 am by Nimelrian »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Linker misses flac.lib when linking SFML dynamically
« Reply #1 on: July 30, 2015, 10:28:00 am »
Is it a clean CMake build, or did you previously link SFML statically? In this case, you'll have to clear the CMake cache.
Laurent Gomila - SFML developer

Nimelrian

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Linker misses flac.lib when linking SFML dynamically
« Reply #2 on: July 30, 2015, 11:12:24 am »
It's a completely clean CMake build. Error still happens when I do a clean clone of the git repo.

Edit: And we didn't link it statically before :)
« Last Edit: July 30, 2015, 11:15:52 am by Nimelrian »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Linker misses flac.lib when linking SFML dynamically
« Reply #3 on: July 30, 2015, 11:27:49 am »
Unless you link statically or built SFML in a strange manner, flac.lib is not needed to build your application.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nimelrian

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Linker misses flac.lib when linking SFML dynamically
« Reply #4 on: July 30, 2015, 11:42:51 am »
Found the cause, we still had a #pragma comment(lib, "flac.lib") in our code :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Linker misses flac.lib when linking SFML dynamically
« Reply #5 on: July 30, 2015, 11:49:21 am »
And that ladies and gentlemen is another example why you never use #pragma comment to link libraries, it's not the source code's task to link libraries.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/