在QtCreator中配置c ++项目时出现问题

Problem with configuring c++ project in QtCreator

本文关键字:问题 项目 QtCreator 配置      更新时间:2023-10-16

我有一些 c++ 代码(Snowboy demo - demo.cc(,并使用 g++ 在我的 RaspPI Zero 上成功构建它:

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

为了调试它,我尝试使用QtCreator并创建Qt项目文件:

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

但是在QtCreator中使用此配置时,我收到构建错误:

/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&)'

我是否忘记在Qt项目文件中指定与g++一起使用的任何参数?

您是否可能建议我一种简单的方法来调试 Raspb Pi zero 中具有外部依赖项的 c ++ 代码?

雪男孩出于某种不敬虔的原因要求你使用-D_GLIBCXX_USE_CXX11_ABI=0(谷歌它(。您的命令行中有此标志,这在 Snowboy 的上下文中是正确的,但在您的 .pro 文件中缺少它。添加它。

QMAKE_CPPFLAGS += -D_GLIBCXX_USE_CXX11_ABI=0

或类似的东西。

您还可以尝试将语言标准选项降级为 C++98(不推荐,但如果您的演示未使用任何特定于 c++11 的代码,则应该可以工作(。


我个人认为,任何在2019年仍在使用-D_GLIBCXX_USE_CXX11_ABI=0的软件都需要报废或分叉,但无论什么漂浮你的船。

这个问题

帮助我在qt-creator上成功运行了雪童演示。

我会给这个问题一个更全面的答案,以帮助更多的人:您只需将代码添加到 .pro 文件:

    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