How to link .o object library in QT Creator?



  • Hi all,

    I have a problem in linking the .o object library in my QT project.
    So this is what I wrote in the .pro file

    [code]
    LIBS += $$PRO_FILE_PWD/libs/triangle.o
    INCLUDEPATH += $$PRO_FILE_PWD/libs
    DEPENDPATH += $$PRO_FILE_PWD/libs
    [/code]

    In the $$PRO_FILE_PWD/libs directory has two files: "triangle.o", "triangle.h" and "triangle.c" (triangle.o is compiled in my machine so it should be compatible with my machine).
    But the QT Creator said "symbols not found", which means the definition of the functions declared in "trianle.h" cannot be found.

    Does anyone know why? Thanks a lot.



  • a .o file is not a DSO (dynamic shared object - .so .dll etc)

    if you want to treat it as a DSO, you will have to build and link it as such using a separate .pro where the main option is

    @
    TEMPLATE = lib
    @

    if you just want to include it during the linking of your main app,
    then i suggest you add the corresponding files to the qmake variables

    @
    SOURCES = triangle.h

    HEADERS = triangle.c
    @



  • Hi compor,

    Thanks for your answer.
    I understand your point. But I saw some similar posts in stack overflow and Qt Center, where some people said .o file can just work as well. Can you explain more details to me?

    http://stackoverflow.com/questions/4644643/how-to-add-object-files-to-a-project-in-qt

    http://www.qtcentre.org/threads/35033-How-to-link-to-o-object-file-in-a-QT-project

    Thank you very much.

    [quote author="compor" date="1389962078"]a .o file is not a DSO (dynamic shared object - .so .dll etc)

    if you want to treat it as a DSO, you will have to build and link it as such using a separate .pro where the main option is

    @
    TEMPLATE = lib
    @

    if you just want to include it during the linking of your main app,
    then i suggest you add the corresponding files to the qmake variables

    @
    SOURCES = triangle.h

    HEADERS = triangle.c
    @
    [/quote]



  • the main difference is that a DSO contains code that is relocatable,
    so many apps can link against it and use it at the same time.

    even if you are the only user, there are many benefits from distibuting your code as a DSO.
    there are plenty resources on the matter in the net.

    now, if you just want to use the .o file, maybe you could try the following

    @
    OBJECTS += triangle.o
    @

    or even

    @
    OBJECTS += $$PRO_FILE_PWD/libs/triangle.o
    @

    according to qmake's reference

    bq. This variable is generated from the SOURCES variable. The extension of each source file will have been replaced by .o (Unix) or .obj (Win32). The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

    so i'm not sure it will work as you intend it to.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.