在 Qt 中包含共享内存 BOOST 库

Including Shared Memory BOOST Libraries in Qt

我安装了 BOOST 1.57 以允许我使用一些新功能,因此我只是在 /usr/local/boost 处创建了一个包含 BOOST 根文件夹的目录。

我已经成功地创建了显示的示例代码 here 并使用以下代码对其进行了编译:

 g++ example.cpp -o example -lrt

这是我的 .pro 文件:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Ph2_ACF
TEMPLATE = app

CONFIG += c++11 debug

QMAKE_CXXFLAGS += -g -O1 -w -pedantic -fPIC -std=c++11 -lrt `root-config --cflags --evelibs` -Wcpp

LIBS += -L../lib -lPh2_Interface -lPh2_Description -lPh2_System -lPh2_Tools -lPh2_Utils
LIBS += $(LibraryPaths:%=-L%) -uhal `root-config --glibs`

LIBS += -L/usr/lib/ -lqjson
INCLUDEPATH += /usr/include/qjson/
INCLUDEPATH += $(ROOTSYS)/include

INCLUDEPATH += /../../Ph2DAQ_dev/
INCLUDEPATH += /usr/local/boost
LIBS += -L/usr/local/boost/libs

这是我的错误:

g++ -Wl,-rpath,/usr/local/Trolltech/Qt-4.8.5/lib -o Ph2_ACF main.o mainview.o startup.o setuptab.o setuptabviewmanager.o settings.o systemcontroller.o cbcregisterstab.o cbcregviewmanager.o provider.o aboutbox.o systemcontrollerworker.o cbcregisters.o mainviewmanager.o cbcregisterworker.o tbrowsertab.o calibrate.o hybridtest.o hybridtestworker.o hybridtestviewmanager.o hybridtesttab.o moc_mainview.o moc_startup.o moc_setuptab.o moc_setuptabviewmanager.o moc_settings.o moc_systemcontroller.o moc_cbcregisterstab.o moc_cbcregviewmanager.o moc_aboutbox.o moc_systemcontrollerworker.o moc_cbcregisters.o moc_mainviewmanager.o moc_cbcregisterworker.o moc_tbrowsertab.o moc_calibrate.o moc_hybridtest.o moc_hybridtestworker.o moc_hybridtestviewmanager.o moc_hybridtesttab.o qrc_Resources.o    -L/usr/local/Trolltech/Qt-4.8.5/lib -L/usr/include/boost -lboost_system -lboost_thread -lboost_regex -L../lib -lPh2_Interface -lPh2_Description -lPh2_System -lPh2_Tools -lPh2_Utils -L/opt/cactus/lib -lcactus_extern_pugixml -lcactus_uhal_log -lcactus_uhal_grammars -lcactus_uhal_uhal  -uhal `root-config --glibs` -L/usr/lib/ -lqjson -L/usr/local/boost/libs -lQtGui -L/usr/local/Trolltech/Qt-4.8.5/lib -L/usr/X11R6/lib -lQtCore -lpthread 
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: skipping incompatible /usr/lib//libdl.so when searching for -ldl
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: skipping incompatible /usr/lib//libdl.a when searching for -ldl
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: skipping incompatible /usr/lib//libpthread.so when searching for -lpthread
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: skipping incompatible /usr/lib//libpthread.a when searching for -lpthread
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: skipping incompatible /usr/lib//libm.so when searching for -lm
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: skipping incompatible /usr/lib//libm.a when searching for -lm
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: skipping incompatible /usr/lib//libpthread.so when searching for -lpthread
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: skipping incompatible /usr/lib//libpthread.a when searching for -lpthread
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: skipping incompatible /usr/lib//libc.so when searching for -lc
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: skipping incompatible /usr/lib//libc.a when searching for -lc
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: hybridtestworker.o: undefined reference to symbol 'shm_open@@GLIBC_2.2.5'
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: note: 'shm_open@@GLIBC_2.2.5' is defined in DSO /lib64/librt.so.1 so try adding it to the linker command line
/lib64/librt.so.1: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make: *** [Ph2_ACF] Error 1

请注意之前的所有 skipping 警告都没有问题,只是最后的 'shm_open@@GLIBC_2.2.5' 似乎打破了它。

我添加的是:

#include <boost/interprocess/shared_memory_object.hpp>

// SNIP !

using namespace boost::interprocess;

// SNIP !

shared_memory_object shm_obj
        (
            create_only                  //only create
           ,"shared_memory"              //name
           ,read_write                   //read-write mode
           );

进入我的一个文件。

知道发生了什么吗?

编辑:

添加:

LIBS += -L/usr/local/boost/libs -lrt

给我新的错误:

/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: mainview.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: note: '_ZN5boost6system15system_categoryEv' is defined in DSO /opt/cactus/lib/libboost_system.so.1.48.0 so try adding it to the linker command line
/opt/cactus/lib/libboost_system.so.1.48.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make: *** [Ph2_ACF] Error 1

您似乎在编译标志中添加了 -lrt,但它们并未包含在 link 阶段。

尝试将 -lrt -lboost_system 添加到 LIBS 变量(如 -lPh2_Description 和其他变量)