J0chem

Hi. I have recently being implementing my game engine in C++ with SFML and CMake (alongside my LibGDX project, so I can compare the two and decide what I prefer in the end). Could anyone tell me what I am doing wrong? Everything works, except for the Spine tests. Pretty sure that I am doing the linking wrong. I have tried a lot of different things, but nothing seems to work.

This is my CMakeLists.txt:
cmake_minimum_required (VERSION 2.6)
project (Plutonium)

set(CMAKE_CXX_STANDARD 11)

set(INCLUDE_DIR include)
set(SOURCE_DIR src)
set(TESTS_DIR tests)
set(BIN_DIR bin)
set(BUILD_DIR build)
set(SPINE_DIR externals)

# Spine
set(SPINE_SFML TRUE)
include_directories(${SPINE_DIR}/spine-c/spine-c/src)
include_directories(${SPINE_DIR}/spine-c/spine-c/include)
include_directories(${SPINE_DIR}/spine-sfml/src)
file(GLOB SPINE_C_INCLUDES "externals/spine-c/spine-c/include/spine/*.h")
file(GLOB SPINE_C_SOURCES "externals/spine-c/spine-c/src/spine/*.cpp")
file(GLOB SPINE_SFML_INCLUDES "externals/spine-sfml/src/spine/*.h")
file(GLOB SPINE_SFML_SOURCES "externals/spine-sfml/src/spine/*.cpp")

include_directories(${INCLUDE_DIR})
include_directories(${SOURCE_DIR})
include_directories(${TESTS_DIR})

set(SOURCES
${INCLUDE_DIR}/Plutonium/Entity.hpp
${INCLUDE_DIR}/Plutonium/Event.hpp
${INCLUDE_DIR}/Plutonium/Component.hpp
${INCLUDE_DIR}/Plutonium/TypeID.hpp
${INCLUDE_DIR}/Plutonium/TimeDelta.hpp
${INCLUDE_DIR}/Plutonium/System.hpp
${INCLUDE_DIR}/Plutonium/World.hpp
${INCLUDE_DIR}/Plutonium/SpineAdapter.hpp
${INCLUDE_DIR}/Plutonium/Component/Animation.hpp

${SOURCE_DIR}/Plutonium/Component.cpp
${SOURCE_DIR}/Plutonium/Entity.cpp
${SOURCE_DIR}/Plutonium/Event.cpp
${SOURCE_DIR}/Plutonium/World.cpp
${SOURCE_DIR}/Plutonium/SpineAdapter.cpp
${SOURCE_DIR}/Plutonium/Component/Animation.cpp
)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(CMAKE_INCLUDE_PATH ${INCLUDE_DIR}:${SPINE_SFML_INCLUDES})

add_library(spine STATIC ${SPINE_SFML_INCLUDES} ${SPINE_SFML_SOURCES})

add_library(Plutonium STATIC ${SOURCES})
target_link_libraries(Plutonium sfml-audio)
target_link_libraries(Plutonium sfml-graphics)
target_link_libraries(Plutonium sfml-window)
target_link_libraries(Plutonium sfml-system)
target_link_libraries(Plutonium spine)

# Tests
add_executable(plutonium-test-basic ${TESTS_DIR}/BasicTest.cpp)
target_link_libraries(plutonium-test-basic Plutonium)
add_executable(plutonium-test-world ${TESTS_DIR}/WorldTest.cpp)
target_link_libraries(plutonium-test-world Plutonium)
add_executable(plutonium-test-sfml ${TESTS_DIR}/SFMLTest.cpp)
target_link_libraries(plutonium-test-sfml Plutonium)
add_executable(plutonium-test-spine ${TESTS_DIR}/SpineTest.cpp)
target_link_libraries(plutonium-test-spine Plutonium)
I am calling cmake .. from plutonium/build, followed by make. The spine-c and spine-sfml folders are located in plutonium/externals/spine-c and plutonium/externals/spine-sfml.

This is the output:
[jochem@localhost build]$ make
[ 11%] Built target spine
[ 52%] Built target Plutonium
[ 58%] Linking CXX executable bin/plutonium-test-spine
build/libPlutonium.a(SpineAdapter.cpp.o): In function `plutonium::SpineAdapter::loadSkeletonData(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
SpineAdapter.cpp:(.text+0x14a): undefined reference to `spSkeletonJson_create'

SpineAdapter.cpp:(.text+0x16f): undefined reference to `spSkeletonJson_readSkeletonDataFile'
build/libPlutonium.a(SpineAdapter.cpp.o): In function `plutonium::SpineAdapter::loadAtlas(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
:
SpineAdapter.cpp:(.text+0x33c): undefined reference to `spAtlas_createFromFile'
build/libPlutonium.a(SpineAdapter.cpp.o): In function `plutonium::SpineAdapter::loadAnimationStateData(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
:
SpineAdapter.cpp:(.text+0x425): undefined reference to `spAnimationStateData_create'
build/libPlutonium.a(SpineAdapter.cpp.o): In function `plutonium::SpineAdapter::createAnimationState(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
:
SpineAdapter.cpp:(.text+0x495): undefined reference to `spAnimationState_create'
build/libPlutonium.a(SpineAdapter.cpp.o): In function `plutonium::SpineAdapter::createSkeleton(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
:
SpineAdapter.cpp:(.text+0x505): undefined reference to `spSkeleton_create'
collect2: error: ld returned 1 exit status
CMakeFiles/plutonium-test-spine.dir/build.make:96: recipe for target '
bin/plutonium-test-spine' failed
make[2]: *** [bin/plutonium-test-spine] Error 1
CMakeFiles/Makefile2:105: recipe for target '
CMakeFiles/plutonium-test-spine.dir/all' failed
make[1]: *** [CMakeFiles/plutonium-test-spine.dir/all] Error 2
Makefile:83: recipe for target '
all' failed


---

P.S. If necessary, I can give you access to the complete source code. However, I feel that the information currently provided is already enough. The SpineAdapter class I have written is not very interesting. It is mostly a wrapper with a cache and some utility functions. And indeed, it calls
#include <spine/spine-sfml.h>
J0chem
Posts: 17

badlogic

Without having dug to deep, my guess is you also need to add the spine-c sources here
add_library(spine STATIC ${SPINE_SFML_INCLUDES} ${SPINE_SFML_SOURCES})
User avatar
badlogic

Mario
Posts: 1084

J0chem

Thanks for your reply, but the problem persists after that. :(

The same problem to be precise.

---

Never mind. I figured it out. It turns out that I made a silly mistake.

I accidentally did
file(GLOB SPINE_C_SOURCES "${SPINE_C_SOURCE_DIR}/spine/*.cpp")
instead of
file(GLOB SPINE_C_SOURCES "${SPINE_C_SOURCE_DIR}/spine/*.c")
When the spine-c sources are regular c files, not cpp! Ugh. I feel so stupid, but I am happy I fixed it.

Thanks for your time anyway.
J0chem
Posts: 17

badlogic

Hah, no worries. CMake usually drives me crazy, but it's the best we have in C/C++ land for now. Glad you figured it out!
User avatar
badlogic

Mario
Posts: 1084


Return to Runtimes