I have some c++ code (Snowboy demo - demo.cc) and successfully build it on my RaspPI Zero using g++:
g++ -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC -I../../ -std=c++0x -Wall -Wno-sign-compare -Wno-unused-local-typedefs -Winit-self -rdynamic -DHAVE_POSIX_MEMALIGN -Iportaudio/install/include -O3 demo.cc portaudio/install/lib/libportaudio.a ../..//lib/rpi/libsnowboy-detect.a -ldl -lm -Wl,-Bstatic -Wl,-Bdynamic -lrt -lpthread portaudio/install/lib/libportaudio.a -L/usr/lib/atlas-base -lf77blas -lcblas -llapack_atlas -latlas -lasound -o demo
To debug it I try to use QtCreator and create Qt project file:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
HEADERS += demo.h
SOURCES += \
demo.cc
INCLUDEPATH += ../../
INCLUDEPATH += portaudio/install/include
LIBS += -Lportaudio/install/lib \
-lportaudio \
-L../../lib/rpi -lsnowboy-detect \
-L/usr/lib/atlas-base \
-ldl -lm -lrt -lpthread \
-lf77blas -lcblas -llapack_atlas -latlas -lasound
But with this configuration in QtCreator I receive build errors:
/home/pi/Prj/snowboy/examples/C++/demo.cc:213: error: undefined reference to `snowboy::SnowboyDetect::SnowboyDetect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
Did I forget to specify any parameters that was used with g++ in Qt project file?
Is it possible you advise me a simple way to debug c++ code with external dependencies in Raspb Pi zero?
Snowboy for some ungodly reason requires you to use -D_GLIBCXX_USE_CXX11_ABI=0 (google it). You have this flag in your command line, which is correct in the context of Snowboy, but are missing it in your .pro file. Add it.
QMAKE_CPPFLAGS += -D_GLIBCXX_USE_CXX11_ABI=0
or something like that.
You can also try downgrading your language standard option to C++98 (not recommended but should work if your demo is not using any c++11-specific code).
I personally think that any software that is still using -D_GLIBCXX_USE_CXX11_ABI=0 in 2019 needs to be scrapped or forked, but whatever floats your boat.
This question help me run the Snowboy demo on qt-creator successfully.
I will give the question a fuller answer, to help more people: You just add the code to .pro file:
QMAKE_CXXFLAGS += -D_GLIBCXX_USE_CXX11_ABI=0
LIBS+= /home/zhurui/QtProject/Test/lib/libsnowboy-detect.a \
-ldl -lm -lrt -lpthread \
/home/zhurui/QtProject/Test/portaudio/install/lib/libportaudio.a \
-L/usr/lib/atlas-base \
-lf77blas -lcblas -llapack_atlas \
-latlas -lasound
Related
I am creating client-server application, using gRPC. So far I was not using TLS encryption. Now I want to enable it, and strangely I get this error. It seems, at least to me, that this is a linker error. What would be best ways to solve it?
CLion doesn't highlight anything, so I assumed everything was syntactically OK, but when compiling I got that error.
/usr/bin/ld: CMakeFiles/projectname.dir/main.cpp.o: in function `grpc::SslServerCredentials(grpc::SslServerCredentialsOptions const&)':
/home/username/projectname/third_party/grpc/include/grpcpp/security/server_credentials.h:60: undefined reference to `grpc_impl::SslServerCredentials(grpc::SslServerCredentialsOptions const&)'
collect2: error: ld returned 1 exit status
This is a makefile that I use to generate C++ code from gRPC specification:
HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
SYSTEM ?= $(HOST_SYSTEM)
CXX = g++
CPPFLAGS += `pkg-config --cflags protobuf grpc`
CXXFLAGS += -std=c++11
ifeq ($(SYSTEM),Darwin)
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++`\
-lgrpc++_reflection\
-ldl
else
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++`\
-Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\
-ldl
endif
PROTOC = protoc
GRPC_CPP_PLUGIN = grpc_cpp_plugin
GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
PROTOS_PATH = ./
vpath %.proto $(PROTOS_PATH)
%.grpc.pb.cc: %.proto
$(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
%.pb.cc: %.proto
$(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
clean:
rm -f *.o *.pb.cc *.pb.h
Then problem was solved like this:
I had to chage grpc++_unsecure to grpc++ under target_link_libraries in CMakeLists.txt cmake build configuration file.
I had forgotten/not thought about this at first.
target_link_libraries(bita_server
pqxx
sodium
protobuf::libprotobuf
# grpc++_unsecure
grpc++
SQLiteCpp
sqlite3
pthread
dl
${_PROTOBUF_LIBPROTOBUF}
)
In CMakeLists.txt under grpc folder, there are many target_link_libraries. which one to edit in order to include the change.
Makefile:
CFLAGS = -c -g -W -O3 -Wall -Werror -Wshadow \
-Wno-long-long -Wpointer-arith -D_REENTRANT \
-D_POSIX_PTHREAD_SEMANTICS -DLINUX2 \
-I ./acl/lib_acl_cpp/include
BASE_PATH=./acl
LDFLAGS = -L$(BASE_PATH)/lib_acl_cpp/lib -l_acl_cpp \
-L$(BASE_PATH)/lib_protocol/lib -l_protocol \
-L$(BASE_PATH)/lib_acl/lib -l_acl \
-lpthread
redisConnection: redisConnection.o
g++ -o $# $^ $(LDFLAGS)
redisConnection.o: redisConnection.cpp
g++ $(CFLAGS) redisConnection.cpp -o redisConnection.o
And I have generated the nrtprofile.pb.cc and nrtprofile.pb.h with the help of protoc command.
What changes must be made in the makefile because I am getting the following error in the class redisConnection.cpp when I am using the functions:
undefined reference to `google::protobuf::MessageLite::ParseFromString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
I have included nrtprofile.pb.h in the redisConnection.cpp
As here there are two things redisConnection and redisConnection.o, I am getting confused where should I write nrtprofile.pb.cc.
Add -lprotobuf to the LDFLAGS variable.
However, this assumes that the protobuf library is installed in a location where the linker finds it (e.g. /usr/lib). If you have it somewhere else, you can provide the additional search path by setting the LD_LIBRARY_PATH variable like this: export LD_LIBRARY_PATH=/my/special/path.
You can find the needed linker and compiler flags here. Basically, compiler and linker-related, you need to do something like c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf
I'm porting an application qt3 -> qt5. As part of that I have in a .cpp file changed (Qt3)
mySystemstruct.display = theWidget->x11Display();
into (Qt5)
mySystemstruct.display = QX11Info::display();
Include has been added in the file.
#include <QX11Info>
I am not using Qt Creator. The file in question is not been linked using qmake. (other files has)
I get this link errors:
/home/go/NetBeansProjects/Arbete_216/Ajourwork/Components/TheRealDeal/GUI/linuxobj//GO_C_QtGUI.o: In function `GO_C_QtGUI::initHistoryFilm(QWidget*, int, int)':
/home/go/NetBeansProjects/Arbete_216/Ajourwork/Modules/GUI/QtGUI/GO_C_QtGUI.cpp:668: undefined reference to `QX11Info::display()'
using this compile command:
clang++ -o gvs_GUI linuxobj/*.o linuxobj/libQtSpecific.a -DLINUX -I/include/ -g -I /opt/intel/composer_xe_2015.1.133/ipp/include/ -Wno-deprecated -D_GNU_SOURCE -D_REENTRANT -D__STDC_CONSTANT_MACROS -I/usr/include/postgresql/ -I/usr/local/Qt/5.2.1/gcc_64/include/QtX11Extras/ -I/usr/local/Qt/5.2.1/gcc_64/include/QtWidgets/ -I/usr/local/Qt/5.2.1/gcc_64/include/ -I/usr/local/Qt/5.2.1/gcc_64/include/QtGui/ -fPIC -fPIE -I/home/go/ffmpeg_build/include/ -I/usr/local/Qt/5.2.1/gcc_64/include/QtCore/ -fPIC -fPIE -I/home/go/ffmpeg_build/include/libavcodec -I/home/go/ffmpeg_build/include/libavformat/ -lpq -lippi -lipps -lippcore -lpthread -lgcrypt -lippvm -lippcv -lippcc -L/opt/intel/composer_xe_2015.1.133/ipp/lib/intel64 -L/usr/local/Qt/5.2.1/gcc_64/lib/ -L/usr/X11R6/lib/ -lXv -lX11 -lXext -ltar -lavformat -lavcodec -lavfilter
Is it not possible to build using Qt libs not using qmake? My code has been built that way with earlier versions of Qt so it seems it should work.(?)
Since not using qmake for linking, I use -I/usr/local/Qt/5.2.1/gcc_64/include/QtX11Extras/ -L/usr/local/Qt/5.2.1/gcc_64/lib/ but it doesn't seem to work.
The QtX11-lib seems to be in place:
locate libQt5X11Extras.so
/usr/local/Qt/5.2.1/gcc_64/lib/libQt5X11Extras.so
/usr/local/Qt/5.2.1/gcc_64/lib/libQt5X11Extras.so.5
/usr/local/Qt/5.2.1/gcc_64/lib/libQt5X11Extras.so.5.2
/usr/local/Qt/5.2.1/gcc_64/lib/libQt5X11Extras.so.5.2.1
What am I doing wrong here?
-L/usr/local/Qt/5.2.1/gcc_64/lib/ only tells the linker where to find the libraries.
You must then add -lQt5X11Extras to ask to link to the Qt5X11 library.
I get a strange error while building my Qt C++ project on Ubuntu Linux using GCC 5.2.1:
/usr/bin/ld: cannot find -llibmath
I include external dynamic library to maky qmake project using command:
LIBS += -L/home/rem -llibmath
and I have library file at path /home/rem/libmath.so
As I can see from compiler output:
g++ -Wl,-rpath,/home/rem/Qt/5.5/gcc_64 -Wl,-rpath,/home/rem/Qt/5.5/gcc_64/lib -o Bazis main.o builder.o -L/home/rem -llibmath -L/home/rem/Qt/5.5/gcc_64/lib -lQt5OpenGL -L/usr/lib64 -lQt5QuickWidgets -lQt5Widgets -lQt5Quick -lQt5Gui -lQt5Sql -lQt5Test -lQt5Qml -lQt5Network -lQt5Core -lGL -lpthread
all parameters are correctly send by qmake to g++.
What is the source of my problem?
The solution is simple:
I changed my .pro file from:
LIBS += -L/home/rem -llibmath
to:
LIBS += -L/home/rem -lmath
This is a bit of a newbie question. I am trying to add the OpenCV libraries to a QT project.
This question says the link flags are given by
pkg-config --libs opencv
If I paste the command line output into the project file like:
LIBS += -L/usr/local/lib -lml -lcvaux -lhighgui -lcv -lcxcore
then everything compiles fine, but now this isn't portable. How can I simply reference the output of the command?
Update: Tried Ken Bloom's suggestion, but it won't compile. The actual generated compiler commands are
# How it should be, at least on my machine
g++ -o QOpenCVTest main.o qopencvtest.o moc_qopencvtest.o -L/usr/lib -L/usr/local/lib -lml -lcvaux -lhighgui -lcv -lcxcore -lQtGui -lQtCore -lpthread
# with CONFIG and PKGCONFIG
g++ -o QOpenCVTest main.o qopencvtest.o moc_qopencvtest.o -L/usr/lib -lQtGui -lQtCore -lpthread
CONFIG += link_pkgconfig
PKGCONFIG += opencv
(I got this answer from http://beaufour.dk/blog/2008/02/using-pkgconfig.html)
Ken's answer worked great. I just had to remove the spaces on either side of the += first.
CONFIG+=link_pkgconfig PKGCONFIG+=opencv
In the newer version of Qt, this needs to be done to avoid a package not found error:
QT_CONFIG -= no-pkg-config
CONFIG += link_pkgconfig
PKGCONFIG += protobuf #or whatever package here
Also had to do this for Mac:
mac {
PKG_CONFIG = /usr/local/bin/pkg-config
}
Something like this in your qmake file should do
LIBS += `pkg-config --libs opencv`
Edit: Hmm, Ken Bloom's answer might be more portable, but erhm not documented?
Add the following lines to your .pro file:
INCLUDEPATH += `pkg-config --cflags opencv`
LIBS += `pkg-config --libs opencv`