<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[.pro file which creates one .so per .cpp]]></title><description><![CDATA[<p dir="auto">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: <a href="http://dog.so" target="_blank" rel="noopener noreferrer nofollow ugc">dog.so</a>, <a href="http://cat.so" target="_blank" rel="noopener noreferrer nofollow ugc">cat.so</a>). My .pro file below compiles fine, but it puts all of the animal files into a single lib called libMYPROJ.so.1.0.0</p>
<p dir="auto">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)</p>
<pre><code>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
</code></pre>
]]></description><link>https://forum.qt.io/topic/143237/pro-file-which-creates-one-so-per-cpp</link><generator>RSS for Node</generator><lastBuildDate>Wed, 06 May 2026 01:55:19 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/143237.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 25 Feb 2023 00:37:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to .pro file which creates one .so per .cpp on Sat, 25 Feb 2023 17:12:27 GMT]]></title><description><![CDATA[<p dir="auto">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.</p>
]]></description><link>https://forum.qt.io/post/749086</link><guid isPermaLink="true">https://forum.qt.io/post/749086</guid><dc:creator><![CDATA[wrosecrans]]></dc:creator><pubDate>Sat, 25 Feb 2023 17:12:27 GMT</pubDate></item></channel></rss>