[CMake] Linker error with sub project's static libs
Marcel Loose
loose at astron.nl
Thu Aug 21 08:31:23 EDT 2014
Olaf,
Unless your code snippets are incomplete, I'm missing the following
statement in ./source/eea/ui/CMakeLists.txt
target_link_libraries(eea_ui_lib
eea_ui_schematic_lib)
I'm not sure this is causing the link error, but it's worth a try.
Furthermore, I think the order of add_subdirectory(), add_library(), and
target_link_libraries() is important. You might want to check those as well.
Cheers,
Marcel Loose.
On 21/08/14 13:29, Olaf Peter wrote:
> 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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: loose.vcf
Type: text/x-vcard
Size: 292 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140821/3122786b/attachment.vcf>
More information about the CMake
mailing list