Results 1 to 3 of 3

Thread: How you do *unescape* a string... and some weirdness

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2012
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default How you do *unescape* a string... and some weirdness

    Hello

    In my qmake file, I added to a variable the following:

    MYSQLIBS = "$$system(mysql_config --libs)"
    MYSQLIBS ~= s/-arch +[a-z0-9_]+//g #remove all "-arch arg" settings
    LIBS += MYSQLIBS

    Unfortunately here, LIBS in the generated Makefile now contains:
    LIBS = $(SUBLIBS) -L/usr/local/mythtv-trunk/lib -Wl,-Bsymbolic-functions\ -rdynamic\ -L/usr/lib/mysql\ -lmysqlclient


    see that all the space have been escaped.

    What I would like to end-up with is:
    LIBS = $(SUBLIBS) -L/usr/local/mythtv-trunk/lib -Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient

    Otherwise the following would fail to compile under linux.

    Now that brings me to another weirdness.
    The reason I did:

    MYSQLIBS = "$$system(mysql_config --libs)"
    instead of:
    MYSQLIBS = $$system(mysql_config --libs)

    It's because otherwise, the regex replacement that follow would have otherwise no effect at all, and it only works if the variable has been placed in quote.

    Another annoyance I do not know how to deal with is: on mac, some linker settings are in the form:
    -arch arg
    where arg can be i386, x86_64, ppc7400, ppc64

    The problem is how qmake deals when adding those parameters.
    If I have

    EXTRA_LFLAGS = -arch i386
    and
    QMAKE_LFLAGS = -arch i386

    doing:

    QMAKE_LFLAGS += $$EXTRA_LFLAGS

    The generated makefile will contain:
    LFLAGS = -arch i386 -arch

    the 2nd i386 has been dropped. Compilation *will* failt
    According to the qmake documentation, += shouldn't drop items, that's what *= does:
    The *= operator adds a value to the list of values in a variable, but only if it is not already present. This prevents values from being included many times in a variable. For example:

    Now I could do:
    EXTRA_FLAGS = "-arch i386"
    QMAKE_LFLAGS += $$EXTRA_FLAGS

    but then I end up in the Makefile with:
    LFLAGS = -arch i386 -arch\ i386

    which will not always work depending on how the linker is called.

    Any advice on how to resolve the above issues would be *extremely* appreciated.

    Thank you in advance.
    Kind regards
    JY

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How you do *unescape* a string... and some weirdness

    Each QMake variable is a list. The regex line in your example works on each value in the list in isolation. When you do not quote the system() output the list gets a populated with elements by splitting on white space. The "-arch" and "arg" go into separate list elements, neither of which matches your regex

    When you quote (or $$quote()) the system call output you put a single value in the list. Your qmake regex now works but anywhere the single list entry is output into a command line the spaces will be quoted as you have seen.

    I'd be inclined to do this on UNIX-ish systems:
    Qt Code:
    1. MYSQLIBS = $$system(mysql_config --libs | sed -r 's/-arch +[a-z0-9_]+//g')
    2. LIBS += MYSQLIBS
    To copy to clipboard, switch view to plain text mode 
    to remove the -arch arg before qmake sees it.

    However: you can also use the [wiki=Undocumented_qmake#Undocumented_functions]undocumented split()[/wiki] function thus:
    Qt Code:
    1. MYSQLIBS = $$quote($$system(mysql_config --libs))
    2. MYSQLIBS ~= s/-arch +[a-z0-9_]+//g #remove all "-arch arg" settings
    3. MYSQLIBS = $$split(MYSQLIBS," ")
    4. LIBS += $$MYSQLIBS
    To copy to clipboard, switch view to plain text mode 


    For the QMAKE_LFLAGS problem. I see the same effect on Linux when unquoted and I am guessing that internally the unique() function is used on the QMAKE_LFLAGS variable. When I do this:
    Qt Code:
    1. EXTRA_FLAGS = "-arch i386"
    2. QMAKE_LFLAGS += $$EXTRA_FLAGS
    To copy to clipboard, switch view to plain text mode 
    the second "-arch i386" completely disappears from the Makefile.

    Why do you need to duplicate this entry? Will the linker accept "-arch:386" or "-arch=386"?
    Last edited by ChrisW67; 3rd March 2012 at 00:55.

Similar Threads

  1. QString::append() weirdness
    By mattc in forum Qt Programming
    Replies: 16
    Last Post: 17th October 2010, 13:02
  2. [SOLVED] quint16 weirdness
    By pdoria in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2009, 00:09
  3. Memory leak weirdness
    By Darhuuk in forum General Programming
    Replies: 10
    Last Post: 10th January 2008, 18:51
  4. QSplashScreen Weirdness
    By mclark in forum Qt Programming
    Replies: 11
    Last Post: 19th November 2007, 06:49
  5. Alpha channel weirdness with QGLContext
    By renaissanz in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2006, 16:10

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.