使用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)
再次運行,成功!