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

Author Topic: Unresolved External Symbol in VS17 using CMAKE  (Read 1918 times)

0 Members and 1 Guest are viewing this topic.

sihan416

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Unresolved External Symbol in VS17 using CMAKE
« on: February 23, 2017, 05:25:52 am »
So I looked up almost all the posts about this error, however I still can't quite figure it out. I do not know CMAKE very well, but need to salvage a project by someone else quite a while back. Now I understand how to link properly (including statically, which is what I am trying to do now) through the project properties. However, this is cmake so I don't actually know what the problem is. Since I was familiar with VS, I decided to try to do this using the new cmake component in VS17. Currently I believe I'm having one of two issues, but I'm having difficulties pinning it down. It is either my compiled SFML libraries for VS17 isn't correct, or my CMakeLists.txt isn't correct. Would someone mind look at my CMakeLists to see if there's any problems with it?
cmake_minimum_required(VERSION 2.6)
project(sync)

# Enable debug symbols by default
if(CMAKE_BUILD_TYPE STREQUAL "")
  set(CMAKE_BUILD_TYPE Debug)
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
    SET(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Werror ${CMAKE_CXX_FLAGS}")
else()
    set(CMAKE_CXX_FLAGS "-std=c++11 -Wall ${CMAKE_CXX_FLAGS}")
endif()
# (you can also set it on the command line: -D CMAKE_BUILD_TYPE=Release)

# Set version information in a config.h file
set(sync_VERSION_MAJOR 0)
set(sync_VERSION_MINOR 1)
set(sync_VERSION_PATCH 0)
#configure_file(
#  "${PROJECT_SOURCE_DIR}/src/config.h.in"
#  "${PROJECT_BINARY_DIR}/config/config.h"
#)
include_directories("${PROJECT_BINARY_DIR}/config")

# Define sources and executable
set(CLIENT_EXE_NAME "sync")
set(SERVER_EXE_NAME "sync-server")
add_executable(${SERVER_EXE_NAME}
    src/server-main.cpp
)
add_executable(${CLIENT_EXE_NAME}
    src/client-main.cpp
)
#add_custom_command(TARGET JackOfClubs
#                   COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/data
#                                                              ${PROJECT_BINARY_DIR}/data
#)

# Detect and add SFML
set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_ROOT "D:/School/Research/SFML-2.4.2/")

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2 COMPONENTS system network REQUIRED)
if(SFML_FOUND)
  include_directories(${SFML_INCLUDE_DIR})
  target_link_libraries(${SERVER_EXE_NAME} ${SFML_LIBRARIES})
  target_link_libraries(${CLIENT_EXE_NAME} ${SFML_LIBRARIES})
endif()
#target_link_libraries(
#    ${SERVER_EXE_NAME}
#    GL
#    GLU
#    GLEW
#)

# Install target
install(TARGETS ${SERVER_EXE_NAME} DESTINATION bin)
install(TARGETS ${CLIENT_EXE_NAME} DESTINATION bin)

# CPack packaging
#include(InstallRequiredSystemLibraries)
#set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
#set(CPACK_PACKAGE_VERSION_MAJOR "${JackOfClubs_VERSION_MAJOR}")
#set(CPACK_PACKAGE_VERSION_MINOR "${JackOfClubs_VERSION_MINOR}")
#include(CPack)

 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Unresolved External Symbol in VS17 using CMAKE
« Reply #1 on: February 23, 2017, 08:49:57 am »
Since VS17 hasn't been officially released, there's no guarantee that SFML will work with it.

Since you didn't actually provide the linker errors, it's impossible for us to say what the issue is.
However, when statically linking SFML you also need to link SFML's dependencies. So you have to add ${SFML_DEPENDENCIES} after the ${SFML_LIBRARIES} in target_link_libraries.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything