Results 1 to 4 of 4

Thread: qmake to compile all files in a directory and make a library for each file

  1. #1
    Join Date
    Mar 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default qmake to compile all files in a directory and make a library for each file

    I want to write a qmake file to compile all .cpp files in a working directory.

    It should also create a .so library for each file.

    Is this possible?

    I can do this easily with a simple script:

    #read all files in the current directory
    files=*.cpp

    #loop over files content
    for file in $files;
    do
    name=${file%.*}
    if [ ! -f $1 ]; then
    echo "The file $1 does not exist."
    exit
    else

    #compile the new library
    g++ -fPIC -c $name.cpp -o $name.o -lgsl -lgslcblas
    g++ -shared -Wl,-soname,lib$name.so -o lib$name.so $name.o -lgsl -lgslcblas

    fi
    fi
    exit 0

  2. #2
    Join Date
    Mar 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: qmake to compile all files in a directory and make a library for each file

    For one file I am able to compile using the simple qmake file below,
    but what about compiling all (*.cpp) files in the directory and make an executable (library) for each?
    Is there something like a loop in qmake?

    Thanks

    Qt Code:
    1. QT -= core gui
    2.  
    3. TEMPLATE = lib
    4.  
    5. LIBS += -lgsl -lgslcblas
    6.  
    7. DEFINES += TEST_LIBRARY
    8.  
    9. SOURCES += test.cpp
    10.  
    11. HEADERS += sharedheader.h
    12.  
    13. TARGET = test
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qmake to compile all files in a directory and make a library for each file

    You could have one .pro file per library and then a .pro file with TEMPLATE=subdirs that lists all these other .pro files in its SUBDIRS variable.

    When you add a new library you add its .pro to that file (or you generate that file with a script)

    Cheers,
    _

  4. #4
    Join Date
    Mar 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: qmake to compile all files in a directory and make a library for each file

    Quote Originally Posted by anda_skoa View Post
    You could have one .pro file per library and then a .pro file with TEMPLATE=subdirs that lists all these other .pro files in its SUBDIRS variable.

    When you add a new library you add its .pro to that file (or you generate that file with a script)

    Cheers,
    _
    Thanks. I was trying to avoid writing scripts and many steps, since the GUI will be also compiled by users who would have to build (if needed) their own libraries.
    So I am trying to make it as simpler as possible.

Similar Threads

  1. make: /Users/.../bin/uic: No such file or directory
    By Seth90 in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2011, 11:57
  2. Replies: 3
    Last Post: 24th March 2011, 10:10
  3. Compile and Install files on qmake
    By gava100 in forum Installation and Deployment
    Replies: 0
    Last Post: 25th October 2010, 19:48
  4. qmake doesn't make a 'make' file
    By elyness in forum Installation and Deployment
    Replies: 1
    Last Post: 4th August 2010, 15:21
  5. Replies: 4
    Last Post: 7th April 2010, 23:09

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.