来自一个具有公共源文件的项目的多个共享库 [英] multiple shared libraries from one project with common source files
问题描述
我有一个主要的应用程序,可以通过动态加载插件(.dll on win - .so on linux)。现在我想创建很多这些插件,其中只是在函数实现不同。
I have a main application wich can be controlled by dynamically loaded plugins (.dll on win - .so on linux). Now i want to create a lot of these plugins where just on function is implemented different.
假设我有我的项目中的以下文件:
Lets say i have the following files in my Project:
- plugin.h
- plugin.cpp
- i001.cpp
i001.cpp包含了我的插件类的run函数的一个实现。现在这个项目编译为plugin.dll。
i001.cpp contains one implementation of the of the "run" function of my plugin class. Now this Project compiles to "plugin.dll".
我想实现的是这样的:
- plugin.h + plugin.cpp + i001.cpp - > i001.dll
- plugin.h + plugin.cpp + i002.cpp - > i002.dll
- plugin.h + plugin.cpp + i003.cpp - > i003.dll
- plugin.h + plugin.cpp + i004.cpp - > i004.dll
- plugin.h + plugin.cpp + i001.cpp --> i001.dll
- plugin.h + plugin.cpp + i002.cpp --> i002.dll
- plugin.h + plugin.cpp + i003.cpp --> i003.dll
- plugin.h + plugin.cpp + i004.cpp --> i004.dll
有一个简单的方法来从一个项目中获得这些输出?
我在Windows和Linux上使用Qt-Creator。
Is there an easy way to get these outputs out of one project? I'm using Qt-Creator on both Windows and Linux.
推荐答案
有两种方法来解决问题。
There are two ways to solve the problem.
-
您应该使用子专案。将您的公共源文件提取为单独的子项目作为静态库。更多信息此处
您可以创建.pri文件:
You may create .pri file:
SOURCES += plugin.cpp
HEADERS += plugin.h
并将其包含在所有.pro文件中:
and include it in all .pro files:
include(deployment.pri)
这篇关于来自一个具有公共源文件的项目的多个共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!