Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Read .mat of matlab in qt
Forum Updated to NodeBB v4.3 + New Features

Read .mat of matlab in qt

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 6.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #2

    welcome to devnet

    I have no experience in binding MathLab stuff to an application.
    However, I would expect a .lib to be used in the linking process. This should ensure that all references to MathLab routines are found.
    You are trying to reference the .dll directly during linking, but it would be loaded during run time.

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • S Offline
      S Offline
      saratchand.kandukuri
      wrote on last edited by
      #3

      Dear koahnig..
      Thanks for the reply.
      I also even have the required libraries. They are libmat.lib and libmx.lib.
      If I add them to the project as an external library.. Gave the file.
      Now the .pro file looked as :
      @QT += core

      QT -= gui

      TARGET = mat_open_test
      CONFIG += console
      CONFIG -= app_bundle

      TEMPLATE = app

      SOURCES += main.cpp

      HEADERS +=
      mat.h
      matrix.h
      tmwtypes.h

      win32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -llibmat
      else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -llibmatd
      else:symbian: LIBS += -llibmat
      else:unix: LIBS += -L$$PWD/ -llibmat

      INCLUDEPATH += $$PWD/../../../../../Program Files/MATLAB/R2012b/extern/include
      DEPENDPATH += $$PWD/../../../../../Program Files/MATLAB/R2012b/extern/include
      @

      and the error is :
      @cannot find -libmattd@..
      I only added libmat.. how can i get the libmatt.d file from??

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #4

        Two I am noticing when looking at your .pro file and the error message.

        .pro references libmat and libmatd
        the error message indicates that it is looking for libmattd
        This is either typo in your posting or the problem.

        Where do have placed the libs?
        $$PWD is your working folder where the source is located.
        The folder used in your original post is more the folder of the shadow build.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #5

          Line 26 of your PRO file says, "if building in debug mode on Windows link with libmatd"
          Apart from the unnecessary "lib" on the front of the library name, if you don't have debug versions of the Matlib libraries then this will not work.

          It probably should read (for release):
          [code]
          win32 {
          LIBS += -LC:/path/to/MatLib/bin -lmat
          }
          [/code]

          1 Reply Last reply
          0
          • S Offline
            S Offline
            saratchand.kandukuri
            wrote on last edited by
            #6

            @koahnig..
            The libmattd is the problem. I have the library libmat.lib .
            I copied the library to the folder where main.cpp is. I am adding the library by right clicking on the project->add library->external library->(gave the path of the library). The include path automatically got set.

            My .pro looks like :
            @QT += core

            QT -= gui

            TARGET = mat_open_test
            CONFIG += console
            CONFIG -= app_bundle

            TEMPLATE = app

            SOURCES += main.cpp

            HEADERS +=
            mat.h
            matrix.h
            tmwtypes.h

            OTHER_FILES +=

            win32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -llibmat
            else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -llibmatd
            else:symbian: LIBS += -llibmat
            else:unix: LIBS += -L$$PWD/ -llibmat

            INCLUDEPATH += $$PWD/
            DEPENDPATH += $$PWD/
            @

            I get the same error :
            cannot find llibmatd..

            @ChrisW67
            What you are saying is correct. I do not have the debug version of the library. But I only have the library. How can I execute it?? Any suggestions

            1 Reply Last reply
            0
            • K Offline
              K Offline
              koahnig
              wrote on last edited by
              #7

              Since your .pro says explicitly in line 29 that it should use "libmathd" in debug, you cannot compile in debug mode.

              For a test try to compile with an additional:
              @
              CONFIG += release
              @

              than it will use the "libmath".
              You may also try to set always:
              @
              LIBS += -L$$PWD/ -llibmat
              @

              Not sure if you can use release libs for both modes.

              Vote the answer(s) that helped you to solve your issue(s)

              1 Reply Last reply
              0
              • S Offline
                S Offline
                saratchand.kandukuri
                wrote on last edited by
                #8

                qkoahnig..
                Can you tell me exactly where I should copy the libraries. Should I copy them in the folder containing the main.cpp or in the debug and release subfolders of the main build folder.. and then I can give the subsequent paths while adding.

                When I added the CONFIG += release..

                I get the error ..
                Undefined reference to matopen.. The very first problem :(

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  koahnig
                  wrote on last edited by
                  #9

                  [quote author="saratchand" date="1373012556"]qkoahnig..
                  Can you tell me exactly where I should copy the libraries. Should I copy them in the folder containing the main.cpp or in the debug and release subfolders of the main build folder.. and then I can give the subsequent paths while adding.
                  [/quote]
                  That basically depends on your preference. However, it is common practice to keep libs somewhere separate. This has also some practical reasons. You do not want to copy the libs to your source all the time. Furthermore, you do not want mix different 3rd party libs.
                  As you have figured already, you can supply the path name of the lib's location in the LIBS parameter. I would suggest to leave the libs in their original location (probably in a sub-folder of mathlab). Declare this folder path with with "-L" as you have done already.

                  [quote author="saratchand" date="1373012556"]
                  When I added the CONFIG += release..

                  I get the error ..
                  Undefined reference to matopen.. The very first problem :([/quote]
                  The linker has found the lib now, which is a success.

                  I do not use mathlab, but according to a quick search matopen is a routine of mathlab called in your program.

                  Possibly there more libs, which you have to declare as well. If there is only one mathlab lib supplied, it looks like it is not compatible with your compiler.

                  Note, not all libs can be mixed. Typically, they are dependent on the compiler used to build them. That is the reason that you have different download options for Qt libs too. You need to use a build for msvc2010 with msvc2010, msvc2012 with msvc2012, mingw 4.7 with mingw 4.7, mingw 4.4 with mingw 4.4 and so on.

                  You need to check out the compatibility of your mathlab libs.

                  Vote the answer(s) that helped you to solve your issue(s)

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    masheen
                    wrote on last edited by
                    #10

                    saratchand , have you solved reading of .mat in qt?

                    I am having the same problems. I made little more progress than in the last post, but still get "undefined reference to mapOpen".

                    This is the relevant .pro section I am using

                    win32: LIBS += -L"C:/Qt/Qt5.1.0/5.1.0/mingw48_32/lib" -llibmat

                    INCLUDEPATH += $$PWD/matlab
                    DEPENDPATH += $$PWD/matlab

                    One hint I have to offer is not to refer to libmatd - that is not necessary and we don't have that anyway. The way I have it above, libmat is used should be used for both the release and debug compilations.

                    I moved the libmat and include files to the directory showns above to make sure they are found and to prevent some other errors I was getting. Maybe that is not necessary.

                    However, I am still getting "undefined reference to mapOpen".

                    Did you maybe find libs and dlls more appropriate for Qt?

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      saratchand.kandukuri
                      wrote on last edited by
                      #11

                      Hii masheen

                      Yes I have solved the issue. But i shifted to Visual Studio for the further implementation as I am supposed to here in my institute.Sorry for replying late.
                      Anyways , This is what my code looks like.

                      @#-------------------------------------------------

                      Project created by QtCreator 2013-07-03T13:12:22

                      #-------------------------------------------------

                      QT += core

                      QT -= gui

                      TARGET = mat_open_test
                      CONFIG += console
                      CONFIG -= app_bundle

                      TEMPLATE = app

                      SOURCES += main.cpp

                      HEADERS +=
                      mat.h
                      matrix.h
                      tmwtypes.h

                      win32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -llibmat
                      else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -llibmatd
                      else:symbian: LIBS += -llibmat
                      else:unix: LIBS += -L$$PWD/ -llibmat

                      INCLUDEPATH += $$PWD/
                      DEPENDPATH += $$PWD/

                      win32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -llibmx
                      else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -llibmxd
                      else:symbian: LIBS += -llibmx
                      else:unix: LIBS += -L$$PWD/ -llibmx

                      INCLUDEPATH += $$PWD/
                      DEPENDPATH += $$PWD/
                      @

                      One small suggestion, make sure the libraries you are trying to load to your IDE are 32 bit version libraries of Matlab. cos my IDE was 32 bit and I, by mistake tried the 64 bit libraries of Matlab.. Sometimes SHIT!! happens :D ..

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved