Cmake 添加共享库和可执行文件,编译源文件两次
你好, 我想知道是否有办法解决以下问题。我强调如下:Cmake 添加共享库和可执行文件,编译源文件两次,cmake,Cmake,你好, 我想知道是否有办法解决以下问题。我强调如下: gcc (GCC) 4.7.2 cmake version 2.8.11 我希望您能看到上面的问题,因为我正在两次编译相同的源文件。一次创建dlg_gw库。然后再次创建可执行的sun_gw 我正在考虑取出“void mainvoid”并将其放入名为runtime.c的新文件中,然后执行以下操作: SET(GW_SOURCE_FILES module.c module_imp.c module_message.c m
gcc (GCC) 4.7.2
cmake version 2.8.11
我希望您能看到上面的问题,因为我正在两次编译相同的源文件。一次创建dlg_gw库。然后再次创建可执行的sun_gw
我正在考虑取出“void mainvoid”并将其放入名为runtime.c的新文件中,然后执行以下操作:
SET(GW_SOURCE_FILES
module.c
module_imp.c
module_message.c
module_config.c
module_queue.c)
# Compiles the source files to create the shared library called dlg_gw.so
ADD_LIBRARY(dlg_gw SHARED ${GW_SOURCE_FILES})
# Link additional libraries to this
TARGET_LINK_LIBRARIES(dlg_gw gc srl ${APRUTIL})
# ISSUE: Now I want to create my executable using the same source files. module.c is where my 'void main(void)' is.
# However, I have some functions in there which will also be part of the library.
# However, this will recompile the same source files all over again. I don't really like that behaviour.
ADD_EXECUTABLE(sun_gw ${GW_SOURCE_FILES})
# After the executable is created, link the libraries with it.
TARGET_LINK_LIBRARIES(sun_gw ${APR} driver dlg_gw dlg_sip dlg_ss7 dlg_isdn)
但以上要求我修改一些源代码
非常感谢任何其他建议,可以使用CMake 2.8.8中引入的对象库类型来避免重复构建相同的文件
请参见CMake 2.8.8中引入的对象库类型可用于避免重复生成相同的文件
请参见您的修复对我来说似乎是正确的选择。库不应该定义主函数。这很有道理。您的修复对我来说似乎是正确的选择。库不应该定义主函数,这很有道理。
ADD_EXECUTABLE(sun_gw runtime.c)