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. error undefined reference to function that declared in header and dynamically linked
Forum Updated to NodeBB v4.3 + New Features

error undefined reference to function that declared in header and dynamically linked

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 6 Posters 9.0k Views 5 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.
  • T Offline
    T Offline
    tony2383
    wrote on 20 Dec 2016, 20:36 last edited by
    #1

    I'm trying to use FTDI libMPSSE library in my QT application. I have made sure that I have imported my external libraries properly and I have made sure that I have include the header files into the project. When I go to build the application referencing a function I get and undefined reference to error. My project can be found here

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 20 Dec 2016, 21:47 last edited by Chris Kawa
      #2

      Drop the "lib" prefix in your linker options i.e. win32: LIBS += -L$$PWD/./ -lMPSSE instead of win32: LIBS += -L$$PWD/./ -llibMPSSE.

      T 1 Reply Last reply 21 Dec 2016, 16:13
      3
      • C Chris Kawa
        20 Dec 2016, 21:47

        Drop the "lib" prefix in your linker options i.e. win32: LIBS += -L$$PWD/./ -lMPSSE instead of win32: LIBS += -L$$PWD/./ -llibMPSSE.

        T Offline
        T Offline
        tony2383
        wrote on 21 Dec 2016, 16:13 last edited by
        #3

        @Chris-Kawa I have tried with and without lib in front of MPSEE already and I still get the same error

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 21 Dec 2016, 22:15 last edited by
          #4

          Hi and welcome to devnet,

          Are you sure that your version of libMPSSE is built for the same architecture as the Qt version your are using ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply 21 Dec 2016, 23:06
          1
          • S SGaist
            21 Dec 2016, 22:15

            Hi and welcome to devnet,

            Are you sure that your version of libMPSSE is built for the same architecture as the Qt version your are using ?

            A Offline
            A Offline
            ambershark
            wrote on 21 Dec 2016, 23:06 last edited by ambershark
            #5

            @SGaist said in error undefined reference to function that declared in header and dynamically linked:

            Hi and welcome to devnet,

            Are you sure that your version of libMPSSE is built for the same architecture as the Qt version your are using ?

            @tony2383 This is almost always the problem.. Especially in windows. People like to mix visual c++ libs and mingw and cygwin and any other type you can imagine. Needless to say it doesn't work however there are no errors thrown except the one you are seeing.

            Make sure you are linking libs that were built with the same compiler (i.e. mingw) and the same addressing i.e. 64 bit/32 bit, etc.

            If all else fails you can use the ar command to see if your library contains the symbols you think it does. ar only works with libs compiled with mingw/cygwin. Also to get the ar command you'll probably need cygwin unless you have a mingw install that has it as well.

            Edit:

            I checked your files for you. You have 3 libs in your directory dll/lib/a. Try removing the dll & lib and build again using the static library (the .a). That should resolve ambiguity. My guess is the dll and lib are not build with mingw and are causing the issue.

            Here is the result of the ar:

            [shockwave] ~/FTDI_QT > ar t libMPSSE.a
            ftdi_infra.o
            ftdi_mid.o
            ftdi_i2c.o
            

            So it has those 3 objects in there.

            Also please show the actual output of the build so we can see the exact error.

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tony2383
              wrote on 22 Dec 2016, 13:21 last edited by
              #6

              @SGaist Yes the libMPSSE was built with MINGW 5.3.0 same as the compiler that I'm using within QT. I'm not sure that it would make a difference that I used a sepreate install of MINGW to compile the library outside the one that is provided with QT. @ambershark I build the library using MINGW32. Does it make a difference that the library was compiled using a C compiler (GCC ) instead of a C++ compiler (G++). I thought it wouldn't being that C code can be compiled using a C++ compiler. Also, I tried removing the the DLL and the LIB and compiling with a static link and I still receive the same error. The errors that I recieve are

              • list item"C:\qt_projects\build-new_sample-Desktop_Qt_5_7_1_MinGW_32bit-Debug\debug\mainwindow.o:-1: In function `ZN10MainWindow21on_pushButton_clickedEv':"

              • list item C:\qt_projects\new_sample\mainwindow.cpp:21: error: undefined reference to `Init_libMPSSE()'

              • list item collect2.exe:-1: error: error: ld returned 1 exit status

              A 1 Reply Last reply 22 Dec 2016, 18:47
              0
              • T tony2383
                22 Dec 2016, 13:21

                @SGaist Yes the libMPSSE was built with MINGW 5.3.0 same as the compiler that I'm using within QT. I'm not sure that it would make a difference that I used a sepreate install of MINGW to compile the library outside the one that is provided with QT. @ambershark I build the library using MINGW32. Does it make a difference that the library was compiled using a C compiler (GCC ) instead of a C++ compiler (G++). I thought it wouldn't being that C code can be compiled using a C++ compiler. Also, I tried removing the the DLL and the LIB and compiling with a static link and I still receive the same error. The errors that I recieve are

                • list item"C:\qt_projects\build-new_sample-Desktop_Qt_5_7_1_MinGW_32bit-Debug\debug\mainwindow.o:-1: In function `ZN10MainWindow21on_pushButton_clickedEv':"

                • list item C:\qt_projects\new_sample\mainwindow.cpp:21: error: undefined reference to `Init_libMPSSE()'

                • list item collect2.exe:-1: error: error: ld returned 1 exit status

                A Offline
                A Offline
                ambershark
                wrote on 22 Dec 2016, 18:47 last edited by
                #7

                @tony2383 said in error undefined reference to function that declared in header and dynamically linked:

                @SGaist Yes the libMPSSE was built with MINGW 5.3.0 same as the compiler that I'm using within QT. I'm not sure that it would make a difference that I used a sepreate install of MINGW to compile the library outside the one that is provided with QT. @ambershark I build the library using MINGW32. Does it make a difference that the library was compiled using a C compiler (GCC ) instead of a C++ compiler (G++). I thought it wouldn't being that C code can be compiled using a C++ compiler. Also, I tried removing the the DLL and the LIB and compiling with a static link and I still receive the same error. The errors that I recieve are

                As long as you use g++ as the actual linker you should be fine. Easy to test though and just build the lib with g++. But you definitely need to use g++ and not gcc to do the linking step or it won't work.

                • list item"C:\qt_projects\build-new_sample-Desktop_Qt_5_7_1_MinGW_32bit-Debug\debug\mainwindow.o:-1: In function `ZN10MainWindow21on_pushButton_clickedEv':"

                • list item C:\qt_projects\new_sample\mainwindow.cpp:21: error: undefined reference to `Init_libMPSSE()'

                • list item collect2.exe:-1: error: error: ld returned 1 exit status

                Which object that my ar command listed is the Init_libMPSSE() function in?

                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 22 Dec 2016, 19:00 last edited by
                  #8

                  Hi
                  Small question.
                  If compiled with c compiler, will it not need
                  extern "c" {
                  }
                  To be used from c++ ?
                  Or is that automatically with g++ ?

                  A 1 Reply Last reply 22 Dec 2016, 19:02
                  0
                  • mrjjM mrjj
                    22 Dec 2016, 19:00

                    Hi
                    Small question.
                    If compiled with c compiler, will it not need
                    extern "c" {
                    }
                    To be used from c++ ?
                    Or is that automatically with g++ ?

                    A Offline
                    A Offline
                    ambershark
                    wrote on 22 Dec 2016, 19:02 last edited by
                    #9

                    @mrjj said in error undefined reference to function that declared in header and dynamically linked:

                    Hi
                    Small question.
                    If compiled with c compiler, will it not need
                    extern "c" {
                    }
                    To be used from c++ ?
                    Or is that automatically with g++ ?

                    Extern c goes the other way. It's for a c++ compiler to not name mangle the function so it can be used from c code. So since his end product will be in c++ it wouldn't need the extern c's since c++ would understand the name mangled functions.

                    My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                    mrjjM 1 Reply Last reply 22 Dec 2016, 19:10
                    0
                    • A ambershark
                      22 Dec 2016, 19:02

                      @mrjj said in error undefined reference to function that declared in header and dynamically linked:

                      Hi
                      Small question.
                      If compiled with c compiler, will it not need
                      extern "c" {
                      }
                      To be used from c++ ?
                      Or is that automatically with g++ ?

                      Extern c goes the other way. It's for a c++ compiler to not name mangle the function so it can be used from c code. So since his end product will be in c++ it wouldn't need the extern c's since c++ would understand the name mangled functions.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 22 Dec 2016, 19:10 last edited by
                      #10

                      @ambershark
                      Ok, I most likely read it wrong then.
                      As i saw
                      LIB created with c compiling
                      No name mangling.

                      We link this to c++ program and
                      to make it see the c names, we
                      do
                      extern "c" {
                      void libFunc1(p1, p2);
                      void libFunc2();
                      }

                      Sorry. Too much coffee I guess :)

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 22 Dec 2016, 21:12 last edited by
                        #11

                        Again, did you check that the architecture of your built library is indeed 32bit like Qt ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        1
                        • T Offline
                          T Offline
                          tony2383
                          wrote on 2 Jan 2017, 15:13 last edited by
                          #12

                          @SGaist the library was built with MINGW 5.3.0, same as the compiler that I'm using within QT. @ambershark the init_libMPSSE function was removed from the library in the most recent version of the library source code. But the effects is still the same when I use any other function call. I have updated my repo to use function I2C_GetNumChannels and still receive the same error. The function can be found in the ftdi_i2c.o.

                          kshegunovK A 2 Replies Last reply 2 Jan 2017, 19:17
                          0
                          • T tony2383
                            2 Jan 2017, 15:13

                            @SGaist the library was built with MINGW 5.3.0, same as the compiler that I'm using within QT. @ambershark the init_libMPSSE function was removed from the library in the most recent version of the library source code. But the effects is still the same when I use any other function call. I have updated my repo to use function I2C_GetNumChannels and still receive the same error. The function can be found in the ftdi_i2c.o.

                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on 2 Jan 2017, 19:17 last edited by
                            #13

                            You compiled said library (libMPSSE) with C or C++ compiler? If you compiled it with a c++ compiler, then you need to match it and use the same compiler in your application code. If you compiled with a C compiler, then you need to instruct your C++ compiler (the one you're using in the application) to not put references to decorated functions. That means you need to extern "C" {} the includes. E.g.:

                            extern "C" 
                            {
                                 #include <mpsse.h>
                                 // ...
                            }
                            

                            C-linkage is compatible across all compilers, so there's no need to match the compiler (but you do need to match architecture) in this case.

                            Read and abide by the Qt Code of Conduct

                            T 1 Reply Last reply 3 Jan 2017, 19:27
                            2
                            • T tony2383
                              2 Jan 2017, 15:13

                              @SGaist the library was built with MINGW 5.3.0, same as the compiler that I'm using within QT. @ambershark the init_libMPSSE function was removed from the library in the most recent version of the library source code. But the effects is still the same when I use any other function call. I have updated my repo to use function I2C_GetNumChannels and still receive the same error. The function can be found in the ftdi_i2c.o.

                              A Offline
                              A Offline
                              ambershark
                              wrote on 2 Jan 2017, 20:07 last edited by
                              #14

                              @tony2383 Since you said you compiled with the same version of mingw for the lib as well as your project then the above comment probably won't help you.

                              Continuing down that line of thought and assuming (huge assumption here) that your libs are correctly matched, please post the output of make VERBOSE=1 for me to take a look at.

                              Just so you know this problem is almost always a wrongly built library though. So it's more likely that the MPSSE lib is built different than your program.

                              Do you potentially have a copy of libMPSSE somewhere else in your lib path that is getting pulled in instead of the one you built? Are you absolutely sure your build of libMPSSE uses the same bit depth and compiler as your application?

                              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                              kshegunovK 1 Reply Last reply 2 Jan 2017, 20:08
                              0
                              • A ambershark
                                2 Jan 2017, 20:07

                                @tony2383 Since you said you compiled with the same version of mingw for the lib as well as your project then the above comment probably won't help you.

                                Continuing down that line of thought and assuming (huge assumption here) that your libs are correctly matched, please post the output of make VERBOSE=1 for me to take a look at.

                                Just so you know this problem is almost always a wrongly built library though. So it's more likely that the MPSSE lib is built different than your program.

                                Do you potentially have a copy of libMPSSE somewhere else in your lib path that is getting pulled in instead of the one you built? Are you absolutely sure your build of libMPSSE uses the same bit depth and compiler as your application?

                                kshegunovK Offline
                                kshegunovK Offline
                                kshegunov
                                Moderators
                                wrote on 2 Jan 2017, 20:08 last edited by
                                #15

                                @ambershark said in error undefined reference to function that declared in header and dynamically linked:

                                Since you said you compiled with the same version of mingw for the lib as well as your project then the above comment probably won't help you.

                                mingw does compile C code (with C linkage), you know ...

                                Read and abide by the Qt Code of Conduct

                                A 1 Reply Last reply 2 Jan 2017, 20:17
                                0
                                • kshegunovK kshegunov
                                  2 Jan 2017, 20:08

                                  @ambershark said in error undefined reference to function that declared in header and dynamically linked:

                                  Since you said you compiled with the same version of mingw for the lib as well as your project then the above comment probably won't help you.

                                  mingw does compile C code (with C linkage), you know ...

                                  A Offline
                                  A Offline
                                  ambershark
                                  wrote on 2 Jan 2017, 20:17 last edited by
                                  #16

                                  @kshegunov said in error undefined reference to function that declared in header and dynamically linked:

                                  @ambershark said in error undefined reference to function that declared in header and dynamically linked:

                                  Since you said you compiled with the same version of mingw for the lib as well as your project then the above comment probably won't help you.

                                  mingw does compile C code (with C linkage), you know ...

                                  Yea, it would be a lot easier to diagnose his problem if he actually posted his build output. It would be pretty obvious if he was mixing C/C++ at that point.

                                  The reason I said that extern C'ing his stuff wasn't the solution is he assured us he was using the same compiler for all his stuff. That to me means he knew the difference between a C compiler and a C++ one. It definitely doesn't hurt to throw the extern c around the includes though to test it. I wasn't meaning to downplay your answer at all. Sorry if it seemed like that. :)

                                  My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                                  kshegunovK 1 Reply Last reply 2 Jan 2017, 20:20
                                  0
                                  • A ambershark
                                    2 Jan 2017, 20:17

                                    @kshegunov said in error undefined reference to function that declared in header and dynamically linked:

                                    @ambershark said in error undefined reference to function that declared in header and dynamically linked:

                                    Since you said you compiled with the same version of mingw for the lib as well as your project then the above comment probably won't help you.

                                    mingw does compile C code (with C linkage), you know ...

                                    Yea, it would be a lot easier to diagnose his problem if he actually posted his build output. It would be pretty obvious if he was mixing C/C++ at that point.

                                    The reason I said that extern C'ing his stuff wasn't the solution is he assured us he was using the same compiler for all his stuff. That to me means he knew the difference between a C compiler and a C++ one. It definitely doesn't hurt to throw the extern c around the includes though to test it. I wasn't meaning to downplay your answer at all. Sorry if it seemed like that. :)

                                    kshegunovK Offline
                                    kshegunovK Offline
                                    kshegunov
                                    Moderators
                                    wrote on 2 Jan 2017, 20:20 last edited by
                                    #17

                                    @ambershark said in error undefined reference to function that declared in header and dynamically linked:

                                    Yea, it would be a lot easier to diagnose his problem if he actually posted his build output. It would be pretty obvious if he was mixing C/C++ at that point.
                                    The reason I said that extern C'ing his stuff wasn't the solution is he assured us he was using the same compiler for all his stuff.

                                    He might've stumbled on some "default behavior" (how can you not love C/C++) where the C compiler is invoked when it sees .c extension. So it may be really transparent from afar, and yet to happen so there's mixing of C and C++ compiled code.

                                    I wasn't meaning to downplay your answer at all. Sorry if it seemed like that.

                                    No offence taken, I have thicker skin than that. :)

                                    Read and abide by the Qt Code of Conduct

                                    A 1 Reply Last reply 2 Jan 2017, 20:45
                                    1
                                    • kshegunovK kshegunov
                                      2 Jan 2017, 20:20

                                      @ambershark said in error undefined reference to function that declared in header and dynamically linked:

                                      Yea, it would be a lot easier to diagnose his problem if he actually posted his build output. It would be pretty obvious if he was mixing C/C++ at that point.
                                      The reason I said that extern C'ing his stuff wasn't the solution is he assured us he was using the same compiler for all his stuff.

                                      He might've stumbled on some "default behavior" (how can you not love C/C++) where the C compiler is invoked when it sees .c extension. So it may be really transparent from afar, and yet to happen so there's mixing of C and C++ compiled code.

                                      I wasn't meaning to downplay your answer at all. Sorry if it seemed like that.

                                      No offence taken, I have thicker skin than that. :)

                                      A Offline
                                      A Offline
                                      ambershark
                                      wrote on 2 Jan 2017, 20:45 last edited by
                                      #18

                                      @kshegunov said in error undefined reference to function that declared in header and dynamically linked:

                                      He might've stumbled on some "default behavior" (how can you not love C/C++) where the C compiler is invoked when it sees .c extension. So it may be really transparent from afar, and yet to happen so there's mixing of C and C++ compiled code.

                                      Absolutely true! I have myself stumbled across that a few times. It always throws me off for a second too.

                                      No offence taken, I have thicker skin than that. :)

                                      Oh good! You never know with written word. I never mean to insult people but sometimes I do online, so now I try to apologize if I feel I might have. :)

                                      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                                      1 Reply Last reply
                                      2
                                      • kshegunovK kshegunov
                                        2 Jan 2017, 19:17

                                        You compiled said library (libMPSSE) with C or C++ compiler? If you compiled it with a c++ compiler, then you need to match it and use the same compiler in your application code. If you compiled with a C compiler, then you need to instruct your C++ compiler (the one you're using in the application) to not put references to decorated functions. That means you need to extern "C" {} the includes. E.g.:

                                        extern "C" 
                                        {
                                             #include <mpsse.h>
                                             // ...
                                        }
                                        

                                        C-linkage is compatible across all compilers, so there's no need to match the compiler (but you do need to match architecture) in this case.

                                        T Offline
                                        T Offline
                                        tony2383
                                        wrote on 3 Jan 2017, 19:27 last edited by
                                        #19

                                        @kshegunov @ambershark that worked. Still having a problem with FTDI libraries, but I will hop on one of there forums to address those issues. Thanks everyone for their help.

                                        1 Reply Last reply
                                        0
                                        • mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on 4 Jan 2017, 07:55 last edited by
                                          #20

                                          So in the end
                                          my hopeless formulated question
                                          about use extern "c" , turned out to be the case ?
                                          My very old compiler does like that. hence I asked :)

                                          A 1 Reply Last reply 4 Jan 2017, 20:09
                                          1

                                          • Login

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