0
votes

I'll describe how my CMake project is currently arranged. It's early, so suggestions for a better arrangement are welcome.

App depends on Lib1 Lib1 depends on Lib2 Lib2 uses Qt

folder structure:

  • top-level
    • Lib1
      • Lib2
    • App

I have CMakeLists.txt at each level.

In Lib1 I add_library (STATIC), then target_link_library with Lib2 which is also STATIC.

Lib2's CMakeLists.txt does the find_package calls for Qt5Widgets, Qt5Core, and Qt5Gui.

Finally, App's CMakeLists.txt does the add_executable followed by target_link_libraries for Lib1.

Everything compiles and links until I actually make a call in the App code to use a function in Lib2. Then I get a bunch of unresolved symbol linker errors pointing to functions from Lib2. It doesn't seem to matter if I make Lib2 an OBJECT library and change the linking in Lib1 accordingly. I've also tried linking App against both Lib1 and Lib2 with the same results.

What am I doing wrong here?

1
You need to target_link_libraries on Lib2 with Qt5Widgets, Qt5Core, and Qt5Gui. Find_packages simply populates the variable with the library locations. - mascoj
Thank you! I don't know why I missed that. For others reading, the syntax I used is: target_link_libraries(FrameworkInterfaceLib Qt5::Widgets Qt5::Core Qt5::Gui) - Rich von Lehe
mascoj - If you put your comment into a answer I can credit you. - Rich von Lehe
Btw: qt5_use_modules(FrameworkInterfaceLib Widgets Core Gui) is another way to link Qt libs into your target. - Th. Thielemann

1 Answers

1
votes

Find_packages simply populates the variable with the library locations.

You need to target_link_libraries on Lib2 with Qt5Widgets, Qt5Core, and Qt5Gui so cmake can properly link them.