我试图在用根库创建的c++中构建这个简单的gui程序:
#include <stdlib.h>
#include <TApplication.h>
#include <TGClient.h>
#include <TGFrame.h>
#include <RQ_OBJECT.h>
class MyMainFrame{
RQ_OBJECT("MyMainFrame")
private:
TGMainFrame *fMain;
public:
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~MyMainFrame();
};
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) {
fMain = new TGMainFrame(p,w,h);
fMain->SetWindowName("Test");
fMain->MapWindow();
}
MyMainFrame::~MyMainFrame() {
fMain->Cleanup();
delete fMain;
}
int main(int argc, char** argv) {
TApplication theApp("App", &argc, argv);
new MyMainFrame(gClient->GetRoot(), 200, 300);
theApp.Run();
return 0;
}我经常犯很多错误。比如/usr/bin/ld: cannot find -lmodule-credentials-goa或者/usr/bin/ld: cannot find -lmodule-outlook-backend。我使用的是根版本6.24/06,运行在Ubuntu21.10上。ROOT安装在SNAP中。
以下是打印的全部错误:
====================[ Build | gui | Debug ]=====================================
/opt/clion-2021.1.2/bin/cmake/linux/bin/cmake --build /home/rado/CLionProjects/BP/gui/cmake-build-debug --target gui -- -j 4
[ 50%] Linking CXX executable gui
/usr/bin/ld: cannot find -lmodule-credentials-goa
/usr/bin/ld: cannot find -lmodule-cache-reaper
/usr/bin/ld: cannot find -lmodule-gnome-online-accounts
/usr/bin/ld: cannot find -lmodule-google-backend
/usr/bin/ld: cannot find -lmodule-oauth2-services
/usr/bin/ld: cannot find -lmodule-outlook-backend
/usr/bin/ld: cannot find -lmodule-secret-monitor
/usr/bin/ld: cannot find -lmodule-trust-prompt
/usr/bin/ld: cannot find -lmodule-webdav-backend
/usr/bin/ld: cannot find -lmodule-yahoo-backend
/usr/bin/ld: cannot find -lmodule-evolution-alarm-notify
/usr/bin/ld: cannot find -lmodule-accounts-window
/usr/bin/ld: cannot find -lmodule-addressbook
/usr/bin/ld: cannot find -lmodule-backup-restore
/usr/bin/ld: cannot find -lmodule-bogofilter
/usr/bin/ld: cannot find -lmodule-book-config-carddav
/usr/bin/ld: cannot find -lmodule-book-config-google
/usr/bin/ld: cannot find -lmodule-book-config-ldap
/usr/bin/ld: cannot find -lmodule-book-config-local
/usr/bin/ld: cannot find -lmodule-cal-config-caldav
/usr/bin/ld: cannot find -lmodule-cal-config-contacts
/usr/bin/ld: cannot find -lmodule-cal-config-google
/usr/bin/ld: cannot find -lmodule-cal-config-local
/usr/bin/ld: cannot find -lmodule-cal-config-weather
/usr/bin/ld: cannot find -lmodule-cal-config-webcal
/usr/bin/ld: cannot find -lmodule-cal-config-webdav-notes
/usr/bin/ld: cannot find -lmodule-calendar
/usr/bin/ld: cannot find -lmodule-composer-autosave
/usr/bin/ld: cannot find -lmodule-composer-to-meeting
/usr/bin/ld: cannot find -lmodule-config-lookup
/usr/bin/ld: cannot find -lmodule-contact-photos
/usr/bin/ld: cannot find -lmodule-gravatar
/usr/bin/ld: cannot find -lmodule-itip-formatter
/usr/bin/ld: cannot find -lmodule-mail-config
/usr/bin/ld: cannot find -lmodule-mail
/usr/bin/ld: cannot find -lmodule-mailto-handler
/usr/bin/ld: cannot find -lmodule-mdn
/usr/bin/ld: cannot find -lmodule-offline-alert
/usr/bin/ld: cannot find -lmodule-plugin-lib
/usr/bin/ld: cannot find -lmodule-plugin-manager
/usr/bin/ld: cannot find -lmodule-prefer-plain
/usr/bin/ld: cannot find -lmodule-settings
/usr/bin/ld: cannot find -lmodule-startup-wizard
/usr/bin/ld: cannot find -lmodule-text-highlight
/usr/bin/ld: cannot find -lmodule-tnef-attachment
/usr/bin/ld: cannot find -lmodule-vcard-inline
/usr/bin/ld: cannot find -lmodule-webkit-editor
/usr/bin/ld: cannot find -lmodule-webkit-inspector
/usr/bin/ld: cannot find -lmodule-webkit-editor-webextension
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/gui.dir/build.make:2827: gui] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:83: CMakeFiles/gui.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/gui.dir/rule] Error 2
gmake: *** [Makefile:124: gui] Error 2这是我的CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(gui)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_FIND_ROOT_PATH /snap/root-framework/current/usr/local)
find_package(ROOT REQUIRED COMPONENTS ${ROOT_LIBRARIES})
include_directories(${ROOT_CURRENT_SOURCE_DIR}/include)
include(${ROOT_USE_FILE})
add_executable(gui main.cpp)
file(GLOB_RECURSE SOURCES2 . $ENV{ROOTSYS}/lib/*.so)
target_link_libraries(gui PUBLIC ${SOURCES2} ${ROOT_LIBRARIES})
set_target_properties(gui PROPERTIES COMPILE_FLAGS ${ROOT_CXX_FLAGS} ${ROOT_CC_FLAGS})发布于 2022-02-24 18:21:16
使用这个修改过的CMakeLists.txt,我可以毫无问题地运行它:
cmake_minimum_required(VERSION 3.15)
project(gui)
set(CMAKE_CXX_STANDARD 17)
if(DEFINED ROOTSYS)
set (ROOT_DIR ${ROOTSYS} CACHE STRING "ROOT build directory")
else()
set (ROOT_DIR /opt/root CACHE STRING "ROOT build directory")
endif()
find_package(ROOT CONFIG REQUIRED)
add_executable(gui main.cpp)
target_link_libraries(gui PUBLIC ROOT::Gui)还请参阅https://root.cern/manual/integrate_root_into_my_cmake_project/#full-example-event-project中的示例
https://stackoverflow.com/questions/69895940
复制相似问题