C++ build error

2 views (last 30 days)
alex oerl
alex oerl on 22 Oct 2017
Answered: Himanshu on 10 Dec 2024
I have create in QtCreator project with such main file:
int main(int argc, char *argv[])
{
// QCoreApplication a(argc, argv);
Engine *ep;
/*
* Call engOpen with a NULL string. This starts a MATLAB process
* on the current host using the command "matlab".
*/
if (!(ep = engOpen(""))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}
engEvalString(ep, "cd '/home/user/developer/matlab/models");
// engEvalString(ep, "/while true ss = sim('weatherW1', 'StopTime', '30'); end");
engEvalString(ep, "ss = sim('weatherW1', 'StopTime', '30')");
int res = 0;//a.exec();
engClose(ep);
return res;
}
but when I compile code I get errors:
^
g++-4.9 -o testM temps/obj/main.o -L/home/user/bin/MATLAB/R2017a/bin/glnxa64 -lmx -lmex -lmat -lm -leng -lpthread
/home/user/bin/MATLAB/R2017a/bin/glnxa64/libmwservices.so: undefined reference to `icu_56::UnicodeString::doReplace(int, int, char16_t const*, int, int)'
/home/user/bin/MATLAB/R2017a/bin/glnxa64/libmwi18n.so: undefined reference to `UCNV_FROM_U_CALLBACK_STOP_WITH_INVISIBLE_CHARS_56'
/home/user/bin/MATLAB/R2017a/bin/glnxa64/libmwi18n.so: undefined reference to `icu_56::UnicodeString::doCompare(int, int, char16_t const*, int, int) const'
Makefile:231: recipe for target 'testM' failed
/home/user/bin/MATLAB/R2017a/bin/glnxa64/libmwi18n.so: undefined reference to `icu_56::UnicodeString::UnicodeString(char16_t const*, int)'
/home/user/bin/MATLAB/R2017a/bin/glnxa64/libmwi18n.so: undefined reference to `UCNV_FROM_U_CALLBACK_ESCAPE_WITH_INVISIBLE_CHARS_56'
/home/user/bin/MATLAB/R2017a/bin/glnxa64/libmwi18n.so: undefined reference to `icu_56::UnicodeString::UnicodeString(char16_t const*)'
collect2: error: ld returned 1 exit status
make: *** [testM] Error 1
19:03:12: Процес "/usr/bin/make" завершився з кодом 2.
Помилка під час збірки/розгортання проекту runML (комплект: Desktop Qt 5.9.2 GCC 64bit)
Під час виконання кроку "Make"
What I do wrong?
Regards
  1 Comment
alex oerl
alex oerl on 22 Oct 2017
I solve this error. In QtCreator project settings you must change LD_LIBRARY_PATH & add in begin
/home/user/bin/MATLAB/R2017a/bin/glnxa64
or your path
becouse qt & matlab use identical library
REgards

Sign in to comment.

Answers (1)

Himanshu
Himanshu on 10 Dec 2024
Hey,
The error you are encountering occurs because both Qt and MATLAB use the ICU library, but different versions, leading to conflicts when linking. To resolve this, you need to modify the LD_LIBRARY_PATH in your QtCreator project settings to prioritize the MATLAB library path by adding /home/user/bin/MATLAB/R2017a/bin/glnxa64 at the beginning.
You can do thisby follwing these steps:
  1. Open your project in QtCreator.
  2. Go to the project settings (usually accessible via the "Projects" button in the sidebar).
  3. Under the "Build & Run" tab, find the "Build Environment" section.
  4. Modify the LD_LIBRARY_PATH by prepending the MATLAB library path: /home/user/bin/MATLAB/R2017a/bin/glnxa64.
  5. Ensure this change is saved and then rebuild your project.
By ensuring the MATLAB library path is prioritized, the linker will use the correct ICU library version that MATLAB expects, resolving the undefined reference errors.
Hope this hels!

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!