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

Author Topic: Cmake build issues: linker cannot find -loptimized and -ldebug  (Read 1971 times)

0 Members and 1 Guest are viewing this topic.

Kraken

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
I have been attempting to build SFML with cmake for integration with my own cmake build system to ensure that it works with any compiler for cross platform development. After messing around with different configurations, I have found a strange problem that I cannot find any solution to.

I am on windows 11, working with MSVC 2019 and Mingw32. To ensure that I am not the source of this error, I am using a fresh clone of https://github.com/SFML/cmake-sfml-project/. Configuring and compiling works fine for both systems, but when linking, I get the same error:

This is the MSVC 2019 error:
LINK : fatal error LNK1104: cannot open file 'optimized.lib'

and this is the Mingw32 error:
x86_64-w64-mingw32/bin/ld.exe: cannot find -loptimized: No such file or directory
x86_64-w64-mingw32/bin/ld.exe: cannot find -ldebug: No such file or directory

I don't think that there is an actual library named debug or optimized that is missing, instead some configuration is messed up somehow.
After some research, the only issue I could find this could be connected to is a way of specifying debug and release linking:

target_link_libraries(${PROJECT_NAME}
    optimized mylib-release
    debug mylib-debug
)

But after some digging, neither the template cmakeLists.txt nor the SFML build cmakeLists.txt includes anything in this format. I'm at a loss for what to do here.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Cmake build issues: linker cannot find -loptimized and -ldebug
« Reply #1 on: April 10, 2024, 08:29:58 am »
"optimized" and "debug" have to be provided as link targets from somewhere, might just be cached.

Make sure to clean your build directory and do a clean CMake configure again.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Kraken

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Cmake build issues: linker cannot find -loptimized and -ldebug
« Reply #2 on: April 10, 2024, 07:45:10 pm »
After some experimentation, a clean make only works sometimes. I can find no consistent reason, but this error continues to appear. Sometimes after a successful build I will rebuild and it will break again. I think this might have something to do with Vscode's default cmake commands.

iphelf

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Cmake build issues: linker cannot find -loptimized and -ldebug
« Reply #3 on: June 12, 2024, 04:32:42 am »
I solved the issue by updating the library target name for Freetype (replacing "Freetype" with "Freetype::Freetype") in CMakeLists.txt of Graphics module, just like https://github.com/SFML/SFML/blob/304a7c1d69e440f419f569a4a3c83690f9b33e22/src/SFML/Graphics/CMakeLists.txt#L120.

 

anything