0

I am trying to include MuParser in my Qt Creator project, but I have been struggling for quite a while to get it working properly.

Where I am now, it appears to be unable to find several symbols in the MuParser library for whatever reason, and I am not really sure what to do about this. Does anyone have any idea what I might want to do to resolve this?

I downloaded the source code as a .zip file from the official website. After extracting the contents, I added a "build" directory to the folder. In MSYS2 MINGW64, I ran

cd (path to muparser folder)/build
cmake .. -DENABLE_SAMPLES=ON -DENABLE_OPENMP=ON -DENABLE_WIDE_CHAR=OFF -DBUILD_SHARED_LIBS=OFF
make

from the build directory. This produced the static library "libmuparser.a".

I added this file, along with the headers, into my project folder in the following file structure:

(Project File)->libs->muparser->lib->libmuparser.a
(Project File)->libs->muparser->include->(MuParser Header Files)

Then, in my .pro file, I added

INCLUDEPATH += $$PWD/libs/muparser/include
LIBS += -L$$PWD/libs/muparser/lib -lmuparser

However, when I attempt to build the project, I get the following error messages:

collect2.exe:-1: error: ld returned 1 exit status
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: debug/main.o: in function `qMain(int, char**)':
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: debug/main.o: in function `mu::Parser::~Parser()':
collect2.exe: error: ld returned 1 exit status
C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\main.cpp:16: error: undefined reference to `__imp__ZN2mu6ParserC1Ev'
:-1: error: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\build\Desktop_Qt_6_7_2_MinGW_64_bit-Debug/../../main.cpp:17: undefined reference to `__imp__ZN2mu10ParserBase9DefineVarERKNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEEPd'
:-1: error: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\build\Desktop_Qt_6_7_2_MinGW_64_bit-Debug/../../main.cpp:18: undefined reference to `__imp__ZN2mu10ParserBase7SetExprERKNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEE'
:-1: error: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\build\Desktop_Qt_6_7_2_MinGW_64_bit-Debug/../../main.cpp:20: undefined reference to `__imp__ZNK2mu10ParserBase4EvalEv'
C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\include\muParser.h:50: error: undefined reference to `__imp__ZTVN2mu6ParserE'
:-1: error: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\build\Desktop_Qt_6_7_2_MinGW_64_bit-Debug/../../libs/muparser/include/muParser.h:50: undefined reference to `__imp__ZN2mu10ParserBaseD2Ev'
:-1: error: [Makefile.Debug:72: debug/TestMuParser.exe] Error 1
Error while building\deploying project TestMuParser (kit:-1: Desktop Qt 6.7.2 MinGW 64-bit)

As stated before, it appears unable to locate several MuParser library symbols, for whatever reason, though I have not edited any of the header files from how they were downloaded. Could this be an issue with the build of libmuparser.a?

EDIT It was suggested to remove the previous update with my additional errors and locate the linkage command that caused my initial errors. While I am not seeing any command with the exact form of /some/path/x86_64-w64-mingw32-g++ -o debug/TestMuParser.exe..., I do see some similar looking lines. Are any of these the linker command? Particularly, the first line of the fourth box below looks as though it may be the linker command.

C:/Qt/Tools/mingw1120_64/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/Aidan Beecher/Desktop/Qt 
Projects/TestMuParser/build/Desktop_Qt_6_7_2_MinGW_64_bit-Debug'
g++ -c -fno-keep-inline-dllexport -g -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -
DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_QML_DEBUG -DQT_WIDGETS_LIB -
DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../../../TestMuParser -I. -
I../../libs/muparser/include -IC:/Qt/6.7.2/mingw_64/include -
IC:/Qt/6.7.2/mingw_64/include/QtWidgets -IC:/Qt/6.7.2/mingw_64/include/QtGui -
IC:/Qt/6.7.2/mingw_64/include/QtCore -Idebug -I. -IC:/VulkanSDK/1.3.290.0/include -
IC:/Qt/6.7.2/mingw_64/mkspecs/win32-g++  -o debug\main.o ..\..\main.cpp
g++ -Wl,-v -Wl,-subsystem,windows -mthreads -o debug\TestMuParser.exe debug/main.o 
debug/mainwindow.o debug/moc_mainwindow.o -L"C:\Users\Aidan Beecher\Desktop\Qt 
Projects\TestMuParser\libs\muparser\lib" -lmuparser C:\Qt\6.7.2\mingw_64\lib\libQt6Widgets.a 
C:\Qt\6.7.2\mingw_64\lib\libQt6Gui.a C:\Qt\6.7.2\mingw_64\lib\libQt6Core.a -lmingw32 
C:\Qt\6.7.2\mingw_64\lib\libQt6EntryPoint.a -lshell32  

EDIT 2 If I understand Mike Kinghan's answer correctly, if I wish to use the static library libmuparser.a in my code, I need to add DEFINES += MUPARSER_STATIC to my .pro file. Doing this seems to have resolved the previous errors, yet I am now getting new errors:

:-1: error: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\lib/libmuparser.a(muParserBase.cpp.o):muParserBase.c:(.text+0x87c0): undefined reference to `omp_get_num_threads'
:-1: error: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\lib/libmuparser.a(muParserBase.cpp.o):muParserBase.c:(.text+0x87c8): undefined reference to `omp_get_thread_num'
:-1: error: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\lib/libmuparser.a(muParserBase.cpp.o):muParserBase.c:(.text+0x10d37): undefined reference to `omp_get_max_threads'
:-1: error: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\lib/libmuparser.a(muParserBase.cpp.o):muParserBase.c:(.text+0x10d4a): undefined reference to `omp_set_num_threads'
:-1: error: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\lib/libmuparser.a(muParserBase.cpp.o):muParserBase.c:(.text+0x10d73): undefined reference to `GOMP_parallel'
collect2.exe:-1: error: ld returned 1 exit status
:-1: error: [Makefile.Debug:72: debug/TestMuParser.exe] Error 1

If I try to build the library as a shared library:

cmake .. -DENABLE_SAMPLES=ON -DENABLE_OPENMP=OFF -DENABLE_WIDE_CHAR=OFF -DBUILD_SHARED_LIBS=ON

I get

libmuparser.dll.a
msys-muparser-2.dll

but not libmuparser.dll. Should I simply rename the .dll file I do get, or is this not the correct file?

Let me include the full compile output, in case it helps:

14:12:02: Running steps for project TestMuParser...
14:12:02: Starting: "C:\Qt\6.7.2\mingw_64\bin\qmake.exe" "C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\TestMuParser.pro" -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
14:12:03: The process "C:\Qt\6.7.2\mingw_64\bin\qmake.exe" exited normally.
14:12:03: Starting: "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" -f "C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParser/build/Desktop_Qt_6_7_2_MinGW_64_bit-Debug/Makefile" qmake_all
mingw32-make: Nothing to be done for 'qmake_all'.
14:12:03: The process "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" exited normally.
14:12:03: Starting: "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" -j16
C:/Qt/Tools/mingw1120_64/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParser/build/Desktop_Qt_6_7_2_MinGW_64_bit-Debug'
C:\Qt\6.7.2\mingw_64\bin\uic.exe ..\..\mainwindow.ui -o ui_mainwindow.h
g++ -c -g -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DMUPARSER_STATIC -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../../../TestMuParser -I. -I../../libs/muparser/include -IC:/Qt/6.7.2/mingw_64/include -IC:/Qt/6.7.2/mingw_64/include/QtWidgets -IC:/Qt/6.7.2/mingw_64/include/QtGui -IC:/Qt/6.7.2/mingw_64/include/QtCore -Idebug -I. -IC:/VulkanSDK/1.3.290.0/include -IC:/Qt/6.7.2/mingw_64/mkspecs/win32-g++  -o debug\main.o ..\..\main.cpp
g++ -c -g -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DMUPARSER_STATIC -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../../../TestMuParser -I. -I../../libs/muparser/include -IC:/Qt/6.7.2/mingw_64/include -IC:/Qt/6.7.2/mingw_64/include/QtWidgets -IC:/Qt/6.7.2/mingw_64/include/QtGui -IC:/Qt/6.7.2/mingw_64/include/QtCore -Idebug -I. -IC:/VulkanSDK/1.3.290.0/include -IC:/Qt/6.7.2/mingw_64/mkspecs/win32-g++  -o debug\mainwindow.o ..\..\mainwindow.cpp
g++ -g -std=gnu++1z -Wall -Wextra -Wextra -dM -E -o debug\moc_predefs.h C:\Qt\6.7.2\mingw_64\mkspecs\features\data\dummy.cpp
C:\Qt\6.7.2\mingw_64\bin\moc.exe -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DMUPARSER_STATIC -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN --include "C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParser/build/Desktop_Qt_6_7_2_MinGW_64_bit-Debug/debug/moc_predefs.h" -IC:/Qt/6.7.2/mingw_64/mkspecs/win32-g++ -I"C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParser" -I"C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParser/libs/muparser/include" -IC:/Qt/6.7.2/mingw_64/include -IC:/Qt/6.7.2/mingw_64/include/QtWidgets -IC:/Qt/6.7.2/mingw_64/include/QtGui -IC:/Qt/6.7.2/mingw_64/include/QtCore -I. -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++ -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/x86_64-w64-mingw32 -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/backward -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include-fixed -IC:/Qt/Tools/mingw1120_64/x86_64-w64-mingw32/include ..\..\mainwindow.h -o debug\moc_mainwindow.cpp
g++ -c -g -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DMUPARSER_STATIC -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../../../TestMuParser -I. -I../../libs/muparser/include -IC:/Qt/6.7.2/mingw_64/include -IC:/Qt/6.7.2/mingw_64/include/QtWidgets -IC:/Qt/6.7.2/mingw_64/include/QtGui -IC:/Qt/6.7.2/mingw_64/include/QtCore -Idebug -I. -IC:/VulkanSDK/1.3.290.0/include -IC:/Qt/6.7.2/mingw_64/mkspecs/win32-g++  -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp
..\..\mainwindow.cpp: In member function 'void MainWindow::on_enterFormula_textChanged(const QString&)':
..\..\mainwindow.cpp:16:61: warning: unused parameter 'arg1' [-Wunused-parameter]
   16 | void MainWindow::on_enterFormula_textChanged(const QString &arg1)
      |                                              ~~~~~~~~~~~~~~~^~~~
..\..\main.cpp: In function 'int qMain(int, char**)':
..\..\main.cpp:15:12: warning: unused variable 'var_a' [-Wunused-variable]
   15 |     double var_a = 1;
      |            ^~~~~
g++ -Wl,-v -Wl,-subsystem,windows -mthreads -o debug\TestMuParser.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -L"C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\lib" -lmuparser C:\Qt\6.7.2\mingw_64\lib\libQt6Widgets.a C:\Qt\6.7.2\mingw_64\lib\libQt6Gui.a C:\Qt\6.7.2\mingw_64\lib\libQt6Core.a -lmingw32 C:\Qt\6.7.2\mingw_64\lib\libQt6EntryPoint.a -lshell32  
collect2 version 11.2.0
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe -plugin C:/Qt/Tools/mingw1120_64/bin/../libexec/gcc/x86_64-w64-mingw32/11.2.0/liblto_plugin.dll -plugin-opt=C:/Qt/Tools/mingw1120_64/bin/../libexec/gcc/x86_64-w64-mingw32/11.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\Aidan Beecher\AppData\Local\Temp\ccrwpgSI.res -plugin-opt=-pass-through=-lmingwthrd -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-liconv -plugin-opt=-pass-through=-lmingwthrd -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 --sysroot=D:/a/mingw-builds/mingw-builds/buildroot/x86_64-1120-posix-seh-rt_v9-rev3/mingw64 -m i386pep -Bdynamic -o debug\TestMuParser.exe C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/crtbegin.o -LC:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\lib -LC:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0 -LC:/Qt/Tools/mingw1120_64/bin/../lib/gcc -LC:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib -LC:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../lib -LC:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib -LC:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../.. -v -subsystem windows debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -lmuparser C:\Qt\6.7.2\mingw_64\lib\libQt6Widgets.a C:\Qt\6.7.2\mingw_64\lib\libQt6Gui.a C:\Qt\6.7.2\mingw_64\lib\libQt6Core.a -lmingw32 C:\Qt\6.7.2\mingw_64\lib\libQt6EntryPoint.a -lshell32 -lstdc++ -lmingwthrd -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lkernel32 -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -liconv -lmingwthrd -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lkernel32 C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/crtend.o
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\lib/libmuparser.a(muParserBase.cpp.o):muParserBase.c:(.text+0x87c0): undefined reference to `omp_get_num_threads'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\lib/libmuparser.a(muParserBase.cpp.o):muParserBase.c:(.text+0x87c8): undefined reference to `omp_get_thread_num'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\lib/libmuparser.a(muParserBase.cpp.o):muParserBase.c:(.text+0x10d37): undefined reference to `omp_get_max_threads'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\lib/libmuparser.a(muParserBase.cpp.o):muParserBase.c:(.text+0x10d4a): undefined reference to `omp_set_num_threads'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParser\libs\muparser\lib/libmuparser.a(muParserBase.cpp.o):muParserBase.c:(.text+0x10d73): undefined reference to `GOMP_parallel'
GNU ld (GNU Binutils) 2.37
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Makefile.Debug:72: debug/TestMuParser.exe] Error 1
mingw32-make: *** [Makefile:45: debug] Error 2
mingw32-make[1]: Leaving directory 'C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParser/build/Desktop_Qt_6_7_2_MinGW_64_bit-Debug'
14:12:05: The process "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project TestMuParser (kit: Desktop Qt 6.7.2 MinGW 64-bit)
When executing step "Make"
14:12:05: Elapsed time: 00:03.

EDIT 3 Further suggestions did not resolve the issue. I attempted to see if using a different version of MuParser might fix things. Specifically, I downloaded MuParserX:

git clone https://github.com/beltoforion/muparserx.git

Building this into a static library (libmuparserx.a), I actually managed to get it working in Visual Studio Code. I wrote a sample code and it ran without an issue.

Weirdly, however, when I created an identical project in Qt Creator, it failed, giving the following errors:

:-1: error: CMakeFiles/Test.dir/main.cpp.obj:C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:7: undefined reference to `mup::ParserX::ParserX(unsigned int)'
collect2.exe:-1: error: ld returned 1 exit status
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/Test.dir/main.cpp.obj: in function `main':
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/Test.dir/main.cpp.obj: in function `mup::ParserX::~ParserX()':
collect2.exe: error: ld returned 1 exit status
C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParserX\main.cpp:8: error: undefined reference to `mup::Value::Value(double)'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:9: undefined reference to `mup::Variable::Variable(mup::IValue*)'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:10: undefined reference to `mup::ParserXBase::DefineVar(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, mup::Variable const&)'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:12: undefined reference to `mup::ParserXBase::DefineConst(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, mup::Value const&)'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:13: undefined reference to `mup::Value::Value(double)'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:13: undefined reference to `mup::ParserXBase::DefineConst(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, mup::Value const&)'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:13: undefined reference to `mup::Value::~Value()'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:15: undefined reference to `mup::ParserXBase::SetExpr(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:16: undefined reference to `mup::ParserXBase::Eval() const'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:16: undefined reference to `mup::Value::Value(mup::IValue const&)'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:18: undefined reference to `mup::operator<<(std::ostream&, mup::IValue const&)'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:19: undefined reference to `mup::Value::~Value()'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:19: undefined reference to `mup::Variable::~Variable()'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:19: undefined reference to `mup::Value::~Value()'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:13: undefined reference to `mup::Value::~Value()'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:19: undefined reference to `mup::Value::~Value()'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:19: undefined reference to `mup::Variable::~Variable()'
:-1: error: C:/Users/Aidan Beecher/Desktop/Qt Projects/TestMuParserX/main.cpp:19: undefined reference to `mup::Value::~Value()'
C:\Users\Aidan Beecher\Desktop\Qt Projects\TestMuParserX\libs\muparserx\include\mpParser.h:52: error: undefined reference to `mup::ParserXBase::~ParserXBase()'
:-1: error: ninja: build stopped: subcommand failed.

It seems then that it must be an issue with how the Qt Creator IDE is configured. However, I am unsure what settings might need to be changed, so please let me know what information would be useful to diagnose this issue. I should clarify that I have switched my projects over to CMake in light of realizing that this worked in VSCode.

1 Answer 1

2

You have built muparser as a static library only:

cmake .. -DENABLE_SAMPLES=ON -DENABLE_OPENMP=ON \
    -DENABLE_WIDE_CHAR=OFF -DBUILD_SHARED_LIBS=OFF
                            ^^^^^^^^^^^^^^^^^^^^^^

giving you the archive that you copied into your project as:

project/libs/muparser/lib/libmuparser.a

But you have built your target debug\TestMuParser.exe with the (default) assumption that muparser is a shared library/DLL. Consequently the compiler generates references to symbols like:

undefined reference to `__imp__ZN2mu6ParserC1Ev'
undefined reference to `__imp__ZN2mu10ParserBase9DefineVarERKNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEEPd'
undefined reference to `__imp__ZN2mu10ParserBase7SetExprERKNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEE'
undefined reference to `__imp__ZNK2mu10ParserBase4EvalEv'

in which the __imp_ ( = import) prefix signifies that the referenced symbols are dynamic symbols - symbols to be prefixed __declspec(dllimport) in the pre-processed source code - that are defined in the import library of the muparser DLL, neither of which you have built.

If you had not specified -DBUILD_SHARED_LIBS=OFF when you built muparser, then instead of libmuparser.a you would have built:

libmuparser.dll     # the DLL
libmuparser.dll.a   # its import library.

and if you had copied these to project/libs/muparser/lib/libmuparser then the linkage would have succeeded - although for your program to run when installed somewhere in your runtime PATH, you would then need to ensure that libmuparser.dll is also found by the dynamic linker per the Windows Dynamic-link Library Search Order.

Since all of your QT libraries are also static it appears that you intend to build a (largely) static application, including a static libmuparser. In that case you will need to direct your compiler not to generate dynamic references to the symbols of libmuparser, but just regular ones for static linkage.

The way to do that is to specify the preprocessor flag:

-DMUPARSER_STATIC

to g++ when you compile you source code, which signifies to the compiler that a static libmuparser will be linked. This fact is not mentioned in the documention - :) - either at the muparser website or at the the github repo, but you can discover it in the source code.

You will need to add:

DEFINES += MUPARSER_STATIC

to your QT project file to have -DMUPARSER_STATIC added to the compiler commandline.

Update for further difficulties

Snag 1

  • When you try to link your application against the static libmuparser.a you get new undefined references:

    undefined reference to `omp_get_num_threads'
    undefined reference to `omp_get_thread_num'
    undefined reference to `omp_get_max_threads'
    undefined reference to `omp_set_num_threads'
    

Snag 2

  • When you rebuild muparser with CMake as a DLL, instead of building import library libmuparser.dll.a and DLL libmuparser.dll, you get import library libmuparser.dll.a but DLL msys-muparser-2.dll.

I do not reproduce either of these snags.

About Snag 1

Now that you have succeeded in getting libmuparser.a input to the linkage of your app, the definitions of the muparser symbols have been found by the linker and those definitions have introduced references to those omp_* symbols, which are defined in the GNU Open Multi-Processing runtime library libgomp. But the linker does not find definitions of those. There are a number of possible explanations for this, all of them in the "should not happen" category; some involving things you might have done that I'm unaware of; some involving characteristics of your mingw_64 GCC installation that I'm unaware of.

These symbols are referenced because you configured the CMake build of libmuparser.a to enable the use of OpenMP shared-memory multi-processing, as per:

cmake .. -DENABLE_SAMPLES=ON -DENABLE_OPENMP=ON -DENABLE_WIDE_CHAR=OFF -DBUILD_SHARED_LIBS=OFF
                              ^^^^^^^^^^^^^^^^^                          

When I do the same:

imkin@MikesInspiron MINGW64 /c/Users/imkin/so/muparser
$ mkdir build

imkin@MikesInspiron MINGW64 /c/Users/imkin/so/muparser
$ cd build

imkin@MikesInspiron MINGW64 /c/Users/imkin/so/muparser/build
$ cmake -G 'MSYS Makefiles' -DENABLE_SAMPLES=ON -DENABLE_OPENMP=ON -DENABLE_WIDE_CHAR=OFF -DBUILD_SHARED_LIBS=OFF ..
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Configuring done (6.5s)
-- Generating done (0.2s)
-- Build files have been written to: C:/Users/imkin/so/muparser/build

imkin@MikesInspiron MINGW64 /c/Users/imkin/so/muparser/build
$ make
[  6%] Building CXX object CMakeFiles/muparser.dir/src/muParser.cpp.obj
[ 12%] Building CXX object CMakeFiles/muparser.dir/src/muParserBase.cpp.obj
[ 18%] Building CXX object CMakeFiles/muparser.dir/src/muParserBytecode.cpp.obj
[ 25%] Building CXX object CMakeFiles/muparser.dir/src/muParserCallback.cpp.obj
[ 31%] Building CXX object CMakeFiles/muparser.dir/src/muParserDLL.cpp.obj
[ 37%] Building CXX object CMakeFiles/muparser.dir/src/muParserError.cpp.obj
[ 43%] Building CXX object CMakeFiles/muparser.dir/src/muParserInt.cpp.obj
[ 50%] Building CXX object CMakeFiles/muparser.dir/src/muParserTest.cpp.obj
[ 56%] Building CXX object CMakeFiles/muparser.dir/src/muParserTokenReader.cpp.obj
[ 62%] Linking CXX static library libmuparser.a
[ 62%] Built target muparser
[ 68%] Building CXX object CMakeFiles/example1.dir/samples/example1/example1.cpp.obj
[ 75%] Linking CXX executable example1.exe
[ 75%] Built target example1
[ 81%] Building C object CMakeFiles/example2.dir/samples/example2/example2.c.obj
[ 87%] Linking CXX executable example2.exe
[ 87%] Built target example2
[ 93%] Building CXX object CMakeFiles/t_ParserTest.dir/test/t_ParserTest.cpp.obj
[100%] Linking CXX executable t_ParserTest.exe
[100%] Built target t_ParserTest

both of the examples build without linkage errors (and run without problems) and it can be seen that all of the problem omp_* symbols are statically defined in them:

$ nm example1.exe | grep omp
0000000140057a20 I __imp_omp_get_max_threads
0000000140057a28 I __imp_omp_get_num_threads
0000000140057a30 I __imp_omp_get_thread_num
0000000140057a38 I __imp_omp_set_num_threads
0000000140057050 I _head_libgomp_1_dll
000000014000c1e0 t _ZN2mu10ParserBase4EvalEPdi._omp_fn.0
0000000140006150 t _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareERKS4_.isra.0
0000000140059014 I libgomp_1_dll_iname
0000000140038a78 T omp_get_max_threads
0000000140038a70 T omp_get_num_threads
0000000140038a68 T omp_get_thread_num
0000000140038a60 T omp_set_num_threads

as signified by T omp_*.

Taking a step back, I think you probably did not have any settled reason for configuring the build of libmuparser.a with -DENABLE_OPENMP=ON. I think that because when you subsequently rebuilt muparser as a DLL, you configured:

cmake .. -DENABLE_SAMPLES=ON -DENABLE_OPENMP=OFF -DENABLE_WIDE_CHAR=OFF -DBUILD_SHARED_LIBS=ON
                             ^^^^^^^^^^^^^^^^^^^
                             

This means we do not know, from the posted information, whether or not the same omp_* undefined references would appear in the linkage of your application if muparser was linked with it as a DLL, with OpenMP enabled. But if you want or prefer to link it as a static library, then I suggest that you rebuild muparser from scratch (delete the CMake build dir; delete the CMakeCache.txt, if it exists, in the muparser directory), and this time just accept the defaults except for requesting a static library. I.e. configure with:

$ cmake -DBUILD_SHARED_LIBS=OFF ..

Then try again to link the static library with your application as before.

About Snag 2

I cannot account for your msys-muparser-2.dll. When I build the DLL (per default):

imkin@MikesInspiron MINGW64 /c/Users/imkin/so/muparser/build
$ rm -fr *

imkin@MikesInspiron MINGW64 /c/Users/imkin/so/muparser/build
$ cmake -G 'MSYS Makefiles' ..
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Configuring done (5.8s)
-- Generating done (0.2s)
-- Build files have been written to: C:/Users/imkin/so/muparser/build

imkin@MikesInspiron MINGW64 /c/Users/imkin/so/muparser/build
$ make
[  6%] Building CXX object CMakeFiles/muparser.dir/src/muParser.cpp.obj
[ 12%] Building CXX object CMakeFiles/muparser.dir/src/muParserBase.cpp.obj
[ 18%] Building CXX object CMakeFiles/muparser.dir/src/muParserBytecode.cpp.obj
[ 25%] Building CXX object CMakeFiles/muparser.dir/src/muParserCallback.cpp.obj
[ 31%] Building CXX object CMakeFiles/muparser.dir/src/muParserDLL.cpp.obj
[ 37%] Building CXX object CMakeFiles/muparser.dir/src/muParserError.cpp.obj
[ 43%] Building CXX object CMakeFiles/muparser.dir/src/muParserInt.cpp.obj
[ 50%] Building CXX object CMakeFiles/muparser.dir/src/muParserTest.cpp.obj
[ 56%] Building CXX object CMakeFiles/muparser.dir/src/muParserTokenReader.cpp.obj
[ 62%] Linking CXX shared library libmuparser.dll
[ 62%] Built target muparser
[ 68%] Building CXX object CMakeFiles/example1.dir/samples/example1/example1.cpp.obj
[ 75%] Linking CXX executable example1.exe
[ 75%] Built target example1
[ 81%] Building C object CMakeFiles/example2.dir/samples/example2/example2.c.obj
[ 87%] Linking C executable example2.exe
[ 87%] Built target example2
[ 93%] Building CXX object CMakeFiles/t_ParserTest.dir/test/t_ParserTest.cpp.obj
[100%] Linking CXX executable t_ParserTest.exe
[100%] Built target t_ParserTest

I build the expected targets:

imkin@MikesInspiron MINGW64 /c/Users/imkin/so/muparser/build
$ ls *muparser.dll*
libmuparser.dll  libmuparser.dll.a

I would not recommend renaming your msys-muparser-2.dll because the import library embeds the name of the associated DLL. If, after you link your app against the import library you run:

>dumpbin /dependents debug\TestMuParser.exe

and see that msys-muparser-2.dll is among the dependencies then all is as it should be.

If problems persist

Since you have an MSYS2 installation (in which you are building muparser), you might abandon the attempt to build it from source and install the MSYS2 binary package mingw-w64-x86_64-muparser with:

$ pacman -S mingw-w64-x86_64-muparser

This will only install DLL version (import library /c/msys64/mingw64/lib/libmuparser.dll.a and DLL /c/msys64/mingw64/bin/libmuparser.dll, but it seems you are prepared to live with the DLL if you have to.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much for the answer. I have edited my post to summarize the results of trying this. I have also read your comments from the staging ground. Yes, you are correct: unfortunately, I took on this project with knowledge of writing C++ code, but without realizing how many details I was missing when it came to actually dealing with building/compiling and all of that business. I will be sure to visit the tutorials you linked. Your help is greatly appreciated.
I should also mention that these errors persist in spite of removing the g++ -c -fno-keep-inline-dllexport -g -std=gnu++1z -Wall -Wextra... etc. command which you brought up.
@AidanBeecher See update to my answer. And about removing that command, I meant just to remove it from the post, not the build, but I'd retract that now: it is informative.
Updated my post. Your suggestions didn't work for me, so I tried a different version of MuParser to see if that would fix things. In summary, I got it working in Visual Studio Code, but an identical project (same main.cpp, same CMakeLists.txt) in Qt Creator failed to run.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.