Qt 5 cmake fails with undefined reference to vtable on hello world with inc & src as subdirs

后端 未结 3 1790
青春惊慌失措
青春惊慌失措 2021-01-04 05:29

Update 2

After messing around a bit (and some editing of the generated Makefiles), it looks like what is happening is that moc is not properly processing Mai

3条回答
  •  执笔经年
    2021-01-04 06:30

    Well, maybe automoc does not work for you, I would guess it's because CMake does not find the corresponding files. Check the documentation here: http://www.cmake.org/cmake/help/v2.8.12/cmake.html#prop_tgt:AUTOMOC

    In this case, you can always call the moc command manually for them in your CMakeLists.txt:

    qt5_wrap_cpp(moc_sources src/MainWindow.cpp)
    qt5_wrap_ui(uic_sources src/MainWindow.cpp)
    
    list(APPEND library_sources ${moc_sources} ${uic_sources})
    

    Note: you have to make sure you use the list command correctly yourself. This code example is from my project where I use a specific list of sources (library_sources).

    It is just a guess but you should try without the automagic first to rule out one possible source of error.

    Also make sure that you fully deleted the CMake cache after changing your directory structure.

提交回复
热议问题