Can't find library
Hello everyone, I'm getting errors while trying to run a program in Qt that I believe is a linker problem:
- cannot find -lfuzzylite
- collect2: ld returned 1 exit status
I've seen some thread on this already but I'm not very fluent in terms of C++ so it's hard for me to abstractly derive a solution from their problems. Here is the compiler output I'm getting:
c:/qtsdk/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lfuzzylite
collect2: ld returned 1 exit status
mingw32-make.exe: *** [debug\dist\gui.exe] Error 1
mingw32-make.exe: *** [debug] Error 2
21:42:33: The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project gui (target: Desktop)
When executing build step 'Make'
I need to run this GUI for a research project so any help would be much appreciated. Thanks.
Edit: Sorry I accidently posted this w/o finishing so I added the rest
The error occurs because linker is unable to find the library. You need to explicitly instruct the linker where the library lies if it is not in the default search path.
If you use qmake, you should add the following line in your .pro file:
in which "/path/to/libfuzzylite" stands for the directory where libfuzzylite.so lies.
Thanks for the response. I have a a few questions however:
First of all, what exactly is qmake?
Secondly, what type of file extension would a library file have...I'm guessing .lib? I understand that this GUI code is trying to reference the actual source code that defines the fuzzy controller that I have in Visual Studio. If there is no library file, would I have to change the code I have in Visual Studio to a static library?
Once again thanks a lot. I really appreciate the help. And sorry if my questions sound dumb. I'm kinda new to programming in general (esp. C++)
(1) qmake is the tool used by Qt to assist you with the compiling. Typically, it reads the content from your .pro file, and generate compile parameters for the compiler. If you use an IDE (Qt Creator, Visual Studio, etc.), qmake is run behind the scenes when Creator thinks it's necessary. There are some "write-up":http://qt-project.org/doc/qt-4.8/qmake-manual.html in documentation about building a Qt application without assistance from IDE, which can make you familiar with those under-the-hood processing.
(2) This really depends. On Windows, possible extensions are .lib, .dll, .a, and .so. Linking requires extensive writing to be explained, and is out of the scope of this forum. I would suggest reading books or tutorials about this, rather than a discussion here. "This":http://stackoverflow.com/questions/3364736/c-c-linking-tutorial seems like a good start. (Keeping in mind that MinGW is basically a Windows port of GCC, so the ideas are quite the same between them.)
Thanks a lot for the quick replies...I'm going to try what you mentioned earlier soon and see if it works. Thanks again.
You will need to set
@LIBS += -L/path/to/libfuzzylite/library -lfuzzylite@
as well as
where "library" is the directory containing your the .dll, .so, .a and/or .lib files and "headers" the directory containing the .h files that come with fuzzylite.
My guess based on your output is that both LIBS and INCLUDEPATH are set, but that the -L part is missing in LIBS.
You might also have set everything set up correctly but with a version of fuzzylite built with a MSVC compiler. I am not a windows user myself, but IIRC msvc uses .lib/.dll while mingw uses .so/.a, so that might also be a problem. You need to build everything (your code, Qt and all other libraries you use) with the same (kind of) compiler on windows. Mixing mingw with MSVC binaries is not possible, neither is mixing binaries build with different versions of MSVC.
I tried adding the library with the LIBS += and INCUDEPATH+= with no apparent success. I'm thinking the problem may be specific to windows so I am going to try using the GUI in Ubuntu through Virtual Box.
Thanks for repsonses, will update soon!