Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. .pro file which creates one .so per .cpp

.pro file which creates one .so per .cpp

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 167 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by ocgltd
    #1

    I have a directory full of files (eg: dog.cpp, dog.h, cat.cpp, cat.h). I want to compile each of these into its own .so file (eg: dog.so, cat.so). My .pro file below compiles fine, but it puts all of the animal files into a single lib called libMYPROJ.so.1.0.0

    How can I tell QMake to create one lib per source file? BTW, I want to be able to drop more .cpp files into the directory without having to update the .pro file (so not looking to add each manually to the .pro)

    TEMPLATE = lib
    
    # Get a list of all the animal .cpp files in the libs directory
    ANIMAL_SOURCES = $$files(../src/cpp/*.cpp)
    message($$ANIMAL_SOURCES)
    
    # Create a library for each animal .cpp file
    for(FILE, ANIMAL_SOURCES) {
        # Extract the name of the animal from the file name
        ANIMAL = $$basename(FILE)
        # Create the library target for this animal
        LIBNAME = $${ANIMAL}.so
    #    message($$replace(LIBNAME, animal, test))
        $${ANIMAL}.target = $$LIBNAME
        $${ANIMAL}.sources = $$FILE
        # Add the library target to the list of targets
        SUBDIRS += $$ANIMAL
    #    LIBS += -l$$ANIMAL
    }
    
    # Build each animal type library
    define_build_subdirs {
        for(dir, SUBDIRS) {
            message("Building $$dir")
            SUBDIR = $$dir
            include($$dir/$${SUBDIR}.pro)
        }
    }
    
    # Link the libraries to the main project
    LIBS += -L$$PWD
    
    1 Reply Last reply
    0
    • W Offline
      W Offline
      wrosecrans
      wrote on last edited by
      #2

      By the time you are doing that level of QMake, you may just want to switch to using CMake. It's much better documented and more widely supported, so it's generally much easier to do unusual things with it.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved