Re: [CMake] Linker error with sub project's static libs
Hello Leif, Are your libraries mutually dependent? You may be hitting the mutually-dependent static library problem. Look for the word mutual near the end of http://www.cmake.org/cmake/help/v3.0/command/target_link_libraries.html, that section explains some of what is going on. yes it is mutually, ui_lib creates a SchematicView, which is derived from GraphicView. SchematicView's instance is in ui_schematic_lib, where GraphicsView is in ui_lib. Probably I should stay the files inside these directory and add them to the source in ui_lib project as the docs suggested. Thanks, 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. thank you a lot, this solves the linker problem - I have to add these twice, reference to the other lib each time. Furthermore, I think the order of add_subdirectory(), add_library(), and target_link_libraries() is important. You might want to check those as well. The order matches of course, but I haven't never such linker problems. The first time I'm using target_link_lib for a library self. The reason is not clear for me. What happens under the hood here? Thanks, Olaf -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/ opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Linker error with sub project's static libs
Hi Olaf, See my reply below inline. On 21/08/14 20:19, Olaf Peter wrote: Hello Marcel, 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. thank you a lot, this solves the linker problem - I have to add these twice, reference to the other lib each time. Furthermore, I think the order of add_subdirectory(), add_library(), and target_link_libraries() is important. You might want to check those as well. The order matches of course, but I haven't never such linker problems. The first time I'm using target_link_lib for a library self. The reason is not clear for me. What happens under the hood here? Libraries can depend on one another. If code that produces libB uses functions that are implemented in code that produces libA, then libB depends on libA. When creating static libraries this doesn't make much of a difference; after all a static library is just a bunch of object files. However, when creating shared libraries it does. Shared library libB will record internally that it depends on libA; something a static library cannot do. Suppose you're linking a main program that only uses functions defined in libB. When using shared libraries, you only need to link your main program against libB; remember, libB has recorded internally that it depends on libA. However, when using static libraries you need to link against libB and libA, even though your main program doesn't use any functions in libA. CMake to the rescue! The only thing you have to tell CMake is that libB depends on libA, using target_link_libraries(B A). CMake will then make sure that the correct libraries on put on the link line in the correct order. There's only one exception: circular dependencies. In that case you may need to help CMake a bit. IMHO you should try very hard to avoid circular library dependencies; they are a real PITA. Thanks, Olaf Cheers, Marcel Loose. attachment: loose.vcf-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Linker error with sub project's static libs
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 -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Linker error with sub project's static libs
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 attachment: loose.vcf-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Linker error with sub project's static libs
Hello Marcel, 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. thank you a lot, this solves the linker problem - I have to add these twice, reference to the other lib each time. Furthermore, I think the order of add_subdirectory(), add_library(), and target_link_libraries() is important. You might want to check those as well. The order matches of course, but I haven't never such linker problems. The first time I'm using target_link_lib for a library self. The reason is not clear for me. What happens under the hood here? Thanks, Olaf -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Linker error with sub project's static libs
Are your libraries mutually dependent? You may be hitting the mutually-dependent static library problem. Look for the word mutual near the end of http://www.cmake.org/cmake/help/v3.0/command/target_link_libraries.html, that section explains some of what is going on. On Thu, Aug 21, 2014 at 2:19 PM, Olaf Peter ope-de...@gmx.de wrote: Hello Marcel, 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. thank you a lot, this solves the linker problem - I have to add these twice, reference to the other lib each time. Furthermore, I think the order of add_subdirectory(), add_library(), and target_link_libraries() is important. You might want to check those as well. The order matches of course, but I haven't never such linker problems. The first time I'm using target_link_lib for a library self. The reason is not clear for me. What happens under the hood here? Thanks, Olaf -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/ opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake -- Cheers, Leif -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
[CMake] Linker error with sub project's static libs
Hello, 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 -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake