Including Shared Memory BOOST Libraries in Qt - c++

I installed BOOST 1.57 to allow me to use some new features, so I simply created a directory at /usr/local/boost which contains the root BOOST folders.
I have managed to create the example code shown here and compile it using:
g++ example.cpp -o example -lrt
Here is my .pro file:
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
And here is my error:
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
Just to note all the previous skipping warnings were fine before, it's just this final 'shm_open##GLIBC_2.2.5' which seems to break it.
All I've added is:
#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
);
Into one of my files.
Any idea what is going on?
EDIT:
Adding:
LIBS += -L/usr/local/boost/libs -lrt
Gives me the new error:
/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

It looks like you added -lrt to the compile flags, and they're not being included at the link stage.
Try adding -lrt -lboost_system to the LIBS variable (like -lPh2_Description and the rest)

Related

Linker can't find -lgcc [CMU Malloc Lab]

I'm trying to make the following makefile code
#
# Students' Makefile for the Malloc Lab
#
TEAM = bovik
VERSION = 1
HANDINDIR = /afs/cs.cmu.edu/academic/class/15213-f01/malloclab/handin
CC = gcc
CFLAGS = -Wall -O2 -m32
OBJS = mdriver.o mm.o memlib.o fsecs.o fcyc.o clock.o ftimer.o
mdriver: $(OBJS)
$(CC) $(CFLAGS) -o mdriver $(OBJS)
mdriver.o: mdriver.c fsecs.h fcyc.h clock.h memlib.h config.h mm.h
memlib.o: memlib.c memlib.h
mm.o: mm.c mm.h memlib.h
fsecs.o: fsecs.c fsecs.h config.h
fcyc.o: fcyc.c fcyc.h
ftimer.o: ftimer.c ftimer.h config.h
clock.o: clock.c clock.h
handin:
cp mm.c $(HANDINDIR)/$(TEAM)-$(VERSION)-mm.c
clean:
rm -f *~ *.o mdriver
but get an error message
gcc -Wall -O2 -m32 -o mdriver mdriver.o mm.o memlib.o fsecs.o fcyc.o clock.o ftimer.o
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/7/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/7/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
collect2: error: ld returned 1 exit status
Makefile:14: recipe for target 'mdriver' failed
make: *** [mdriver] Error 1
Things that I have tried include:
Install gcc-multilib, libc6-i386, libc6-dev-i386 lib32gcc1, lib32stdc++6,libc6-dev-i386
export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/usr/lib/i386-linux-gnu
In my system, there is no libgcc.so file but libgcc_s.so and libgcc_s.so.1. Can someone help me with it?

CMake linking to the result of a subshell

I am having trouble linking python 3 in cmake.
The options to link in the shell are $(/usr/bin/python3-config --ldflags) and that works completely fine.
But when I move to cmake, I use:
set(Python_ADDITIONAL_VERSIONS 3.5)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries(sim ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(sim ${CMAKE_DL_LIBS})
target_link_libraries(sim ${PYTHON_LIBRARIES})
giving me the error:
/usr/bin/ld: /usr/local/lib/libpython3.5m.a(dynload_shlib.o): undefined reference to symbol 'dlsym##GLIBC_2.2.5'
/usr/lib/x86_64-linux-gnu/libdl.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I then tried
target_link_libraries(sim "$(/usr/bin/python3-config --ldflags)")
but this also does not work with error message
c++: error: $(/usr/bin/python3-config: No such file or directory
c++: error: unrecognized command line option ‘--ldflags)’
The only method that works for me is to open the subshell by
echo $(/usr/bin/python3-config --ldflags)
-L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -L/usr/lib -lpython3.5m -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions
and write the content to cmake as
target_link_libraries(sim "-L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -L/usr/lib -lpython3.5m -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions")
This works but the method is nasty. Is there any clean way to perform such linking?

Cross compiling a Webots controller

I'm trying to use MinGW to cross compile from Linux to Windows a robotic controller (.exe) for Webots (simulation software).
Webots supplies a Makefile.include file common to all platforms, that prepares the building environment for compilation (necessary dependencies):
My current makefile, where I set several variables according to MinGW and my webots installation:
WEBOTS_HOME = /usr/share/webots/resources/windows_home
#WEBOTS_HOME = /usr/share/webots
RESOURCES_PATH = $(WEBOTS_HOME)/resources/projects/robots/darwin-op
SOURCES_PATH = src
SOCKET_PATH = ../../../extra/socket/src
KIN_INCLUDE = ../../lib/OPKinematics/include
KIN_LIB = ../../lib/OPKinematics/lib/libOPKinematics64.a
EXT_INCLUDE = ../../lib/include
CFLAGS = -g -Wall
INCLUDE=-I$(RESOURCES_PATH)/libraries/darwin/darwin/Framework/include -I$(RESOURCES_PATH)/include -I$(KIN_INCLUDE) -I$(EXT_INCLUDE) -I$(SOCKET_PATH)
LIBRARIES = -Wl,-Bstatic -lws2_32 -lpthread -lboost_system-mt -lboost_serialization-mt -static-libgcc -static-libstdc++ -Wl,-Bdynamic $(RESOURCES_PATH)/libraries/darwin/darwin.dll $(KIN_LIB)
CXX_SOURCES = $(SOURCES_PATH)/main.cpp $(SOURCES_PATH)/DarwinRobot.cpp $(SOURCES_PATH)/dyn_system.cpp $(SOURCES_PATH)/writefilestuff.cpp $(SOCKET_PATH)/socket_boost.cpp
#CC=x86_64-w64-mingw32-g++
CXX=x86_64-w64-mingw32-g++
EXE_EXTENSION=.exe
OSTYPE=windows
CFLAGS += -DWIN_MAKE
# ----------------------------------------------------
#
### Do not modify: this includes Webots global Makefile.include
space :=
space +=
WEBOTS_HOME_PATH=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME))))
include $(WEBOTS_HOME_PATH)/resources/Makefile.include
# No pre or post build rules are necessary, override the default set on Makefile.include
pre-build: ;
post-build: main-build ;
#echo $(CC)
#echo $(OSTYPE)
# ---------------------------------------------------
Additionaly, I've installed Webots on my Windows box and copied the installation folder to the installation folder on my Linux box, so that I could have access to the pre-compiled Windows libraries.
The problem is when the linker tries to find a couple of libraries (-lController and -lCppController, which are appended inside Makefile.include):
# linking build/release/darwin_socket.exe
x86_64-w64-mingw32-g++ -s -Wl,--enable-auto-import -o build/release/darwin_socket.exe build/release/main.o build/release/DarwinRobot.o build/release/dyn_system.o build/release/writefilestuff.o build/release/socket_boost.o -Wl,-Bstatic -lws2_32 -lpthread -lboost_system-mt -lboost_serialization-mt -static-libgcc -static-libstdc++ -Wl,-Bdynamic /usr/share/webots/resources/windows_home/resources/projects/robots/darwin-op/libraries/darwin/darwin.dll ../../lib/OPKinematics/lib/libOPKinematics64.a -lmingw32 -B"/usr/share/webots/resources/windows_home\mingw\lib\gcc\mingw32\5.1.0" -L"/usr/share/webots/resources/windows_home/lib" -lController -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/libController.a when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/Controller.lib when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/Controller.dll when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/libController.a when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/libController.a when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/Controller.lib when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/Controller.dll when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/Controller.lib when searching for -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32 /bin/ld: cannot find -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/libCppController.a when searching for -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/CppController.dll when searching for -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/libCppController.a when searching for -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/libCppController.a when searching for -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/share/webots/resources/windows_home/lib/CppController.dll when searching for -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lCppController
collect2: error: ld returned 1 exit status
/usr/share/webots/resources/windows_home/resources/Makefile.include:529: recipe for target 'build/release/darwin_socket.exe' failed
make: *** [build/release/darwin_socket.exe] Error 1
From what I've gathered, this issue is usually caused when trying to link 32-bit libraries to a 64-bit binary (or vice-versa), but I have no -m32 or -m64 flags on my makefile or on Makefile.include. My OSs are both 64-bit, so I assume there should not be any problem with the type of libraries.
I've tried using Webots' native linux installation folder instead, but I encounter similar issues:
# linking build/release/darwin_socket.exe
x86_64-w64-mingw32-g++ -s -Wl,--enable-auto-import -o build/release/darwin_socket.exe build/release/main.o build/release/DarwinRobot.o build/release/dyn_system.o build/release/writefilestuff.o build/release/socket_boost.o -Wl,-Bstatic -lws2_32 -lpthread -lboost_system-mt -lboost_serialization-mt -static-libgcc -static-libstdc++ -Wl,-Bdynamic /usr/share/webots/resources/projects/robots/darwin-op/libraries/darwin/darwin.dll ../../lib/OPKinematics/lib/libOPKinematics64.a -lmingw32 -B"/usr/share/webots\mingw\lib\gcc\mingw32\5.1.0" -L"/usr/share/webots/lib" -lController -lCppController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lController
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lCppController
collect2: error: ld returned 1 exit status
/usr/share/webots/resources/Makefile.include:529: recipe for target 'build/release/darwin_socket.exe' failed
make: *** [build/release/darwin_socket.exe] Error 1
which is rather strange, because both libController.so and libCppController.so are present inside /usr/share/webots/lib/.
So what exactly am I missing here?

Undefined reference to QVideoSurfaceFormat constructor

I am programming for Ubutu linux, and am tryi9ng to display video. However, i have run into a problem:
i am not able to create instances of QVideoSurfaceFormat, due to the following error:
undefined reference to `QVideoSurfaceFormat::QVideoSurfaceFormat(QSize const&, QVideoFrame::AVPixelFormat, QAbstractVideoBuffer::HandleType)'
collect2: error: ld returned 1 exit status
I am guessing that the problem lies inQt Multimedia binaries, somewhere. But in the compile output there is the following:
g++ -o LPR_Demo main.o mainwindow.o imgProcessor.o qpicturelabel.o aboutdialog.o state.o videowidget.o videowidgetsurface.o videoplayer.o qt_videoreader.o roidialog.o recognitionresult.o ffmpeg_reader.o moc_mainwindow.o moc_imgProcessor.o moc_aboutdialog.o moc_videowidget.o moc_videowidgetsurface.o moc_videoplayer.o moc_qt_videoreader.o moc_roidialog.o moc_recognitionresult.o qrc_lpr_Res.o -L/usr/lib/i386-linux-gnu -L/usr/X11R6/lib -L/home/truskov/development/lprsdk/LPR/bin -lLPR -lavformat -lavcodec -lavutil -lswscale -L/usr/lib/i386-linux-gnu -lQtMultimediaKit -lQtOpenGL -lQtGui -lQtNetwork -lQtCore -lGL -lpthread
where QtMultimediaKit library seems to be in place.
My .pro file goes like this:
QT += core gui
win32:QT+= multimedia
unix {
QT+= mobility multimediakit
MOBILITY = multimedia
CONFIG += mobility
}
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = LPR_Demo
TEMPLATE = app
however, when qmake runs, i get following messages:
Project MESSAGE: Warning: unknown QT: mobility
Project MESSAGE: Warning: unknown QT: multimediakit
What could cause this? How can it be solved?

make command gives Incompatible i386 architecture(i386x86-64)

Im having trouble using my make file for a program i am writing in a linux environment. The program is a fern fractal that uses bitmapImage.h and bitmapImage.so given to me by my professor. Whenever i attempt to run the make file i get a long string of errors, the main one being :
make
g++ -c -o fern.o fern.cpp
g++ -c -o fernType.o fernType.cpp
g++ -m32 -o fern fern.o fernType.o bitmapImage.so
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: ld returned 1 exit status
make: *** [spiro] Error 1
my guess is that the bitmapImage.so is designed for a 32 bit system, but my virtual machine ubuntu runs 64-bit. How do i go about fixing this so i can compile my program? Thanks!
EDIT: updated my old post to show the current error i am getting
MakeFile:
# Make file for spirograph program
## note, uses bitmapImage shared object file (library).
OBJS = fern.o fernType.o
CC = g++ -m32
DEPS1 = fernType.h
DEPS2 = bitmapImage.h
all: spiro
spiro: $(OBJS)
$(CC) -m32 -o fern $(OBJS) bitmapImage.so
spiro.o: fern.cpp $(DEPS1)
$(CC) -m32 -c fern.cpp
spiroType.o: fernType.cpp $(DEPS1) $(DEPS2)
$(CC) -m32 -c fernType.cpp
# -----
# clean by removing object files.
clean:
rm $(OBJS)
Add the -m32 option to your compilation lines, that forces everything to be compiled for a 32-bit address space. (It will still run on a 64-bit system.)
Yes, that's exactly the problem -- you can't link a 32-bit object file with a 64-bit object file. You need to either:
Compile on a 32-bit machine (real or virtual),
Ask your professor for a 64-bit library, or
Ask for the source code to the library so you can compile it all yourself
Use file to see if, indeed, the shared lib is 32-bit.
If it is, you'll have to acquire a 64-bit copy of it somehow.