Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [Solved] Using libsndfile library in Qt Creator
Forum Updated to NodeBB v4.3 + New Features

[Solved] Using libsndfile library in Qt Creator

Scheduled Pinned Locked Moved Installation and Deployment
9 Posts 3 Posters 10.0k 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.
  • S Offline
    S Offline
    simplePlan
    wrote on 3 Aug 2012, 08:43 last edited by
    #1

    I want to use Qt Creator with libsndfile (www.mega-nerd.com/libsndfile/). I tried several ways to use that library, but I always get linker error LNK2019. Here is my code, where i just tried to open a wavfile:

    @#include <QApplication>
    #include "mainwindow.h"
    #include <stdio.h>
    #include "sndfile.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;

    // Soundfile open
    const char *path = "c:/handel.wav";
    const int mode = 1;
    SF_INFO *sfinfo = new SF_INFO;
    
    SNDFILE* soundfile=sf_open(path,  mode, sfinfo) ;
    
    
    w.show();
    return a.exec(&#41;;
    

    }
    @

    Can you please explain (step-by-step instructions) to me how to use that library correctly in Qt Creator?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on 3 Aug 2012, 09:09 last edited by
      #2

      welcome to devnet

      It looks like you are using a Microsoft compiler and linker together with Qt creator. Did you make sure that the library you are using is compatible with the MS tool chain?

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        simplePlan
        wrote on 3 Aug 2012, 09:16 last edited by
        #3

        Thank you.

        I am using Qt 4.8.2 and MS Visual C++ Compiler 10.0 (x64) on Win7 64. The download link I used from the libsndfile homepage was: Win64 installer: "libsndfile-1.0.25-w64-setup.exe":http://www.mega-nerd.com/libsndfile/files/libsndfile-1.0.25-w64-setup.exe (thoroughly tested on 64 bit Windows 7).

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on 3 Aug 2012, 09:39 last edited by
          #4

          LNK2019 is an unresolved external reference. Since your program is really very basic I would expect that you are not linking with the library at all.

          Did you add the library to the environment at all?
          Here is some "documentation for qt creator on adding libraries":http://doc.qt.nokia.com/qtcreator-2.3/creator-project-qmake-libraries.html

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            simplePlan
            wrote on 3 Aug 2012, 10:06 last edited by
            #5

            Here is the error message:
            main.obj:-1: error: LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_sf_open" in Funktion "_main". File not found: main.obj

            I already switched environment settings to english. Issues/Errors remain german. Do you know how to change those to english?

            The problem I might have is that the library comes with a lib-file, a dll, and two headerfiles sndfile.h and sndfile.hh. And I dont have a clue how to add all those correctly to the project.

            I did add the lib-file using the 'add library' wizard > 'external library'. I tried both static/dynamic linking. Additionally I added the header-files to project. Same error. Yes, the code is very basic, because I need the linkage to work before I can actually use the library.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              koahnig
              wrote on 3 Aug 2012, 12:26 last edited by
              #6

              [quote author="simplePlan" date="1343988406"]Here is the error message:
              main.obj:-1: error: LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_sf_open" in Funktion "_main". File not found: main.obj

              I already switched environment settings to english. Issues/Errors remain german. Do you know how to change those to english?
              [/quote]
              I am a native German speaker. It is always a mess if you do not know the proper English terms.
              In MSVC 2005 you can change the language under "tools" and "options". I do not know, if it has an effect when you are using the tool chain in Qt creator.
              [quote author="simplePlan" date="1343988406"]
              The problem I might have is that the library comes with a lib-file, a dll, and two headerfiles sndfile.h and sndfile.hh. And I dont have a clue how to add all those correctly to the project.

              I did add the lib-file using the 'add library' wizard > 'external library'. I tried both static/dynamic linking. Additionally I added the header-files to project. Same error. Yes, the code is very basic, because I need the linkage to work before I can actually use the library.
              [/quote]
              The *.h and probably also *.hh are include files. You need to set up the include path towards the directory with the includes. I guess the *.lib are smaller than the corresponding *.dll. That is typically a sign that you have the libs for dynamic linkage. The *.lib provides the entries allowing the use of the dll functions. You need to add the directory with the *.lib into the libpath.

              You should see a .pro file in Qt creator. There are already some basic qmake assignments.
              You may have to add some adapted lines similar to
              @
              INCLUDEPATH += .
              ../../boostLib
              LIBS += -L./../../lib/HOST
              -lKaLib
              @
              The "INCLUDEPATH":http://qt-project.org/doc/qt-4.8/qmake-variable-reference.html#includepath is used for includes during compilation and "LIBS":http://qt-project.org/doc/qt-4.8/qmake-variable-reference.html#libs specifies the path to the libs. The case above is using relative path', but you may use also e.g. c:/mylibs/lib . For LIBS you have "-L" for the path and "-l" for the library itself.

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

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JKSH
                Moderators
                wrote on 3 Aug 2012, 14:32 last edited by
                #7

                I use libsnd file in a Qt project, so I can give you a specific example to koahnig's hints. This is my folder structure:

                @
                ROOT

                • libsndfile
                • src
                  @

                The libsndfile folder contains the library files (.dll, .h, .hh, .lib and .def), and the src folder contains my code and .pro file.

                My .pro file contains these lines:
                @ INCLUDEPATH += ../libsndfile
                LIBS = -L../libsndfile -lsndfile-1
                @

                ...and my source code contains this:
                @#include <sndfile.hh>@

                Since you're writing a C++ program, I recommend including sndfile.hh (not sndfile.h), and using the SndfileHandle class. It's much cleaner than the C code in sndfile.h

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  simplePlan
                  wrote on 3 Aug 2012, 18:56 last edited by
                  #8

                  It seems that the libraries where correctly linked in Qt Creator. Using the 32-bit libraries (not the 64-bit libraries, which I used first) resolved the problem. Thank you for all your support. You saved my day.

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    koahnig
                    wrote on 4 Aug 2012, 09:38 last edited by
                    #9

                    Good to know that your problem is solved. I marked your post accordingly.

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

                    1 Reply Last reply
                    0

                    1/9

                    3 Aug 2012, 08:43

                    • Login

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