我正在尝试在 Qt Creator 中构建 voip 应用程序。我在 C++ 方面没有太多经验。我安装了 Qt 并构建并安装了 pjproject 库。我用 pkgconfig 添加了 pjproject 库,如下所示
这里是源代码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 文件,其中包含适合我的项目的完美骨架代码,因此我将代码从该文件复制到了项目的主文件中。
这是我得到的错误:
以下是一些错误行:
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):在函数
spx_codec_decode': speex_codec.c:-1: error: undefined reference to
speex_bits_read_from'中
:-1:错误:/usr/local/lib/libpjmedia-audiodev-x86_64-unknown-linux-gnu.a(alsa_dev.o):在函数
alsa_factory_refresh': alsa_dev.c:-1: error: undefined reference to
snd_device_name_hint'
...
我尝试运行编译版本的pjsua2_demo.cpp,一切正常。 pjproject 目录内的可执行位置./pjsip-apps/bin/samples/x86_64-unknown-linux-gnu。我怀疑问题在于包含库并将其链接到项目,但我不知道该怎么做。
提前致谢。
我还没有找到 .pro 构建文件的解决方案,所以我决定尝试使用 cmake。我在 this Stackoverflow Question 上找到了解决方案,并将其与 tsyvarev 用户的评论结合起来。
这是我的项目中的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 变量的行。