Solved error undefined reference to function that declared in header and dynamically linked
-
@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.
-
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.
-
@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?
-
@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 ...
-
@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. :)
-
@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. :)
-
@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. :)
-
@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.
-
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 :) -
@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. ;)
-
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