Results 1 to 3 of 3

Thread: Using external ANSI C library

  1. #1
    Join Date
    Mar 2011
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Using external ANSI C library

    Hello,

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

    I tried it writting,

    Qt Code:
    1. #include "library.h"
    To copy to clipboard, switch view to plain text mode 

    in my source program, and inserting

    Qt Code:
    1. LIBS += -Llibrary.lib
    To copy to clipboard, switch view to plain text mode 

    in my project definition.

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

    Qt Code:
    1. undefined reference to 'library_function@8'
    To copy to clipboard, switch view to plain text mode 



    Help me please!! Thanks!!

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using external ANSI C library

    HI, you have to provide "external linkage" information to your compiler

    Try with
    Qt Code:
    1. extern "C" {
    2. #include "library.h"
    3. }
    To copy to clipboard, switch view to plain text mode 

    Notice that the correct syntax for linking libraries in .pro file is
    Qt Code:
    1. LIBS += -L<library_path> -l<library_basename>
    To copy to clipboard, switch view to plain text mode 

    Eg
    Qt Code:
    1. LIBS += -Llibs/ -llibrary
    To copy to clipboard, switch view to plain text mode 
    Last edited by mcosta; 5th May 2011 at 13:28. Reason: updated contents
    A camel can go 14 days without drink,
    I can't!!!

  3. The following user says thank you to mcosta for this useful post:

    npascual (9th May 2011)

  4. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using external ANSI C library

    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.
    Qt Code:
    1. extern "C" {
    2. #include "mylib.h"
    3. };
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to squidge for this useful post:

    npascual (9th May 2011)

Similar Threads

  1. Problem with link of external Library
    By navratill in forum Qt Programming
    Replies: 4
    Last Post: 4th May 2011, 08:18
  2. Replies: 4
    Last Post: 6th March 2011, 12:10
  3. Qt Creator and using an external library under windows
    By QChristian in forum Installation and Deployment
    Replies: 1
    Last Post: 15th September 2010, 17:12
  4. how to link external library in qt linux?
    By qtlinuxnewbie in forum Qt Programming
    Replies: 2
    Last Post: 5th March 2010, 09:11
  5. Adding an external Library
    By afflictedd2 in forum Qt Programming
    Replies: 1
    Last Post: 13th December 2008, 05:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.