简体   繁体   English

无法使用 ROOT 构建 gui 程序

[英]Cannot build gui program with ROOT

I am trying to build this simple gui program in c++ created with ROOT libraries:我正在尝试在使用 ROOT 库创建的 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;
}

I always get many errors with ld.我总是在 ld 上遇到很多错误。 Like /usr/bin/ld: cannot find -lmodule-credentials-goa or /usr/bin/ld: cannot find -lmodule-outlook-backend ./usr/bin/ld: cannot find -lmodule-credentials-goa/usr/bin/ld: cannot find -lmodule-outlook-backend I am using ROOT version 6.24/06, running on Ubuntu 21.10.我正在使用 ROOT 版本 6.24/06,在 Ubuntu 21.10 上运行。 ROOT was installed with SNAP. ROOT 是随 SNAP 安装的。

Here is the full error print out:这是打印出的完整错误:

====================[ 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

Here is my CMakeLists.txt这是我的 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})

With this modified CMakeLists.txt, I can run it without problems:使用这个修改后的 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)

See also the example at https://root.cern/manual/integrate_root_into_my_cmake_project/#full-example-event-project另请参阅 https 中的示例://root.cern/manual/integrate_root_into_my_cmake_project/#full-example-event-project

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM