multiple shared libraries from one project with common source files

人盡茶涼 提交于 2020-01-07 03:09:20

问题


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 contains one implementation of the of the "run" function of my plugin class. Now this Project compiles to "plugin.dll".

What i want to achieve is something like this:

  • 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

Is there an easy way to get these outputs out of one project? I'm using Qt-Creator on both Windows and Linux.


回答1:


There are two ways to solve the problem.

  1. You should use subprojects. Extract your common source-files into separate subproject as static library. More info here

  2. You may create .pri file:

    SOURCES += plugin.cpp
    HEADERS += plugin.h
    

and include it in all .pro files:

include(deployment.pri)


来源:https://stackoverflow.com/questions/34432748/multiple-shared-libraries-from-one-project-with-common-source-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!