Home > front end >  Convert a C project to Library to use in QT
Convert a C project to Library to use in QT

Time:10-30

I have a C project which spits out an executable. I want to convert that project into a library which I want to use in my QT C application.

I am hitting a wall. Can someone provide me any information on it?

So I have been looking at https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application#Creating_a_static_library

I created a no-qt project to compile and it generates a .a file. Here is my .pro file

TEMPLATE = lib
CONFIG  = staticlib
CONFIG -= app_bundle
CONFIG -= qt

SOURCES  = \
    libmnl/dhcp/dhcpclient.c \
    libmnl/dhcp/dhcpmsg.c \
    libmnl/dhcp/packet.c \
    libmnl/attr.c \
    libmnl/callback.c \
    libmnl/ifutils.c \
    libmnl/nlmsg.c \
    libmnl/socket.c \
    atc.c \
    atchannel.c \
    at_tok.c \
    device.c \
    GobiNetCM.c \
    mbim-cm.c \
    MPQMUX.c \
    qmap_bridge_mode.c \
    QMIThread.c \
    QmiWwanCM.c \
    udhcpc_netlink.c \
    util.c

HEADERS  = \
    libmnl/dhcp/dhcp.h \
    libmnl/dhcp/dhcpmsg.h \
    libmnl/dhcp/packet.h \
    libmnl/ifutils.h \
    libmnl/libmnl.h \
    atchannel.h \
    at_tok.h \
    MPQMUX.h \
    QMIThread.h \
    util.h

DISTFILES  =


QMAKE_CFLAGS  = -Wall #-s
QMAKE_LFLAGS  = -lpthread -ldl -lrt

LIBS  = -pthread

My understanding tells me that my C project spits out an executable instead I want it to spit out a library and a header

Which I could then add it to my QT project

CodePudding user response:

Does this help:

https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application

Note that I have C libraries that I include in my Qt projects and don't have to do anything special at all. I just produce libFOO.a and then edit my Qt projects .pro file to add -L and -lFOO. Here is a cut & paste from one such project.

LIBS  = -L../MyLib/lib -lMyLib

You might also have to add something like this:

INCLUDEPATH  = ../MyLib/src

Notice there's no -I on this.

  • Related