问题描述
2.8的CMake
海湾合作委员会(GCC)4.8.1
编辑----------
结束语静态库在全归档
适用于除 pjmedia-videodev每个库
现在的问题是当我尝试建立我碰到下面的错误。
cbar_factory_init':colorbar_dev.c :(文字+ 0x2a0):未定义引用pjmedia_format_init_video
您好,
我创建了一个共享库,我需要的库约10静态库链接。然后我联系我的可执行文件,共享库。
我的问题是,当我运行make失败联系起来,因为它希望静态库为好。的目的是创建用于静态库的包装。因此,可执行只有1单一的共享库链接。由于我与静态链接共享库,那么静将自动成为共享库的源$ C $ C的一部分。
只有code sippnets使之短。
在我的CMakeLists.txt创建共享库和链接的静态库:
add_library(app_module_sip SHARED app_module_sip_init.c) 设置(PJSIP_LIBRARIES
g7221 codeC
GSM codeC
ILBC codeC
MILENAGE
PJ
pjlib-UTIL
pjmedia
pjmedia- codeC
pjmedia-AUDIODEV
pjmedia-videodev
pjnath
PJSIP
PJSIP简单的
PJSIP-UA
pjsua
portaudio
重采样
Speex语音
SRTP
)target_link_libraries(app_module_sip的pthread米UUID NSL RT asound在加密的SSL $ {} PJSIP_LIBRARIES)
现在我的CMakeLists.txt,使可执行
add_executable(APP sip_test.c)target_link_libraries(APP app_module_sip)
这是正确的我在做什么在这里。我不想可执行文件与静态库链接。就在单一的共享库,因为这是我的包装什么,我会中调用的功能。
它确实联系好的,如果我链接使所有可执行文件时的静态库,但是这不是我想要的结果。
非常感谢您的任何建议,
#位置的共享库
集(LIBRARY_OUTPUT_PATH $ {} PROJECT_SOURCE_DIR /库)#创建共享库
add_library(app_module_sip SHARED app_module_sip_init.c)#编译和链接的32位模式
set_target_properties(app_module_sip性能COMPILE_FLAGS-m32LINK_FLAGS-m32)#PJSIP静态库
设置(PJSIP_LIBRARIES
pjsua
PJSIP-UA
PJSIP简单的
PJSIP
pjmedia- codeC
pjmedia-videodev
pjmedia
pjmedia-AUDIODEV
pjnath
pjlib-UTIL
重采样
MILENAGE
SRTP
GSM codeC
Speex语音
ILBC codeC
g7221 codeC
portaudio
PJ
)#裹静态库中的共享库
target_link_libraries(app_module_sip轮候册, - 启动组$ {} PJSIP_LIBRARIES轮候册, - 端基
米UUID NSL RT的pthread asound在加密的SSL)
需要包装的PJSIP库将下面的链接命令轮候册, - 启动组* .A轮候册, - 端基
这解决了我的问题。
cmake 2.8
gcc (GCC) 4.8.1
Edit ----------
Wrapping the static libraries in whole-archive
works for every library except the pjmedia-videodev
The problem now is that when I try and build I get the following error.
cbar_factory_init': colorbar_dev.c:(.text+0x2a0): undefined reference to pjmedia_format_init_video'
Hello,
I have created a shared library and I need to link that library with about 10 static libraries. I then link my executable with the shared library.
My question is that when I run make it fails to link as it wants the static libraries as well. The purpose of is to create a wrapper for the static libraries. So the executable only has to link with 1 single shared library. As I am linking the shared library with the statics, then the statics will automatically become part of the source code of the shared library.
Only code sippnets to make it short.In my CMakeLists.txt that creates the shared library and links the static libraries:
add_library(app_module_sip SHARED app_module_sip_init.c)
set(PJSIP_LIBRARIES
g7221codec
gsmcodec
ilbccodec
milenage
pj
pjlib-util
pjmedia
pjmedia-codec
pjmedia-audiodev
pjmedia-videodev
pjnath
pjsip
pjsip-simple
pjsip-ua
pjsua
portaudio
resample
speex
srtp
)
target_link_libraries(app_module_sip pthread m uuid nsl rt asound crypto ssl ${PJSIP_LIBRARIES})
Now my CMakeLists.txt that makes the executable
add_executable(app sip_test.c)
target_link_libraries(app app_module_sip)
Is this correct what I am doing here. I don't want to link the executable with the static libraries. Just the single shared library as that is my wrapper what I will be calling the functions in.
It does link ok, if I link all the statics libraries when making the executable, but that is not the result I want.
Many thanks for any suggestions,
# Location for shared library
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/libs)
# Create shared library
add_library(app_module_sip SHARED app_module_sip_init.c)
# compile and link for 32 bit mode
set_target_properties(app_module_sip PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
# PJSIP static libraries
set(PJSIP_LIBRARIES
pjsua
pjsip-ua
pjsip-simple
pjsip
pjmedia-codec
pjmedia-videodev
pjmedia
pjmedia-audiodev
pjnath
pjlib-util
resample
milenage
srtp
gsmcodec
speex
ilbccodec
g7221codec
portaudio
pj
)
# Wrap the static libraries in to the shared library
target_link_libraries(app_module_sip -Wl,--start-group ${PJSIP_LIBRARIES} -Wl,--end-group
m uuid nsl rt pthread asound crypto ssl)
Need to wrap the pjsip libraries will the following linker command -Wl,--start-group *.a -Wl,--end-group.
That solved my problem.
这篇关于连接使用CMake的静态共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!