본문 바로가기
IT기술(코딩)/ros2

ros2 error LNK2001: "public: virtual struct QMetaObject const * __cdecl solve. edit cmakelists.

by 크리에이트매이커 2024. 2. 13.
반응형

Hi I'm CreateMaker Inc.

 

We faced error working to make ROS2 Programming.

error LNK2001: "public: virtual struct QMetaObject const * __cdecl...

 

For use UI (Qt5) at cpp. we need to use command

QMetaObject::connectSlotsByName()

this.

 

When we use this we faced error like that.

 

So we edit Cmakelists.

 

first.

set(UI_FILES
    ui/maingui.ui)
    
set(${PROJECT_NAME}_HDRS
  include/${PROJECT_NAME}/station_gui.h
  include/${PROJECT_NAME}/station_wp.h
)
set(${PROJECT_NAME}_RESOURCES
  resources/resource.qrc
)

 

setting locs header files which have qt info.

and locs ui file

and locs resources which .qrc file. (this can be no exist.)

 

And

 

second .

 

setiing moc

 

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

 

third wrap

 


qt5_wrap_cpp(${PROJECT_NAME}_MOCS     ${${PROJECT_NAME}_HDRS})
qt5_add_resources(${PROJECT_NAME}_RCC ${${PROJECT_NAME}_RESOURCES})
qt5_wrap_ui(UI_SRCS ${UI_FILES})

 

last

 

add_executable(station_main_node
 ${${PROJECT_NAME}_MOCS}
 ${${PROJECT_NAME}_RCC}
 ${UI_SRCS}
 )

 

add locs which related ui info locs.

 

this way is on condition that you did everything that need to build your code except these.

 

have a good time !

반응형