# target\_link\_libraries doesn't link sfml libraries

**URL:** <https://discourse.cmake.org/t/target-link-libraries-doesnt-link-sfml-libraries/14060>\
**Category:** Code\
**Created:** [May 8, 2025, 11:14am UTC](https://discourse.cmake.org/t/target-link-libraries-doesnt-link-sfml-libraries/14060 "2025-05-08T11:14:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laurent7601](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/a5b964/32.png) [@Laurent7601](https://discourse.cmake.org/u/Laurent7601)\
**Post date:** [May 8, 2025, 11:14am UTC](https://discourse.cmake.org/t/target-link-libraries-doesnt-link-sfml-libraries/14060/1 "2025-05-08T11:14:03Z")

</div>

Hi!  
I’m trying to compile a lib using SFML, so I put this SFML code :

```auto
include(${PROJECT_SOURCE_DIR}/cmake/Macros.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/Modules/FindSFML.cmake)
set(INCROOT ${PROJECT_SOURCE_DIR}/include/odfaeg/Core)
set(SRCROOT ${PROJECT_SOURCE_DIR}/src/odfaeg/Core)
set(SRC    
	${INCROOT}/archive.h
	${SRCROOT}/archive.cpp
	${INCROOT}/serialization.h
	${INCROOT}/entityFactory.hpp
	${INCROOT}/ecs.hpp
	${INCROOT}/erreur.h
	${INCROOT}/export.hpp
	${SRCROOT}/erreur.cpp	
	${INCROOT}/resourceManager.h		
	${INCROOT}/any.h
	${INCROOT}/resourceCache.h
	${INCROOT}/utilities.h
	${SRCROOT}/utilities.cpp	
	${INCROOT}/factory.h
	${INCROOT}/factory.cpp
	${INCROOT}/entitySystem.h
	${INCROOT}/timer.h		
	${INCROOT}/state.h
	${SRCROOT}/state.cpp
	${INCROOT}/stateGroup.h
	${SRCROOT}/stateGroup.cpp
	${INCROOT}/stateStack.h
	${SRCROOT}/stateStack.cpp
	${INCROOT}/stateParameter.h
	${INCROOT}/stateParameterBase.h
	${INCROOT}/stateExecutor.h		
	${INCROOT}/archive.h	
	${INCROOT}/time.h
	${SRCROOT}/time.cpp
	${INCROOT}/clock.h
	${SRCROOT}/clock.cpp
	${INCROOT}/variant.h
	${INCROOT}/class.hpp
	${SRCROOT}/class.cpp
	${INCROOT}/constructor.hpp
	${SRCROOT}/constructor.cpp
	${INCROOT}/memberFunction.hpp
	${SRCROOT}/memberFunction.cpp
	${INCROOT}/runtimeCompiler.hpp
	${SRCROOT}/runtimeCompiler.cpp
	${INCROOT}/fastDelegate.h
	${INCROOT}/ecs.hpp	
	)	

include_directories(${CMAKE_INCLUDE_PATH})
link_directories(${CMAKE_LIBRARY_PATH})

find_package(SFML 2 REQUIRED audio network graphics window system)

sfgl_add_library(odfaeg-core
                 SOURCES ${SRC})
target_link_libraries (odfaeg-core ${SFML_LIBRARIES})

```

odfaeg-core is linked but cmake dosn’t link SFML\_LIBRARIES.

```auto
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\odfaeg-math.dir/objects.a(distribution.cpp.obj): in function `operator()':
C:/Users/Laurent et Christian/ODFAEG-master/ODFAEG/src/odfaeg/Math/distribution.cpp:77:(.text+0xd2): undefined reference to ` __imp__ ZN2sf7secondsEf'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\odfaeg-math.dir/objects.a(distribution.cpp.obj): in function `odfaeg::math::Distributions::uniform(sf::Time, sf::Time)':
C:/Users/Laurent et Christian/ODFAEG-master/ODFAEG/src/odfaeg/Math/distribution.cpp:70:(.text+0x103): undefined reference to ` __imp__ ZN2sfleENS_4TimeES0_'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Laurent et Christian/ODFAEG-master/ODFAEG/src/odfaeg/Math/distribution.cpp:72:(.text+0x13a): undefined reference to ` __imp__ ZNK2sf4Time9asSecondsEv'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Laurent et Christian/ODFAEG-master/ODFAEG/src/odfaeg/Math/distribution.cpp:73:(.text+0x151): undefined reference to ` __imp__ ZNK2sf4Time9asSecondsEv'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\odfaeg-math.dir/objects.a(distribution.cpp.obj): in function `operator()':
C:/Users/Laurent et Christian/ODFAEG-master/ODFAEG/src/odfaeg/Math/distribution.cpp:120:(.text+0x6bc): undefined reference to ` __imp__ ZN2sf5ColorC1Ev'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [src\odfaeg\Math\CMakeFiles\odfaeg-math.dir\build.make:273: lib/libodfaeg-math-d.dll] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:317: src/odfaeg/Math/CMakeFiles/odfaeg-math.dir/all] Error 2
mingw32-make: *** [makefile:135: all] Error 2

```

I get this errors when I want to build my lib in shared mode.

Thanks.

---

<div class="post-metadata">

**Author:** ![Laurent7601](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/a5b964/32.png) [@Laurent7601](https://discourse.cmake.org/u/Laurent7601)\
**Post date:** [May 9, 2025, 11:36am UTC](https://discourse.cmake.org/t/target-link-libraries-doesnt-link-sfml-libraries/14060/2 "2025-05-09T11:36:18Z")

</div>

Ok it was in my cmake file the problem, I referenced sfml twice, with find package and with the path to my dependencies dir.  
Solved.
