PDA

View Full Version : Using external ANSI C library



npascual
5th May 2011, 11:45
Hello,

It's possible to include in a Qt project an external library written in ANSI C??

I tried it writting,


#include "library.h"

in my source program, and inserting


LIBS += -Llibrary.lib

in my project definition.

When I compile the project, it seems that Qt finds the library correctly, but I get the followings error messages


undefined reference to 'library_function@8'



Help me please!! Thanks!!

mcosta
5th May 2011, 12:01
HI, you have to provide "external linkage" information to your compiler

Try with


extern "C" {
#include "library.h"
}


Notice that the correct syntax for linking libraries in .pro file is


LIBS += -L<library_path> -l<library_basename>


Eg


LIBS += -Llibs/ -llibrary

squidge
5th May 2011, 12:02
Do you state the fact that the library is a C-style library (rather than C++) in the header file or before the #include statement?

Eg.


extern "C" {
#include "mylib.h"
};