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.
  • A ambershark

    @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 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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 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
        0
        • T tony2383

          @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 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
          2
          • T tony2383

            @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 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
            0
            • A ambershark

              @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 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
              0
              • kshegunovK kshegunov

                @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 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
                0
                • A ambershark

                  @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 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
                  1
                  • kshegunovK kshegunov

                    @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 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

                      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 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 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
                        1
                        • mrjjM mrjj

                          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 Offline
                          A Offline
                          ambershark
                          wrote on last edited by
                          #21

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

                          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 :)

                          Indeed it was. :) I was quick to shrug it off too thinking no that can't be it... But then you and @kshegunov proved me quite wrong there. ;)

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

                          mrjjM 1 Reply Last reply
                          1
                          • A ambershark

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

                            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 :)

                            Indeed it was. :) I was quick to shrug it off too thinking no that can't be it... But then you and @kshegunov proved me quite wrong there. ;)

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #22

                            @ambershark

                            well, i would (also) have bet my money
                            on mixed libs/compiler or incorrect LIBS +=
                            and not extern "c" so that is very understandable.

                            Also, very informative as i did not knew mingw would do that :)
                            Cheers

                            1 Reply Last reply
                            1

                            • Login

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