[CMake] Linker error with sub project's static libs

Olaf Peter ope-devel at gmx.de
Thu Aug 21 07:29:52 EDT 2014


no idea here? It's seems to be a C++ problem, but how to solve it. 
Changing the order of

  target_link_libraries(eea
       eea_ui_schematic_lib
       eea_ui_lib

to

  target_link_libraries(eea
       eea_ui_lib
       eea_ui_schematic_lib

makes it even worser - more unresolved symbols. So what happens here?

> for my project I have the following structure in my project directory:
>
> ./CMakeLists.txt
> ./source/CMakeLists.txt
> ./source/eea/CMakeLists.txt
> ./source/eea/ui/CMakeLists.txt
> ./source/eea/ui/schematic/CMakeLists.txt
>
> with
> ---8<---
> ./CMakeLists.txt:
> project(eea)
> ...
>
> ---8<---
> ./source/CMakeLists.txt:
> add_subdirectory(eea)
> ...
>
> ---8<---
> ./source/eea/CMakeLists.txt
> add_executable(eea ...)
>
> target_link_libraries(eea
>      eea_ui_schematic_lib
>      eea_ui_lib
>      ...
> )
>
> qt5_use_modules(eea Widgets ...)
>
> add_subdirectory(ui)
> ...
>
> ---8<---
> ./source/eea/ui/CMakeLists.txt
> project(eea_ui)
> ...
> set(eea_ui_SOURCE mainwindow_private.cpp graphics_view.cpp...)
> add_library(eea_ui_lib STATIC
>      ${eea_ui_SOURCE}
>      ...
> )
>
> qt5_use_modules(eea_ui_lib Widgets ...)
>
> add_subdirectory(schematic)
> ...
> ---8<---
> ./source/eea/ui/schematic/CMakeLists.txt:
> project(eea_ui_schematic)
> ...
> set(eea_ui_schematic_SOURCE schematics_view.cpp ...)
> add_library(eea_ui_schematic_lib STATIC
>      ${eea_ui_schematic_SOURCE}
>      ...
> )
>
> qt5_use_modules(eea_ui_schematic_lib Widgets ...)
>
> So far, so good - all compiles.
>
>
>
> With
> ---8<---
> ./source/eea/ui/mainwindow_private.cpp :
> ...
> createWindows() {
>      SchematicView* schematicView = new SchematicView(q);
>      ...
> }
>
> ---8<---
> ./source/eea/ui/graphics_view.cpp:
> GraphicsView::GraphicsView(QWidget* parent) { ...  }
>
> ---8<---
> ./source/eea/ui/schematic/schematic_view.cpp
> class SchematicView
> : public GraphicsView
> { .... }
>
>
> I got the linker error:
>
> ../../lib/libeea_ui_lib.a(mainwindow_private.cpp.o): In function
> `eea::ui::MainWindowPrivate::createWindows()':
> mainwindow_private.cpp:(.text+0xbb): warning: undefined reference to
> `eea::ui::SchematicView::SchematicView(QWidget*)'
>
> So, what happened here and how to solve it? Before the contents of
> ui/schematic moved into the ui directory/project and I've got no errors.
>
> Thanks,
> Olaf



More information about the CMake mailing list