'Cmake target_link_libraries producing multiple linking problems

I porting a big qmake project to cmake and I have multiple linking problems, LNK2001, LNK2019 like:

foo.cpp.obj : error LNK2001: unresolved external symbol "public: signed char __cdecl libA::XXX::YYY(void)const " (?YYY@XXX@libA@@QEBACXZ)

foo.cpp.obj : error LNK2019: unresolved external symbol "public: unsigned short __cdecl libA::XXX::YYY(void)const " (?YYY@XXX@libA@@QEBAGXZ) referenced in function "void __cdecl libA::ZZZZ(class LibA::WWWW &)" (?ZZZZ@libA@@YAXAEAVVVVV@1@@Z)

I think that the main problem is that I have libraries that are used in the main project as well in other libraries. But I don't discard the fact that in target_include_directories I'm adding a folder with the same name.

Example of my structure:

Project (Main):

find_package(Qt5 COMPONENTS core REQUIRED)
add_executable(main...
target_include_directories(main...
target_link_libraries(main PUBLIC
    Qt5::Core
    libA
    libB
)

Project (LibA):

find_package(Qt5 COMPONENTS core REQUIRED)
add_library(libA...
target_include_directories(libA PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(main PUBLIC
    Qt5::Core
    libB
    libC
)

Project (LibB):

find_package(Qt5 COMPONENTS core REQUIRED)
add_library(libB...
target_include_directories(libB PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(libB PUBLIC
    Qt5::Core
    libA
)

Project (LibC):

find_package(Qt5 COMPONENTS core REQUIRED)
add_library(libC...
target_include_directories(libC PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(libC PUBLIC
    Qt5::Core
    libA
    libB
)

I'm missing something or doing something not properly??



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source