tags:

views:

6612

answers:

3

Hello, I am new to QT and have one error I am unable to fix...

I have a bunch of windows (VS2005) static library file (.lib). And I am testing if they work well with QT. So I took the most simple library that I have. (Called "MessageBuffer").

So I added MessageBuffer.h to the main.cpp, and added the location of thoses file in the INCLUDEPATH of the .pro

Until then everything seem fine, I can use the class and QT IDE show all method and everything. So to me it look like it found the .h file.

Now I added the MessageBuffer.lib (VS2005/Debug build) in the .pro like this:

LIBS += E:/SharedLibrary/lib/MessageBufferd.lib

I have also tried the following: win32:LIBS += E:/SharedLibrary/lib/MessageBufferd.lib LIBS += -LE:/SharedLibrary/lib -lMessageBufferd win32:LIBS += -LE:/SharedLibrary/lib -lMessageBufferd

Here is the content of my pro file:

QT += opengl
TARGET = SilverEye
TEMPLATE = app
INCLUDEPATH += E:/SharedLibrary/MessageBuffer
SOURCES += main.cpp \
    silvereye.cpp
HEADERS += silvereye.h
FORMS += silvereye.ui
OTHER_FILES += 
win32:LIBS += E:/SharedLibrary/lib/MessageBufferd.lib

They all give me the same errors: (and I get the same even if I don't include the .lib)

Running build steps for project SilverEye...
Configuration unchanged, skipping QMake step.
Starting: C:/Qt/2009.03/mingw/bin/mingw32-make.exe -w 
mingw32-make: Entering directory `C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye'
C:/Qt/2009.03/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\SilverEye.exe debug/main.o debug/silvereye.o debug/moc_silvereye.o -L"c:\Qt\2009.03\qt\lib" -lopengl32 -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmaind E:/SharedLibrary/lib/MessageBufferd.lib -lQtOpenGLd4 -lQtGuid4 -lQtCored4
mingw32-make[1]: Leaving directory `C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye'
mingw32-make: Leaving directory `C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye'
debug/main.o: In function `Z5qMainiPPc':
C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye/main.cpp:12: undefined reference to `MessageBuffer::MessageBuffer()'
C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye/main.cpp:13: undefined reference to `MessageBuffer::Append(char*, int)'
C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye/main.cpp:17: undefined reference to `MessageBuffer::~MessageBuffer()'
C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye/main.cpp:17: undefined reference to `MessageBuffer::~MessageBuffer()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\SilverEye.exe] Error 1
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project SilverEye
When executing build step 'Make'

Can anyone help please...

A: 

I assume that you have used the MessageBuffer library in another application with problems. The error looks like it either cannot find the library or the MessageBuffer class is not being exported.

Have you tried putting -l on front of the library in the pro file?

win32:LIBS += -lE:/SharedLibrary/lib/MessageBufferd.lib

See my other answer. I added the other answer because I didn't want to make this answer any more messy than it already was.

Tried so far:

  • Not a typo, d is appended to the library
  • Using the lib extension is correct as seen in the output
Jesse
d is the actual name, d is added for the debug version of the .lib
@xcimo makes sense...just wanted to check
Jesse
I do not know if MessageBuffer class is exported. I dont not have any "export" keyword in the messageBuffer class, since I have been able to use this library in many other Visual studio c++ project. Does a static library need an export? or maybe its something that mingw need? Thanks for helping.
To be honest, not sure if it needs it...but the error seems to imply that they cannot be found.
Jesse
do you think its not finding the .h or the .lib?
.lib...otherwise you would have a compile error.
Jesse
Try using the "nm" command that comes with minigw to see what is being exported by your lib.
Jesse
If you have not tried it yet, tack a -l on the front of the library in the pro file
Jesse
+1  A: 

Based on the question Use libraries compiled with visual studio in an application compiled by g++ (mingw) and the MSDN forum post I can't mix VC & GCC it does not appear you can link a gcc application with visual c++ compiled libraries.

The solution would be to recompile everything with the same compiler.

Jesse
This is actually what I was going to post, I found this:These libraries, like many other precompiled Windows development packages such as the MySQL client library, were compiled with Ms Visual C++ (MSVC). MSVC and MinGW, we discovered, use different naming conventions for stdcall functions. MSVC exports them as _name@ordinal, but MinGW exports them as name. As a result, the MinGW build failed with “undefined references” link errors when calling stdcall functions exported from the MSVC library.
Please look here for solutions:http://blog.outofhanwell.com/2006/05/01/linking-msvc-libraries-with-mingw-projects/
+2  A: 

The MinGW FAQ discusses this problem and offers a solution:

  1. Create a definition file using reimp (for lib files) or pexports (for dll files).
  2. Remove the underscore prefixes from the stdcall functions.
  3. Use dlltool to convert the MSVC library into a MinGW library with the new definition.

That didn’t work. We finally removed the ordinals from the function names, which caused it to compile. But the program wouldn’t run because it couldn’t find the linked functions in the DLL. Finally, after consulting the MSDN documentation for definition files, we changed the build instructions:

  1. Create a definition file using reimp.
  2. For each stdcall function (formatted as _name@ordinal) add a line name = _name@ordinal, allowing MinGW to map its stdcall naming convention to that of MSVC.
  3. Use dlltool to convert the MSVC library into a MinGW library with the new definition.

It worked! To compile the project you must simply:

  1. Download and install the Qt/Windows package, which includes MinGW.
  2. Download reimp and drop it into the MinGW/bin folder.
  3. Download the development packages for the third-party libraries and point an environment variable to that location.
  4. Build the project with the usual qmake/make commands.

Taken from: http://blog.outofhanwell.com/2006/05/01/linking-msvc-libraries-with-mingw-projects/

I am currently trying the visual studio plugin for QT, to try to build QT apps and use the VS compiler (and use my MSVC .libs)