I'm building a C++ GStreamer project with CMake which depends on GStreamer, GLIB, Libsoup and json-glib. I'm new to CMake and having trouble setting up my project. I've managed to include many of the dependencies but some seem to remain unresolved even though they are part of GStreamer. All GStreamer methods and types are resolved with the exception of SDP and WebRTC. They are, to my understanding, part of GStreamer and are also located inside of the directory which GMake correctly "finds".
These are the errors that are occurring when trying to build the project.
[build] error LNK2019: unresolved external symbol __imp_gst_sdp_message_new referenced in function "void __cdecl soup_websocket_message_cb(struct _SoupWebsocketConnection *,enum SoupWebsocketDataType,struct _GBytes *,void *)" (?soup_websocket_message_cb##YAXPEAU_SoupWebsocketConnection##W4SoupWebsocketDataType##PEAU_GBytes##PEAX#Z)
[build] error LNK2019: unresolved external symbol __imp_gst_sdp_message_parse_buffer referenced in function "void __cdecl soup_websocket_message_cb(struct _SoupWebsocketConnection *,enum SoupWebsocketDataType,struct _GBytes *,void *)" (?soup_websocket_message_cb##YAXPEAU_SoupWebsocketConnection##W4SoupWebsocketDataType##PEAU_GBytes##PEAX#Z)
[build] error LNK2019: unresolved external symbol __imp_gst_sdp_message_as_text referenced in function "void __cdecl on_offer_created_cb(struct _GstPromise *,void *)" (?on_offer_created_cb##YAXPEAU_GstPromise##PEAX#Z)
[build] error LNK2019: unresolved external symbol __imp_gst_webrtc_session_description_get_type referenced in function "void __cdecl on_offer_created_cb(struct _GstPromise *,void *)" (?on_offer_created_cb##YAXPEAU_GstPromise##PEAX#Z)
[build] error LNK2019: unresolved external symbol __imp_gst_webrtc_session_description_new referenced in function "void __cdecl soup_websocket_message_cb(struct _SoupWebsocketConnection *,enum SoupWebsocketDataType,struct _GBytes *,void *)" (?soup_websocket_message_cb##YAXPEAU_SoupWebsocketConnection##W4SoupWebsocketDataType##PEAU_GBytes##PEAX#Z)
[build] error LNK2019: unresolved external symbol __imp_gst_webrtc_session_description_free referenced in function "void __cdecl on_offer_created_cb(struct _GstPromise *,void *)" (?on_offer_created_cb##YAXPEAU_GstPromise##PEAX#Z)
This is my CMakeLists.txt
# CMakeList.txt : CMake project for stream-project, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)
project (stream-project LANGUAGES CXX)
# Packages
find_package(PkgConfig REQUIRED)
# Add source to this project's executable.
add_executable (${PROJECT_NAME} "main.cpp" "main.h")
# Search all modules that we so desire to use and "include_directories"
pkg_search_module(GST REQUIRED gstreamer-1.0 gstreamer-sdp-1.0 gstreamer-video-1.0 gstreamer-app-1.0 gstreamer-webrtc-1.0)
pkg_search_module(GLIB REQUIRED glib-2.0)
pkg_search_module(LIBSOUP REQUIRED libsoup-2.4)
pkg_search_module(JSONGLIB REQUIRED json-glib-1.0)
include_directories(
${GST_INCLUDE_DIRS}
${GLIB_INCLUDE_DIRS}
${LIBSOUP_INCLUDE_DIRS}
${JSONGLIB_INCLUDE_DIRS}
)
# Link target directories and libraries
target_link_directories(${PROJECT_NAME} PRIVATE
${GST_LIBRARY_DIRS}
${GLIB_LIBRARY_DIRS}
${LIBSOUP_LIBRARY_DIRS}
${JSONGLIB_LIBRARY_DIRS}
)
target_link_libraries(${PROJECT_NAME} PRIVATE
${GST_LIBRARIES}
${GLIB_LIBRARIES}
${LIBSOUP_LIBRARIES}
${JSONGLIB_LIBRARIES}
)
message(STATUS ${GST_INCLUDE_DIRS})
I've managed to solve it by using a premade find script I found online.
https://chromium.googlesource.com/external/Webkit/+/master/Source/cmake/FindGStreamer.cmake
It creates all necessary defines which I then include and link.
These are the defaults as specified in the FindGStreamer.cmake file
FIND_GSTREAMER_COMPONENT(GSTREAMER_APP gstreamer-app-1.0 gst/app/gstappsink.h gstapp-1.0)
FIND_GSTREAMER_COMPONENT(GSTREAMER_AUDIO gstreamer-audio-1.0 gst/audio/audio.h gstaudio-1.0)
FIND_GSTREAMER_COMPONENT(GSTREAMER_FFT gstreamer-fft-1.0 gst/fft/gstfft.h gstfft-1.0)
FIND_GSTREAMER_COMPONENT(GSTREAMER_PBUTILS gstreamer-pbutils-1.0 gst/pbutils/pbutils.h gstpbutils-1.0)
FIND_GSTREAMER_COMPONENT(GSTREAMER_VIDEO gstreamer-video-1.0 gst/video/video.h gstvideo-1.0)
I extended those above with:
FIND_GSTREAMER_COMPONENT(GSTREAMER_SDP gstreamer-sdp-1.0 gst/sdp/sdp.h gstsdp-1.0)
FIND_GSTREAMER_COMPONENT(GSTREAMER_WEBRTC gstreamer-webrtc-1.0 gst/webrtc/webrtc.h gstwebrtc-1.0)
Related
So I've been trying to get started on opencv c++. I followed a tutorial on how to set it up, link here. I wrote a simple opencv script for an image display. I built the project after that and I got this error:
[build] main.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl cv::Mat::Mat(void)" (??0Mat#cv##QEAA#XZ) referenced in function main
[build] main.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl cv::Mat::~Mat(void)" (??1Mat#cv##QEAA#XZ) referenced in function main
[build] main.cpp.obj : error LNK2019: unresolved external symbol "public: class cv::Mat & __cdecl cv::Mat::operator=(class cv::Mat &&)" (??4Mat#cv##QEAAAEAV01#$$QEAV01##Z) referenced in function main
[build] mingw32-make[2]: *** [CMakeFiles\opencv.dir\build.make:152: opencv.exe] Error -1
[build] mingw32-make[1]: *** [CMakeFiles\Makefile2:838: CMakeFiles/opencv.dir/all] Error 2
[build] mingw32-make: *** [Makefile:120: all] Error 2
[build] main.cpp.obj : error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?imread#cv##YA?AVMat#1#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function main
[build] main.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?namedWindow#cv##YAXAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function main
[build] main.cpp.obj : error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey#cv##YAHH#Z) referenced in function main
[build] main.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::debug_build_guard::_InputArray const &)" (?imshow#cv##YAXAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AEBV_InputArray#debug_build_guard#1##Z) referenced in function main
[build] opencv.exe : fatal error LNK1120: 7 unresolved externals
I did some research but most of the answers were for Visual Studio users and I'm using vscode, not that. Here's how my CMakeLists.txt look like:
cmake_minimum_required(VERSION 3.0.0)
project(opencv VERSION 0.1.0)
include(CTest)
enable_testing()
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(opencv main.cpp)
target_link_libraries( opencv ${OpenCV_LIBS} )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
How can I fix this error and what was the cause of it? By the way, I'm using VS Build tools 2019.
Edit:
So I tried changing my Cmake kit to my usual compiler, MingW64 and the code seems to be compiling fine. The error only really happens with the Visual Studio C++ compiler. Why does it only happen to the VS compiler though?
i want to use taglib in my QT project on windows, so i build taglib and zlib from source like below:
cmake CMakeLists.txt
cmake --build --config release
cmake command uses visual studio compiler, i build zlib and taglib from source with above command with no error, i added their include and lib path to QT project .pro file like below:
INCLUDEPATH+=F:\project\TAGLIB\taglib\taglib F:\project\TAGLIB\taglib\taglib\toolkit F:\project\TAGLIB\taglib F:\project\zlib-1.2.11\Release F:\project\zlib-1.2.11
LIBS+=-LF:\project\zlib-1.2.11\Release -lzlib
LIBS+= -LF:\project\TAGLIB\taglib\taglib\Release -ltag
LIBS+=-LF:\project\TAGLIB\taglib\taglib\Debug -ltag
LIBS+=-LF:\project\zlib-1.2.11\Debug -lzlibd
and in main.cpp i added:
#include<fileref.h>
#include<tag.h>
#include<QDebug>
and in main function:
TagLib::FileRef f("C:\\Users\\sub\\Downloads\\Mohsen Chavoshi - Sharhe Alef.mp3");
TagLib::String artist = f.tag()->artist();
when i run my application in debug mode,it doesn't run and give me below errors:
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl TagLib::String::~String(void)" (__imp_??1String#TagLib##UEAA#XZ) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: char const * __cdecl TagLib::String::toCString(bool)const " (__imp_?toCString#String#TagLib##QEBAPEBD_N#Z) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl TagLib::FileName::FileName(char const *)" (__imp_??0FileName#TagLib##QEAA#PEBD#Z) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl TagLib::FileRef::FileRef(class TagLib::FileName,bool,enum TagLib::AudioProperties::ReadStyle)" (__imp_??0FileRef#TagLib##QEAA#VFileName#1#_NW4ReadStyle#AudioProperties#1##Z) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl TagLib::FileRef::~FileRef(void)" (__imp_??1FileRef#TagLib##UEAA#XZ) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: class TagLib::Tag * __cdecl TagLib::FileRef::tag(void)const " (__imp_?tag#FileRef#TagLib##QEBAPEAVTag#2#XZ) referenced in function main
debug\testTag2.exe:-1: error: LNK1120: 6 unresolved externals
but when i run application in Release mode,the above error are just some Warning and application run with no problem, why this is happening?
thank you.
I am trying to build a qt project using cmake. As a startinng point, I started off by just writing a simple code in qt creator, which contains main.cpp, mainwindow.cpp & mainwindow.h. Below are my CMakeLists.txt configuration.
cmake_minimum_required(VERSION 2.8.11)
project(testproject)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the QtWidgets library
find_package(Qt5Widgets)
find_package(Qt5Core)
get_target_property(QtCore_location Qt5::Core LOCATION)
# Tell CMake to create the executable
add_executable(testproject WIN32 main.cpp mainwindow.cpp)
# Use the Widgets module from Qt 5.
target_link_libraries(testproject Qt5::Widgets)
Cmake did successfully generate the VS Project files. However, when I try to build them in visual studio, it gives me linking errors. Some of the errors are listed below. I could not post the whole error list as it is too long.
>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QWidget::show(void)" (__imp_?show#QWidget##QEAAXXZ) referenced in function main
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QApplication::QApplication(int &,char * *,int)" (__imp_??0QApplication##QEAA#AEAHPEAPEADH#Z) referenced in function main
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl QApplication::~QApplication(void)" (__imp_??1QApplication##UEAA#XZ) referenced in function main
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl QApplication::exec(void)" (__imp_?exec#QApplication##SAHXZ) referenced in function main
2>mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QMetaObject::Connection::~Connection(void)" (__imp_??1Connection#QMetaObject##QEAA#XZ) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow##QEAA#PEAVQWidget###Z)
2>mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QString::~QString(void)" (__imp_??1QString##QEAA#XZ) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow##QEAA#PEAVQWidget###Z)
2>testproject_automoc.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual int __cdecl QMainWindow::qt_metacall(enum QMetaObject::Call,int,void * *)" (__imp_?qt_metacall#QMainWindow##UEAAHW4Call#QMetaObject##HPEAPEAX#Z) referenced in function "public: virtual int __cdecl MainWindow::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#MainWindow##UEAAHW4Call#QMetaObject##HPEAPEAX#Z)
2>testproject_automoc.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static struct QMetaObject const QMainWindow::staticMetaObject" (__imp_?staticMetaObject#QMainWindow##2UQMetaObject##B) referenced in function "void __cdecl `dynamic initializer for 'public: static struct QMetaObject const MainWindow::staticMetaObject''(void)" (??__E?staticMetaObject#MainWindow##2UQMetaObject##B##YAXXZ)
2>MSVCRT.lib(crtexew.obj) : error LNK2019: unresolved external symbol WinMain referenced in function __tmainCRTStartup
I am using Qt5.3.1, cmake 3.0.2 and visual studio 2012.
In order to fix this issue you have to remove the WIN32 statement from
add_executable(testproject WIN32 main.cpp mainwindow.cpp).
Possible causes:
Check the source file names in the add_executable command inside your CMakeLists.txt for spelling errors. File names in the source list that do not exist will produce the linker error error LNK2019: unresolved external symbol main referenced.
What does your entry point function look like?
WinMain requires add_executable(testproject WIN32 main.cpp mainwindow.cpp)
main requires add_executable(testproject main.cpp mainwindow.cpp)
Note: I suggest using int main(int argc, char *argv[]), as it will be portable to linux, while using WinMain won't.
I just ran into this error, I was using the x64-Debug configuration in Visual Studio, but the variable CMAKE_PREFIX_PATH in CMake was the path of x86 Qt, so the linker tried to link the x86 Qt libraries to the x64 program and the error occurred.
The solution is correcting the Visual Studio configuration and the Qt path to the same architecture.
You have to link against QtCore, you only link against Qt5::Widgets. Add Qt5::Core to your link libraries. At least for me, the CMake files don't include transitive dependencies (so linking against Qt5::Widgets is not enough.)
I am trying to add wxWidgets to my project using cmake.
in cmake I have:
#wxWidgets
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})
and for my project in cmake I have:
target_link_libraries(MyProject
${OpenCV_LIBS}
${wxWidgets_LIBRARIES}
${Boost_LIBRARIES})
and then run cmake using:
cmake -G "Visual Studio 11 Win64" ..
but when I compile the generated project in visual studio I am getting link error:
unresolved external symbol "public: __cdecl wxSplashScreen::wxSplashScreen(class wxBitmap const &,long,int,class wxWindow *,int,class wxPoint const &,class wxSize const &,long)" (??0wxSplashScreen##QEAA#AEBVwxBitmap##JHPEAVwxWindow##HAEBVwxPoint##AEBVwxSize##J#Z) referenced in function "public: __cdecl MainWindow::MainWindow(void)" (??0MainWindow##QEAA#XZ)
unresolved external symbol "public: virtual __cdecl wxSplashScreen::~wxSplashScreen(void)" (??1wxSplashScreen##UEAA#XZ) referenced in function "public: __cdecl MainWindow::MainWindow(void)" (??0MainWindow##QEAA#XZ)
unresolved external symbol main referenced in function __tmainCRTStartup
What is the problem and how can I fix it?
wxSplashScreen is part of the wxAdvanced library, so you need to tell cmake to link to that as well as core and base:
find_package(wxWidgets COMPONENTS core base adv REQUIRED)
I built libcurl and added it to project (specified include directory, library directory and library to use: libcurl.lib/libcurl_imp.lib - I both tried to compile and link static and dynamic library). In both cases (static/dynamic) I faced following:
1>tmp.obj : error LNK2019: unresolved external symbol _curl_easy_cleanup referenced in function "void __cdecl perform(char *)" (?perform##YAXPAD#Z)
1>tmp.obj : error LNK2019: unresolved external symbol _curl_easy_perform referenced in function "void __cdecl perform(char *)" (?perform##YAXPAD#Z)
1>tmp.obj : error LNK2019: unresolved external symbol _curl_easy_setopt referenced in function "void __cdecl perform(char *)" (?perform##YAXPAD#Z)
1>tmp.obj : error LNK2019: unresolved external symbol _curl_easy_init referenced in function "void __cdecl perform(char *)" (?perform##YAXPAD#Z)
1>C:\Users\Public\Documents\Project\curl-7.35.0\Debug\tmp.exe : fatal error LNK1120: 4 unresolved externals
All solutions I found was different variations of "add libcurl.lib".
Now just to clarify my configuration:
dynamic: include directory specified, library directory specified, libcurl_imp.lib specified as additional dependency, libcurl.dll copied to the directory where executable files should be generated.
static: include directory specified, library directory specified, libcurl.lib specified as additional dependency.
using vs2005
Well, it's silly but I was trying to use x64 library in x32 project.