Undefined reference to __imp__ZNK10QByteArray11toStdStringEv
-
Hi all, I am using QT6 Creator on Windows and struggling the following problem.
I am using CMake with QT and few libraries using Conan package manager. I am trying to build the project but facing error messages like these:
[49/50 1.6/sec] Linking CXX executable ElegiaApp.exe FAILED: ElegiaApp.exe cmd.exe /C "cd . && C:\msys64\mingw64\bin\g++.exe -D_GLIBCXX_USE_CXX11_ABI=0 -L D:/Study/University/Elegia/frontend/Elegia/backend/build/conanlibs -g -mwindows CMakeFiles/ElegiaApp.dir/ElegiaApp_autogen/mocs_compilation.cpp.obj CMakeFiles/ElegiaApp.dir/main.cpp.obj CMakeFiles/ElegiaApp.dir/MainWindow.cpp.obj CMakeFiles/ElegiaApp.dir/ElegiaApp_autogen/EWIEGA46WW/qrc_Images.cpp.obj -o ElegiaApp.exe -Wl,--out-implib,libElegiaApp.dll.a -Wl,--major-image-version,0,--minor-image-version,0 backend/lib/libutils.a backend/lib/libdata.a backend/lib/libelegia.a D:/Soft/Qt/6.4.0/mingw_64/lib/libQt6Widgets.a backend/lib/libdata.a backend/lib/libutils.a -lboost_contract -lboost_coroutine -lboost_context -lboost_graph -lboost_iostreams -lboost_log_setup -lboost_log -lboost_locale -lboost_math_c99 -lboost_math_c99f -lboost_math_c99l -lboost_math_tr1 -lboost_math_tr1f -lboost_math_tr1l -lboost_program_options -lboost_random -lboost_regex -lboost_timer -lboost_type_erasure -lboost_thread -lboost_atomic -lboost_chrono -lboost_container -lboost_date_time -lboost_exception -lboost_wave -lboost_filesystem -lboost_wserialization -lboost_serialization -lfmt -lz -lbz2 -lboost_contract -lboost_coroutine -lboost_context -lboost_graph -lboost_iostreams -lboost_log_setup -lboost_log -lboost_locale -lboost_math_c99 -lboost_math_c99f -lboost_math_c99l -lboost_math_tr1 -lboost_math_tr1f -lboost_math_tr1l -lboost_program_options -lboost_random -lboost_regex -lboost_timer -lboost_type_erasure -lboost_thread -lboost_atomic -lboost_chrono -lboost_container -lboost_date_time -lboost_exception -lboost_wave -lboost_filesystem -lboost_wserialization -lboost_serialization -lfmt -lz -lbz2 D:/Soft/Qt/6.4.0/mingw_64/lib/libQt6Gui.a D:/Soft/Qt/6.4.0/mingw_64/lib/libQt6Core.a -lmpr -luserenv -lmingw32 D:/Soft/Qt/6.4.0/mingw_64/lib/libQt6EntryPoint.a -lshell32 -ld3d11 -ldxgi -ldxguid -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/ElegiaApp.dir/MainWindow.cpp.obj: in function `QString::toStdString() const': D:/Soft/Qt/6.4.0/mingw_64/include/QtCore/qstring.h:1477: undefined reference to `__imp__ZNK10QByteArray11toStdStringEv' collect2.exe: error: ld returned 1 exit status
So that, I am using in the MainWindow.cpp file with the headers and the line where is toStdString() method used is:
#include "MainWindow.h" #include "./ui_mainwindow.h" #include <string> #include <QtCore/QByteArray> #include <QtCore/QString> #include "backend/elegia/include/NotesIdentifier.h" ... void MainWindow::on_nextButton_clicked() { QString selectedAnswer{ui->noteSelectorComboBox->currentText()}; // Here is the problem VVV const std::string stdString {selectedAnswer.toStdString()}; }
My CMakeLists.txt file:
cmake_minimum_required(VERSION 3.5) project(ElegiaApp VERSION 0.1 LANGUAGES CXX) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) ### Qt5 #find_package( Qt5Core REQUIRED) #find_package( Qt5Widgets REQUIRED ) #find_package( Qt5Gui REQUIRED ) #find_package( Qt5OpenGL REQUIRED ) #find_package( Qt5Multimedia REQUIRED ) #find_package( Qt5WebKitWidgets REQUIRED ) #find_package( Qt5Xml REQUIRED) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_PREFIX_PATH $ENV{QTDIR}) set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0 -L ${PROJECT_SOURCE_DIR}/backend/build/conanlibs") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) set(PROJECT_SOURCES main.cpp MainWindow.cpp MainWindow.h mainwindow.ui Images.qrc ) #qt5_add_resources(PROJECT_SOURCES Image.qrc) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(ElegiaApp MANUAL_FINALIZATION ${PROJECT_SOURCES} ) # Define target properties for Android with Qt 6 as: # set_property(TARGET ElegiaApp APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR # ${CMAKE_CURRENT_SOURCE_DIR}/android) # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation else() if(ANDROID) add_library(ElegiaApp SHARED ${PROJECT_SOURCES} ) # Define properties for Android with Qt 5 after find_package() calls as: # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") else() add_executable(ElegiaApp ${PROJECT_SOURCES} ) endif() endif() set_target_properties(ElegiaApp 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 ) install(TARGETS ElegiaApp BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(ElegiaApp) endif() add_subdirectory(backend) target_compile_features(ElegiaApp PUBLIC cxx_std_17) target_link_libraries(ElegiaApp PUBLIC elegia::utils elegia::data elegia::elegia PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core )
As you can see, I've tried including QByteArray but it did not help.
Could you please help? -
Hi
I was able to replicate this error on my end, and did some random experimenting, here's what I found:Removing the down below line from
CMakeLists.txt
gets rid of the error, and program ran fine:set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0 -L ${PROJECT_SOURCE_DIR}/backend/build/conanlibs")
Hope this helps you or someone else at narrowing down the causes of your problem.
here's my minimal reproducible example:
#include <QCoreApplication> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString selectedAnswer("df"); // Here is the problem VVV const std::string stdString {selectedAnswer.toStdString()}; qDebug()<<stdString; return a.exec(); }
cmake_minimum_required(VERSION 3.5) project(ElegiaApp VERSION 0.1 LANGUAGES CXX) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) ### Qt5 #find_package( Qt5Core REQUIRED) #find_package( Qt5Widgets REQUIRED ) #find_package( Qt5Gui REQUIRED ) #find_package( Qt5OpenGL REQUIRED ) #find_package( Qt5Multimedia REQUIRED ) #find_package( Qt5WebKitWidgets REQUIRED ) #find_package( Qt5Xml REQUIRED) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_PREFIX_PATH $ENV{QTDIR}) #set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0 -L ${PROJECT_SOURCE_DIR}/backend/build/conanlibs") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) set(PROJECT_SOURCES main.cpp ) #qt5_add_resources(PROJECT_SOURCES Image.qrc) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(ElegiaApp MANUAL_FINALIZATION ${PROJECT_SOURCES} ) # Define target properties for Android with Qt 6 as: # set_property(TARGET ElegiaApp APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR # ${CMAKE_CURRENT_SOURCE_DIR}/android) # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation else() if(ANDROID) add_library(ElegiaApp SHARED ${PROJECT_SOURCES} ) # Define properties for Android with Qt 5 after find_package() calls as: # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") else() add_executable(ElegiaApp ${PROJECT_SOURCES} ) endif() endif() set_target_properties(ElegiaApp 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 ) install(TARGETS ElegiaApp BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(ElegiaApp) endif() target_compile_features(ElegiaApp PUBLIC cxx_std_17) target_link_libraries(ElegiaApp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core )
Good luck!
-
Hi
I was able to replicate this error on my end, and did some random experimenting, here's what I found:Removing the down below line from
CMakeLists.txt
gets rid of the error, and program ran fine:set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0 -L ${PROJECT_SOURCE_DIR}/backend/build/conanlibs")
Hope this helps you or someone else at narrowing down the causes of your problem.
here's my minimal reproducible example:
#include <QCoreApplication> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString selectedAnswer("df"); // Here is the problem VVV const std::string stdString {selectedAnswer.toStdString()}; qDebug()<<stdString; return a.exec(); }
cmake_minimum_required(VERSION 3.5) project(ElegiaApp VERSION 0.1 LANGUAGES CXX) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) ### Qt5 #find_package( Qt5Core REQUIRED) #find_package( Qt5Widgets REQUIRED ) #find_package( Qt5Gui REQUIRED ) #find_package( Qt5OpenGL REQUIRED ) #find_package( Qt5Multimedia REQUIRED ) #find_package( Qt5WebKitWidgets REQUIRED ) #find_package( Qt5Xml REQUIRED) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_PREFIX_PATH $ENV{QTDIR}) #set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0 -L ${PROJECT_SOURCE_DIR}/backend/build/conanlibs") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) set(PROJECT_SOURCES main.cpp ) #qt5_add_resources(PROJECT_SOURCES Image.qrc) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(ElegiaApp MANUAL_FINALIZATION ${PROJECT_SOURCES} ) # Define target properties for Android with Qt 6 as: # set_property(TARGET ElegiaApp APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR # ${CMAKE_CURRENT_SOURCE_DIR}/android) # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation else() if(ANDROID) add_library(ElegiaApp SHARED ${PROJECT_SOURCES} ) # Define properties for Android with Qt 5 after find_package() calls as: # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") else() add_executable(ElegiaApp ${PROJECT_SOURCES} ) endif() endif() set_target_properties(ElegiaApp 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 ) install(TARGETS ElegiaApp BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(ElegiaApp) endif() target_compile_features(ElegiaApp PUBLIC cxx_std_17) target_link_libraries(ElegiaApp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core )
Good luck!
@Abderrahmene_Rayene said in Undefined reference to __imp__ZNK10QByteArray11toStdStringEv:
"-D_GLIBCXX_USE_CXX11_ABI=0
This forces the compile to use the old pre c++11 ABI so yes, it was wrong.
-
Thanks guys a lot for your feedback! I did the thing with removing
-D_GLIBCXX_USE_CXX11_ABI=0
flag and now it compiles! Thanks!
But could you also suggest what can I do with
-L ${PROJECT_SOURCE_DIR}/backend/build/conanlibs
option?
Without defining that, my libraries downloaded through conan won't link but they are seen by backend modules (actually, I am using QT as frontend repository and my C+++ logic module as backend repository, which uses these conan libs like boost, fmt and others...)
So I mean the situation like this will happen:FAILED: ElegiaApp.exe cmd.exe /C "cd . && C:\msys64\mingw64\bin\g++.exe -g -mwindows CMakeFiles/ElegiaApp.dir/ElegiaApp_autogen/mocs_compilation.cpp.obj CMakeFiles/ElegiaApp.dir/main.cpp.obj CMakeFiles/ElegiaApp.dir/MainWindow.cpp.obj CMakeFiles/ElegiaApp.dir/ElegiaApp_autogen/EWIEGA46WW/qrc_Images.cpp.obj -o ElegiaApp.exe -Wl,--out-implib,libElegiaApp.dll.a -Wl,--major-image-version,0,--minor-image-version,0 backend/lib/libutils.a backend/lib/libdata.a backend/lib/libelegia.a D:/Soft/Qt/6.4.0/mingw_64/lib/libQt6Widgets.a backend/lib/libdata.a backend/lib/libutils.a -lboost_contract -lboost_coroutine -lboost_context -lboost_graph -lboost_iostreams -lboost_log_setup -lboost_log -lboost_locale -lboost_math_c99 -lboost_math_c99f -lboost_math_c99l -lboost_math_tr1 -lboost_math_tr1f -lboost_math_tr1l -lboost_program_options -lboost_random -lboost_regex -lboost_timer -lboost_type_erasure -lboost_thread -lboost_atomic -lboost_chrono -lboost_container -lboost_date_time -lboost_exception -lboost_wave -lboost_filesystem -lboost_wserialization -lboost_serialization -lfmt -lz -lbz2 -lboost_contract -lboost_coroutine -lboost_context -lboost_graph -lboost_iostreams -lboost_log_setup -lboost_log -lboost_locale -lboost_math_c99 -lboost_math_c99f -lboost_math_c99l -lboost_math_tr1 -lboost_math_tr1f -lboost_math_tr1l -lboost_program_options -lboost_random -lboost_regex -lboost_timer -lboost_type_erasure -lboost_thread -lboost_atomic -lboost_chrono -lboost_container -lboost_date_time -lboost_exception -lboost_wave -lboost_filesystem -lboost_wserialization -lboost_serialization -lfmt -lz -lbz2 D:/Soft/Qt/6.4.0/mingw_64/lib/libQt6Gui.a D:/Soft/Qt/6.4.0/mingw_64/lib/libQt6Core.a -lmpr -luserenv -lmingw32 D:/Soft/Qt/6.4.0/mingw_64/lib/libQt6EntryPoint.a -lshell32 -ld3d11 -ldxgi -ldxguid -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_contract: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_coroutine: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_context: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_graph: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_iostreams: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_log_setup: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_log: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_locale: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_math_c99: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_math_c99f: No such file or directory ... ... other related libraries errors ... ... C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_wave: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_filesystem: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_wserialization: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_serialization: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lfmt: No such file or directory collect2.exe: error: ld returned 1 exit status [35/40 1.1/sec] Building CXX object backend/test/CMakeFiles/unit_tests.dir/cmake_pch.hxx.gch ninja: build stopped: subcommand failed. 10:39:39: The process "C:\msys64\mingw64\bin\cmake.exe" exited with code 1. Error while building/deploying project ElegiaApp (kit: Clone of Desktop Qt 6.4.0 MinGW 12.2 64-bit) When executing step "Build"
Maybe there is some another better method to link them?
In any case, thanks with resolving the main issue!
-
-