undefined reference to ... CMake | Не проходит последняя стадия линковки модулей

Недавно начал осваивать CMake. Осознал модульный подход при сборке таргетов.

Пытаюсь собрать модуль (библиотеку) shunting_yard_alg_tests, который имеет следующие зависимости:

shunting_yard_alg_tests
|-- shunting_yard_alg (PUBLIC lib)
    |-- queue (INTERFACE lib)
    |-- stack (INTERFACE lib)
    |-- token (PUBLIC lib)

Во время ее сборки (см. фото): shunting_yard_alg_tests building log | png

На этапе линковки ловлю следующие ошибки:

/usr/bin/ld: CMakeFiles/shunting_yard_alg_tests.dir/__/__/src/shunting_yard_alg/shunting_yard_alg.cpp.o: in function `polish_notation::shunting_yard_alg::tryMakeOperationWithDequeuedToken(polish_notation::token::Token const&, polish_notation::data_structures::queue::Queue<polish_notation::token::Token>&, polish_notation::data_structures::stack::Stack<polish_notation::token::Token>&)':
/path/to/project/src/shunting_yard_alg/shunting_yard_alg.cpp:25: undefined reference to `polish_notation::token::Token::isNumOrX() const'
/usr/bin/ld: /path/to/project/src/shunting_yard_alg/shunting_yard_alg.cpp:31: undefined reference to `polish_notation::token::Token::isFunction() const'
/usr/bin/ld: CMakeFiles/shunting_yard_alg_tests.dir/__/__/src/shunting_yard_alg/shunting_yard_alg.cpp.o: in function `polish_notation::shunting_yard_alg::setFunctionFromStackTopToQueueIfExists(polish_notation::data_structures::stack::Stack<polish_notation::token::Token>&, polish_notation::data_structures::queue::Queue<polish_notation::token::Token>&)':
/path/to/project/src/shunting_yard_alg/shunting_yard_alg.cpp:67: undefined reference to `polish_notation::token::Token::isFunction() const'
collect2: error: ld returned 1 exit status
gmake[3]: *** [tests/shunting_yard_alg/CMakeFiles/shunting_yard_alg_tests.dir/build.make:149: tests/shunting_yard_alg/shunting_yard_alg_tests] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:1659: tests/shunting_yard_alg/CMakeFiles/shunting_yard_alg_tests.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:1666: tests/shunting_yard_alg/CMakeFiles/shunting_yard_alg_tests.dir/rule] Error 2
gmake: *** [Makefile:751: shunting_yard_alg_tests] Error 

Имеется следующая иерархия проекта (некоторые файлы и директории были исключены):

polish_notation
├── CMakeLists.txt
├── include
│   └── polish_notation
│       └── token
|           └── token.h
├── src
│   ├── CMakeLists.txt
│   ├── shunting_yard_alg
│   │   ├── CMakeLists.txt
│   │   ├── shunting_yard_alg.cpp
│   │   └── shunting_yard_alg.h
│   └── token
│       ├── CMakeLists.txt
│       ├── token.cpp
│       └── token_data.cpp
└── tests
    ├── CMakeLists.txt
    └── shunting_yard_alg
        ├── CMakeLists.txt
        └── shunting_yard_alg_tests.cpp

CmakeLists.txt (в корневой директории проекта):

cmake_minimum_required(VERSION 3.5.0)

project(polish_notation LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

enable_testing()

include(CTest)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(tests)

src/CmakeLists.txt:

add_subdirectory(token)
add_subdirectory(parser)
add_subdirectory(shunting_yard_alg)

src/token/CmakeLists.txt:

set(TARGET token)

add_library(${TARGET})

target_sources(${TARGET} PUBLIC
    ${CMAKE_CURRENT_LIST_DIR}/token_data.cpp
    ${CMAKE_CURRENT_LIST_DIR}/token.cpp
)

target_include_directories(${TARGET} PUBLIC
    ${CMAKE_SOURCE_DIR}/include
)

src/shunting_yard_alg/CmakeLists.txt:

set(TARGET shunting_yard_alg)

add_library(${TARGET})

target_sources(${TARGET} PUBLIC
    ${CMAKE_CURRENT_LIST_DIR}/shunting_yard_alg.cpp
)

target_include_directories(${TARGET} PUBLIC
    ${CMAKE_CURRENT_LIST_DIR}
)

target_link_libraries(${TARGET}
    INTERFACE
        queue
        stack
    PUBLIC
        token
)

tests/CmakeLists.txt:

add_subdirectory(data_structures)
add_subdirectory(parser)
add_subdirectory(token)
add_subdirectory(shunting_yard_alg)

tests/shunting_yard_alg/CmakeLists.txt:

set(TARGET shunting_yard_alg_tests)

add_executable(${TARGET})

target_sources(${TARGET} PUBLIC
    ${CMAKE_CURRENT_LIST_DIR}/shunting_yard_alg_tests.cpp
)

target_link_libraries(${TARGET}
    PUBLIC
        gtest_main
        shunting_yard_alg
)

Я уже битый час пытаюсь понять, в чем проблема... Почему src/shunting_yard_alg/shunting_yard_alg.cpp не видит определения методов структуры Token, которые были слинкованы при сборке модуля token?


Ответы (0 шт):