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

Author Topic: undefined references to... On Windows  (Read 2824 times)

0 Members and 1 Guest are viewing this topic.

marmal102

  • Newbie
  • *
  • Posts: 9
    • View Profile
undefined references to... On Windows
« on: April 29, 2017, 10:22:15 am »
Hello everyone,

I have encountered a strange problem recently while trying to configure CLion with SFML on Windows.
I did it many times and it worked perfectly but now I am getting many problems such:

undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'

Whole list of that problems. I know it is the problem with linking but I don't know why.
SFML is detected by CMake, the same version of SFML works in Visual Studio.

FindSFML.cmake is original from SFML package downloaded.

Here is my CMakeLists.txt:

Code: [Select]
cmake_minimum_required(VERSION 3.7)
project(untitled)

set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES main.cpp)
set(SFML_ROOT "D:/Development/SFML-2.4.2")
add_executable(untitled ${SOURCE_FILES})

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
find_package(SFML REQUIRED COMPONENTS audio graphics window system)
if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(untitled ${SFML_LIBRARIES})
endif()


sjaustirni

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
Re: undefined references to... On Windows
« Reply #1 on: April 29, 2017, 10:32:54 am »
EDIT: This is not the cause of the error. See the post by eXpl0it3r.

You're not linking main.

Personally, I use this setup for cross-platform linking
if(MSVC) # Hide console window on Windows
    set_target_properties(${EXECUTABLE_NAME} PROPERTIES  LINK_FLAGS "/SUBSYSTEM:WINDOWS")
    find_package(SFML 2 REQUIRED main system window graphics network audio)
else() # Linux doesn't need the special care
    find_package(SFML 2 REQUIRED system window graphics network audio)
endif(MSVC)

if(SFML_FOUND)
  include_directories(${SFML_INCLUDE_DIR})
  target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()
« Last Edit: April 29, 2017, 12:59:47 pm by sjaustirni »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: undefined references to... On Windows
« Reply #2 on: April 29, 2017, 11:37:25 am »
The CMake script looks fine. So my guess is that your compiler isn't matching your SFML libs.
What's your exact compiler and where did you get SFML from?

You're not linking main.
While that is a true statement, it has nothing to do with the linker error. ;)

Also the recommended way to set the subsystem is to use the follow code:
add_executable(name WIN32 ${SOURCES})
With that code in place the check can be changed from MSVC to Windows as it will also work with MinGW.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

sjaustirni

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
Re: undefined references to... On Windows
« Reply #3 on: April 29, 2017, 01:02:59 pm »
You're right, I have just seen the combo "windows linking failing" and "sfml-main not linked" and assumed the wrong conclusion.

Thanks for the comment about setting the window subsystem. I will implement it once I boot Windows again. I am glad I haven't taken it out as an irrelevant piece of code as you would have not made the comment then :D

marmal102

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: undefined references to... On Windows
« Reply #4 on: April 29, 2017, 01:30:03 pm »
But I wrote I am using CLion with MinGW.
GCC Version is 5.3.0.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: undefined references to... On Windows
« Reply #5 on: April 29, 2017, 07:19:30 pm »
MinGW GCC 5.3.0 can be a lot. There are many different variations of MinGW, thus you need to be more specific. Where did you download said MinGW version?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

marmal102

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: undefined references to... On Windows
« Reply #6 on: April 30, 2017, 11:11:27 am »
I got it from here: http://www.mingw.org/category/wiki/download
Then I downloaded Installer from: https://sourceforge.net/projects/mingw/files/Installer/
And installed gcc compiler from here.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: undefined references to... On Windows
« Reply #7 on: April 30, 2017, 12:35:41 pm »
Then you'll have to build SFML yourself as we don't provide any binaries for that MinGW version. See the links on the download page if you want to get a matching compiler.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

marmal102

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: undefined references to... On Windows
« Reply #8 on: April 30, 2017, 03:40:46 pm »
Yes... I really forgot about matching compiler to downloaded SFML..
Shame on me :) Thanks, works well.