c++ 如何在qt creator中编译和运行pjsua2演示应用程序?

wb1gzix0  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(141)

我正在尝试在Qt creator中构建P2P应用程序。我对C++没有太多的了解。我安装了Qt,并构建和安装了pjproject库。我添加了pjproject库与pkgconfig,如Adding library to qt project
下面是源代码code on GitHub
以下是我的.pro文件:

QT += quick

SOURCES += \
        main.cpp

resources.files = main.qml 
resources.prefix = /$${TARGET}
RESOURCES += resources

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += libpjproject

unix: PKGCONFIG += openssl

字符串
在pjproject目录中,我发现了**./pjsip-apps/src/samples/pjsua2_demo.cpp**文件,其中包含了我的项目的完美 backbone 代码,所以我将代码从该文件复制到了我的项目主文件中。

这是我得到的错误:

Image of errors in Qt Creator
以下是一些错误行:

  1. gsm.c:-1:错误:未定义对gsm_decode' :-1: error: /usr/local/lib/libpjmedia-codec-x86_64-unknown-linux-gnu.a(gsm.o): in function gsm_codec_encode '的引用:
    1.地址:/usr/local/lib/libpjmedia-codec-x86_64-unknown-linux-gnu.a(speex_codec.o):in function spx_codec_decode': speex_codec.c:-1: error: undefined reference to speex_bits_read_from'
    1.地址:深圳市宝安区沙井街道沙井工业园A栋2楼电话:0755 - 88888888传真:0755 - 88888888
    1.......这是什么?
    我试着运行编译版本的pjsua2_demo.cpp,一切正常。可执行文件位置**./pjsip-apps/bin/samples/x86_64-unknown-linux-gnu**在pjproject目录下。我怀疑问题是包含库并将其链接到项目中,但我不知道如何做到这一点。
    先谢了。
bq9c1y66

bq9c1y661#

我还没有找到 .pro 构建文件的解决方案,所以我决定尝试使用 cmake。我在this Stackoverflow question上找到了解决方案,并将其与tsyvarev用户的评论相结合。
下面是我的project中的 cmake 文件:

cmake_minimum_required(VERSION 3.16)

project(bjSip VERSION 0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTORCC ON)

#adding pthread flags for pjsip
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(THREADS_PREFER_PTHREAD_FLAG ON)

find_package(Qt6 6.4 REQUIRED COMPONENTS Core Quick LinguistTools )
#qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} translationSR.ts)
#configure_file(${QM_FILES} ${CMAKE_SOURCE_DIR} COPYONLY)

#add pkgconfig tool for linking pjsip lib
INCLUDE(FindPkgConfig)
find_package(PkgConfig REQUIRED)
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)

pkg_check_modules(PJSIP "libpjproject")

add_definitions(${PJSIP_CFLAGS})
#adding paths to include dirs and static library
include_directories(${PJSIP_INCLUDE_DIRS})
include_directories(/cpp/include)
link_directories(${PJSIP_STATIC_LIBRARY_DIRS})

qt_standard_project_setup()

qt_add_executable(appbjSip
    main.cpp
    cpp/sip/bjendpoint.h cpp/sip/bjendpoint.cpp
    cpp/sip/bjcall.h cpp/sip/bjcall.cpp
    cpp/sip/bjaudiomediaport.h cpp/sip/bjaudiomediaport.cpp
    cpp/sip/bjaccount.h cpp/sip/bjaccount.cpp
    cpp/sip/bjsip.h cpp/sip/bjsip.cpp

    Models/local-storage.js
    Models/user-model.js
    Models/contact-model.js
    Models/call-history-model.js
    Utils/changeBrightness.js
    Utils/getBuddiesUsernames.js
    Resources.qrc
    ${QM_FILES}
)

qt_add_qml_module(appbjSip
    URI bjSip
    VERSION 1.0
    QML_FILES   Main.qml
                ./Views/MenuView.qml
                ./Views/AndroidView.qml
                ./Views/DesktopView.qml
                ./Views/LoginView.qml
                ./Views/RegisterView.qml
                ./Views/CallView.qml
                ./Views/SettingView.qml
                ./Views/AppBar.qml
                ./Components/Forms/LoginForm.qml
                ./Components/Forms/RegisterForm.qml
                ./Components/Forms/AddNewContactForm.qml
                ./Components/Reusables/FontAwesomeIcons.qml
                ./Components/Reusables/ColorTheme.qml
                ./Components/Reusables/Icon.qml
                ./Components/Reusables/CustomTextField.qml
                ./Components/Reusables/CustomSpinBox.qml
                ./Components/Reusables/CustomButton.qml
                ./Components/Reusables/CustomLink.qml
                ./Components/Reusables/CustomText.qml
                ./Components/Reusables/CustomTabView.qml
                ./Components/Reusables/CustomTabButton.qml
                ./Components/Reusables/CustomComboBox.qml
                ./Components/Reusables/AvatarGroup.qml
                ./Components/Reusables/RoundedButton.qml
                ./Components/Reusables/Circle.qml
                ./Components/Reusables/Avatar.qml
                ./Components/Reusables/QuaterCircle.qml
                ./Components/Reusables/AppLogo.qml
                ./Components/Reusables/AppLogoWithText.qml
                ./Components/Users/ContactList.qml
                ./Components/Users/ContactListItem.qml
                ./Components/Users/AddNewContact.qml
                ./Components/Calls/VoiceCallUserBox.qml
                ./Components/Calls/CallAnswerButton/CallAnswerButton.qml
                ./Components/Calls/CallAnswerButton/CallAnswerButtonAnimatedBorder.qml
                ./Components/Calls/CallPendingScreen.qml
                ./Components/Calls/CallPendingDots/CallPendingDot.qml
                ./Components/Calls/CallPendingDots/CallPendingDots.qml
                ./Components/Calls/CallFooter.qml
                ./Components/Calls/CallGrid.qml
                ./Components/Calls/CallHistory.qml
                ./Components/Calls/CallHistoryItem.qml
                ./Components/Calls/CallEnded.qml
                ./Components/Calls/IncomingCallPopup/IncomingCallPopup.qml
                ./Models/AppState.qml
                Resources.qrc
)

set_target_properties(appbjSip PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

#linking with pjsip lib and other dependent libs
target_link_libraries(appbjSip PRIVATE ${PJSIP_STATIC_LIBRARIES})
target_link_libraries(appbjSip PRIVATE Threads::Threads)
target_link_libraries(appbjSip PRIVATE OpenSSL::Crypto)
target_link_libraries(appbjSip PRIVATE OpenSSL::SSL)

target_link_libraries(appbjSip
    PRIVATE Qt6::Quick
)

install(TARGETS appbjSip
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

字符串
对于其他有类似问题的人,根据您的需要调整 cmake 文件,保持带有 PJSIP 变量的行。

相关问题