使用Xenomai建立动态连接库
项目中须要Xenomai建立实时周期的任务,并封装为动态连接库,这里记录下遇到的问题。html
按照 QT编译xenomai用户层程序 中的步骤设置,创建好动态库工程以后。shell
编译,会发生以下错误:bootstrap
:-1: error: /usr/xenomai/lib/xenomai/bootstrap.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
提示编译动态库的时候须要加 -fPIC标志,添加以下:app
XCFLAGS = $(shell $$XENO_CONFIG -fPIC --skin=alchemy --cflags) XLDFLAGS = $(shell $$XENO_CONFIG -fPIC --skin=alchemy --ldflags)
编译经过,运行动态连接库,又发生下面的错误:ide
Segmentation fault(core dumped)
发生了堆栈溢出。spa
幸亏在Xenomai论坛中有人碰到一样的问题,.net
Cannot create a share library linked against Xenomai libscode
按照里面的描述,参考官方文档:htm
XENO-CONFIG(1) Manual Pageblog
--auto-init-solib This switch enables the auto-initialization feature described above for a shared library target instead of a pure executable. The main difference resides in a position-independent (PIC) glue code being used for bootstrapping the initialization.
在编译参数中添加 --auto-init-solib 标志
XCFLAGS = $(shell $$XENO_CONFIG --skin=alchemy --auto-init-solib --cflags) XLDFLAGS = $(shell $$XENO_CONFIG --skin=alchemy --auto-init-solib --ldflags)
再次运行,成功!