[SOLVED]QMAKE_CXXFLAGS += -static doesn't work



  • I trying to create a statically linked application.

    For simplicity I created a Non-Qt Project --> Plain C Text like this:

    @#include <stdio.h>

    int main(void)
    {
    printf("Hello World!\n");
    return 0;
    }@

    If I compile and link in a terminal:

    gcc -static -c -o main main.c

    or if I do in 2 steps:

    gcc -static -c -o main.o main.c
    g++ -static -o main main.o

    I get a statically linked application, but if I do in QtCreator it doesn't work.
    My .pro file is:

    TEMPLATE = app
    CONFIG += console
    CONFIG -= qt
    QT -= core gui

    QMAKE_CXXFLAGS += -static
    QMAKE_CFLAGS = -static

    SOURCES += main.c

    and the senteces that make execute are:

    gcc -c -static -O2 -Wall -W -DQT_WEBKIT -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -o main.o main.c
    g++ -m64 -Wl,-O1 -o prueba main.o

    ¿Why it doesn't appear option -static in g++?

    I also tried with QMAKE_CXXFLAGS_RELEASE = -static and QMAKE_CXXFLAGS_DEBUG = -static with identical result.


  • Lifetime Qt Champion

    Hi,

    IIRC, -static is a linker flag, so you might want to try to add it to QMAKE_LFLAGS_RELEASE/QMAKE_LFLAGS.



  • Thank you so much, SGaist.

    It works if my .pro file is:

    TEMPLATE = app
    CONFIG += console
    CONFIG -= qt
    QT -= core gui

    QMAKE_CFLAGS = -static
    QMAKE_LFLAGS += -static

    SOURCES += main.c


Log in to reply
 

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