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

Author Topic: Upgrading SFML and Cmake  (Read 2573 times)

0 Members and 1 Guest are viewing this topic.

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Upgrading SFML and Cmake
« on: April 13, 2017, 07:20:33 pm »
Hi folks.  Since y'all suggested I upgrade SFML, I am trying to do that.

Here's my problem, and I've already found a few posts about it but they aren't solving my issues.
I downloaded SFML 2.4.2, GCC 6.1.0 MinGW (DW2) - 32-bit (I'm using codeblocks)

In my cmake files (I have two projects, one is a library I created and one is my game), I changed:
find_package(SFML REQUIRED COMPONENTS audio network graphics window system)
to
find_package(SFML 2.4 REQUIRED COMPONENTS audio network graphics window system)

Cmake did not complain a bit about either change, said it had successfully found 2.4.2, and everyone was happy.  I made sure too, that the SFML include directory was correct, and that the correct .dll files were listed.

When I compiled my library, everything went fine.
When I compiled my game, I got warnings that sf::Text.setColor() was deprecated, which seemed to me to indicate that the linking had worked.

Then, I got 40 undefined references.

I have tried everything I could find by googling, and haven't had success.  Here are my cmake files:
JollyLava (my library)

project(JollyLava CXX)
cmake_minimum_required( VERSION 2.6 )

# Set version information in a config.h file
set(myproject_VERSION_MAJOR 0)
set(myproject_VERSION_MINOR 1)

# Name of this library.
set(LIBRARY_NAME "JollyLava")

#
# --- Our CMake settings
#
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" ${CMAKE_MODULE_PATH})

# Place libraries in the root BUILD directory.
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) # static
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) # dynamic

#
# --- Dependencies
#

# SFML
find_package(SFML 2.4 REQUIRED system window graphics network audio)
include_directories("${SFML_INCLUDE_DIR}")

# Box2D
find_package(Box2D REQUIRED)
include_directories("${BOX2D_INCLUDE_DIR}")

# Include headers.
include_directories(${CMAKE_SOURCE_DIR}/include)

# C++ source code.
add_subdirectory(src)

#
# --- Install
#
install(DIRECTORY include DESTINATION lib)
 

and JollyZorbit (my game)
project(JollyZorbit CXX)

cmake_minimum_required(VERSION 2.6)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" ${CMAKE_MODULE_PATH})

#set(EXECUTABLE_NAME "JollyZorbit")
#add_executable(${EXECUTABLE_NAME} main.cpp)

find_package(JollyLava REQUIRED)
include_directories("${JOLLYLAVA_INCLUDE_DIR}")

find_package(SFML 2.4 REQUIRED audio network graphics window system)
include_directories("${SFML_INCLUDE_DIR}")
# Note - if I enable the following line I get the error "Cannot specify link libraries
# for target "debug" which is not built by this project"
#target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})


find_package(Box2D REQUIRED)
#set(BOX2D_LIBRARY C:/Box2D_v2.2.1/build/Box2D/libBox2D.a)
#set(BOX2D_INCLUDE_DIR C:/Box2D_v2.2.1/)
include_directories("${BOX2D_INCLUDE_DIR}")

find_package(Steamworks REQUIRED)
include_directories(${STEAMWORKS_INCLUDE_DIR})

# Include headers.
include_directories(${CMAKE_SOURCE_DIR}/include)

# C++ source code.
add_subdirectory(src)

#set_property(TARGET JollyZorbit PROPERTY WIN32_EXECUTABLE true)

Does anyone have any thoughts on what is wrong?  I am obviously quite a CMake newb, so please don't assume I know anything about what I'm doing.

Edit:  Here's a little extra info:
http://imgur.com/a/o5kpe
« Last Edit: April 13, 2017, 07:37:40 pm by gws923 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10835
    • View Profile
    • development blog
    • Email
Re: Upgrading SFML and Cmake
« Reply #1 on: April 13, 2017, 11:01:16 pm »
Then, I got 40 undefined references.
You've left out the most important information. Errors don't just happen to annoy the developer (if that was the goal then everything would fail silently), but it's to inform the developer what went wrong.
So in order to figure out what did go wrong, you need to start by analyzing the error messages. They'll tell you want symbols weren't found and then you can start from there to see why it wasn't linked.
Be it, wrong linking order, wrong architecture, wrong static/shared library type, wrong library exporting, etc. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Re: Upgrading SFML and Cmake
« Reply #2 on: April 13, 2017, 11:06:03 pm »
Thanks, exploiter.  The error messages I got were along these lines:

undefined reference to `_imp___zn2sf6stringc1erkssrkst6locale'|
and a similar one regarding Texture::loadFromFile().

Those error messages are long gone at this point because I have made such a mess of the whole thing -_-

When I asked cmake to tell me the state of SFML_LIBRARIES, however, it did list all the .dll files as being linked.

I'll see if I can reproduce the error, but does your reply mean you don't have any hunch at all based on the information I gave you?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10835
    • View Profile
    • development blog
    • Email
Re: Upgrading SFML and Cmake
« Reply #3 on: April 13, 2017, 11:17:33 pm »
I'll see if I can reproduce the error, but does your reply mean you don't have any hunch at all based on the information I gave you?
No, it just means that I didn't bother really looking at the rest, because it's pointless to chase a ghost when the cause can be determined more easily by looking at the error message. ;)

undefined reference to `_imp___zn2sf6stringc1erkssrkst6locale'|
and a similar one regarding Texture::loadFromFile().
Linker errors with std::string/sf::String is generally an indication that you have mismatching runtime versions.
You mentioned that you got "SFML 2.4.2, GCC 6.1.0 MinGW (DW2) - 32-bit" and that you're using Code::Blocks, you didn't mention that you changed anything about your compiler, so can I assume, that you didn't update your compiler to match the one that was used to build said SFML package?

Quote from: Download Page
The compiler versions have to match 100%! Here are links to the specific MinGW compiler versions used to build the provided packages:
If you use the compiler that gets shipped with Code::Blocks, you'll have to use the package for the TDM compiler. But keep in mind, that if you haven't updated Code::Blocks to the latest version, then the provided SFML packages won't match with your compiler version either.

Easiest solution: Just build SFML from source with the compiler you have right now and you don't have to care about compiler version mismatches. ;)

And finally, don't forget to rebuild your library either, if you update the compiler (or SFML).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Re: Upgrading SFML and Cmake
« Reply #4 on: April 13, 2017, 11:20:23 pm »
Ok, cool.  Right now I am just trying to revert my project back to 2.0 and get it compiling, which unfortunately is not going well.  But, should I succeed at that, I will start over and compile SFML myself.

Thank you for the help, and sorry it took me so long to provide the relevant information ;)

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Re: Upgrading SFML and Cmake
« Reply #5 on: April 14, 2017, 02:36:48 am »
Ok.  I was able to upgrade.

My problems stemmed from downloading the SFML binaries instead of compiling SFML myself.  I'm using a rather old version of code::blocks, so I'm not really sure why I was surprised to encounter compiler discrepancies between my files and SFML.  In any case, once I did all the stupid things I did to my own project, I compiled SFML myself and was upgraded in seconds.  Glad to know that I didn't have to change a single line of code to make mine compatible with 2.4.2.

Thanks for your help, everyone.