Closed zultron closed 10 years ago
Before I forget, the asm/system.h
issue is about that file being removed from Linux somewhere around v. 3.4.
Fixed in 909dfb6. Looks like base/arch/x86_64
is obsoleted by base/arch/x86
.
Good catch about asm/system.h
.
Why was base/arch/x86_64
even there then? I just checked and it's not there in the release tarball, but it's still there both in magma and vulcano! What a mess RTAI is!
Guessing based on the Xenomai project history, the x86 32-bit and 64-bit architectures used to have separate i-pipe patches, but a couple of years ago these were unified. Probably this required RTAI to unify these architectures too, but the obsolete x86_64
stuff simply wasn't removed.
It looks like magma was merged into the ShabbyX/RTAI repo since I built my original packages (I don't do a good job of staying up-to-date :P), and with the old build recipe (in Debian packaging form) still using x86_64
and the new unified code still with the obsolete code, things broke in a confusing way. The only google result I found wasn't helpful.
Anyway, now Machinekit is building against the latest ShabbyX/RTAI + linux 3.8.13 packages, next step is testing....
Magma hasn't been updated since 4 months ago! Speaking of that, I need to update it soon. So, in case something new breaks for you, that should be the cause! :-"
Hi guys,
I am trying to compile a simple module of RTAI and I get this error about /asm/system.h missing:
make -C /lib/modules/3.8.13-rtai/build SUBDIRS=pwd
modules
make[1]: Entering directory /usr/src/linux-headers-3.8.13-rtai' CC [M] /home/drugo/Hand_Project/Teensy_3_1/Teensy_RTAI/rtai_teensy_serial.o In file included from /usr/include/rtai/asm/rtai.h:20:0, from /usr/include/rtai/rtai.h:25, from /home/drugo/Hand_Project/Teensy_3_1/Teensy_RTAI/rtai_teensy_serial.c:11: /usr/include/rtai/asm/rtai_hal.h:269:24: fatal error: asm/system.h: No such file or directory compilation terminated. make[2]: *** [/home/drugo/Hand_Project/Teensy_3_1/Teensy_RTAI/rtai_teensy_serial.o] Error 1 make[1]: *** [_module_/home/drugo/Hand_Project/Teensy_3_1/Teensy_RTAI] Error 2 make[1]: Leaving directory
/usr/src/linux-headers-3.8.13-rtai'
make: *\ [rtai_teensy_serial] Error 2
It is actually not there within the folder /usr/include/rtai/asm/ do you know how to fix it? I have installed RTAI 4.0 Vulcano on Kernel 3.8.13 on Ubuntu 12.04 I have followed the installation steps to install the HART toolbox. RTAI is installed properly and it works. What is the problem? Actually I had to add path to the C_LIBRARY_PATH of gcc to let it find all the includes from RTAI which is sort of strange as well. Can you help me please?
Thanks Ugo
@drugolebowski85 first of all, it would help if you format the make
output as a code block, either with 4-space indentation, or surrounding it with three backticks.
Now that you know how to do that, please include your Makefile
as well. I suspect you are not using rtai-config
?
I have passed that phase but I think there is still something wrong...I am trying to create a FIFO within the module and destroy it. this is basically what I am doing, but I get two errors: one it cannot find the pthread library and the second it cannot find functions as rtf_create, rt_printk, rtf_put and rtf_destroy.
I type the output(I am sorry but I have not really get it how to format the make output hope it works):
make -C /usr/src/linux-stable SUBDIRS=
pwdmodules
make[1]: Entering directory
/usr/src/linux-stable'
Building modules, stage 2.
MODPOST 1 modules
WARNING: "rtf_create" [/home/drugo/Hand_Project/Teensy_3_1/Teensy_RTAI/rtai_teensy.ko] undefined!
WARNING: "rtf_destroy" [/home/drugo/Hand_Project/Teensy_3_1/Teensy_RTAI/rtai_teensy.ko] undefined!
WARNING: "rtf_put" [/home/drugo/Hand_Project/Teensy_3_1/Teensy_RTAI/rtai_teensy.ko] undefined!
WARNING: "rt_printk" [/home/drugo/Hand_Project/Teensy_3_1/Teensy_RTAI/rtai_teensy.ko] undefined!
LD [M] /home/drugo/Hand_Project/Teensy_3_1/Teensy_RTAI/rtai_teensy.ko
ld: cannot find -lpthread
make[2]: [/home/drugo/Hand_Project/Teensy_3_1/Teensy_RTAI/rtai_teensy.ko] Error 1
make[1]: [modules] Error 2
make[1]: Leaving directory /usr/src/linux-stable'
make: *** [rtai_teensy_serial] Error 2
The makefile is this one:
KERNEL_SOURCE = /usr/src/linux-stable
CC = gcc
EXTRA_CFLAGS= -ffast-math -mhard-float -I/usr/realtime/include -I$(KERNEL_SOURCE)/include -I$(KERNEL_SOURCE)/tools/perf/util/include/ -I/usr/src/comedi/include -I/usr/src/comedi -I/usr/include -I/usr/lib/i386-linux-gnu -I/usr/include/i386-linux-gnu -I/usr/include/i386-linux-gnu -DDEBUG # it works for making modules but not for building normal programs
EXTRA_LDFLAGS= -L/usr/realtime/lib -L/usr/lib/i386-linux-gnu -static
RTAIDIR = /usr/realtime RTAICONFIG = $(RTAIDIR)/bin/rtai-config
INCLUDEDIR=-ffast-math -mhard-float -I/usr/realtime/include -I$(KERNEL_SOURCE)/tools/perf/util/include/ -I/usr/src/comedi/include -I/usr/src/comedi -I/usr/include
LDFLAGS = -L/usr/lib $(shell $(RTAICONFIG) --lxrt-ldflags)
obj-m := rtai_teensy.o
rtai_teensy-objs := rtai_teensy_serial.o
default: rtai_teensy_serial
all: RTserial2FIFO debugger RTserial2FIFO RTserial2FIFO2 rtai_teensy_serial
rtai_teensy_serial: rtai_teensy_serial.c debugger.h Makefile
make -C ${KERNEL_SOURCE} SUBDIRS=pwd
modules
RTserial2FIFO: RTserial2FIFO.c debugger.h $(CC) $(INCLUDEDIR) $(LDFLAGS) RTserial2FIFO.c -o RTserial2FIFO $(INCLUDE) -DDEBUG -llxrt -lpthread
RTserial2FIFO2: RTserial2FIFO2.c debugger.h $(CC) $(INCLUDEDIR) $(LDFLAGS) RTserial2FIFO2.c -o RTserial2FIFO2 $(INCLUDE) -DDEBUG -llxrt -lpthread
debugger: debugger.c debugger.h comunica.h $(CC) $(INCLUDEDIR) $(LDFLAGS) debugger.c -o debugger $(INCLUDE) -DDEBUG -llxrt
clean: rm _~ .o .ko *.mod.c .rtaiteensy
Strange also I get a seg fault if I try to use real time FIFOs in user space I do not quite get that as well.
Thanks for helping me! Ugo
@drugolebowski85 See the github guide for Markdown for examples and explanations.
First of all, since Linux 2.6, that's not how you make kernel modules. There is a tool named rtai-config
that is also used for giving you the necessary flags. Also since Linux 2.6, the kernel Makefiles look for a file named Kbuild with the description what should be built (and they resort to your Makefile if missing, but better just have the Kbuild file).
So here is an example:
Makefile
:
EXTRA_CFLAGS += $(shell rtai-config --module-cflags) # Any other flag you want to put
KBUILD_EXTRA_SYMBOLS := $(shell rtai-config --module-dir)/Module.symvers
.PHONY: all clean
all:
@$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) \
EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
KBUILD_EXTRA_SYMBOLS="$(KBUILD_EXTRA_SYMBOLS)" \
modules
clean:
@$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) clean
And the Kbuild
file:
obj-m += your_module.o
your_module-y := source.o files.o of.o your.o module.o
And that's it! You don't need to specify the RTAI flags manually, or clean up kernel build files by yourself.
To build user-space applications with RTAI, you also use rtai-config
:
The previous Makefile
with added user-space application:
EXTRA_CFLAGS += $(shell rtai-config --module-cflags) # Any other flag you want to put
KBUILD_EXTRA_SYMBOLS := $(shell rtai-config --module-dir)/Module.symvers
EXTRA_CFLAGS_USER += $(shell rtai-config --lxrt-cflags)
EXTRA_LDFLAGS += $(shell rtai-config --ld-flags)
TARGET := your_user_app
.PHONY: all clean
all: $(TARGET)
@$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) \
EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
KBUILD_EXTRA_SYMBOLS="$(KBUILD_EXTRA_SYMBOLS)" \
modules
clean:
@$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) clean
$(TARGET): user.o app.o file1.o and.o file2.o
gcc -o $@ $^ $(EXTRA_LDFLAGS)
%.o: %.c some_header.h
gcc $(EXTRA_CFLAGS_USER) -o $@ -c $^
So try to build your application and kernel modules properly like above and see if it works.
Some other things to look out for are:
sudo
.I have remade the makefile not sure if I am right in the way I have remade it. This is how it looks:
EXTRA_CFLAGS += $(shell rtai-config --module-cflags) # Any other flag you want to put KBUILD_EXTRA_SYMBOLS := $(shell rtai-config --module-dir)/Module.symvers
EXTRA_CFLAGS_USER += $(shell rtai-config --lxrt-cflags) EXTRA_LDFLAGS += $(shell rtai-config --ld-flags)
TARGET := RTserial2FIFO
.PHONY: all clean all: $(TARGET) @$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) \ EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \ KBUILD_EXTRA_SYMBOLS="$(KBUILD_EXTRA_SYMBOLS)" \ modules clean: @$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) clean
$(TARGET): RTserial2FIFO.o gcc -o $@ $^ $(EXTRA_LDFLAGS)
RTserial2FIFO.o: RTserial2FIFO.c debugger.h gcc $(EXTRA_CFLAGS_USER) -o $@ -c $^
I have not quite got several things. 1) Should I create a separated file named Kbuild? 2) if I type make all on the terminal it comes out the help of the rtai config...I do not understand how should I run the makefile... 3) the makefile is probably wrong because I have not really understood how to modify it. the application that I am try to build is RTserial2FIFO.c and the module source is rtai_teensy_serial.c.Can you give me more help in writing this Makefile?
About eager inlining is activated, and about the sudo thing I am calling within the program this RTAI function rt_allow_nonroot_hrt(); that gives root privileges or it should give that, do you think is better using sudo?
Sorry there was a typo in what I sent you. After -c
(in the last line of Makefile), it should be $<
not $^
. You can read on what they mean here.
1,3) Yes you should create a separate Kbuild
file. The Kbuild
file is also where you define what kernel module you are building and what source files it has. Make sure to read all of the kernel's documentation on modules.
2) If you write rtai-config --module-cflags
on the terminal, what do you see?
About rt_allow_nonroot_hrt()
, I remember trying it once and it didn't work, but I may be wrong. I always used sudo
so I don't really know the difference.
I want to stress one thing though. Writing kernel modules is not like writing user space applications. You don't write something you don't fully understand because it's going to crash on you in such weird ways that you would be very hard pressed figuring it out. So I suggest you don't rush into RTAI, and instead try writing some simple non-RTAI kernel modules. Make sure you understand how they work and read about kernel modules as much as you can. Only when you feel comfortable with kernel space, then start using RTAI.
Thanks for your kind reply! Thanks also for the links I will check them out. There was another typo that I have corrected.
If I run rtai-config --module-cflags
I see -I. -I/usr/realtime/include -D_FORTIFY_SOURCE=0 -ffast-math -mhard-float
which is fair enough I guess just strange that there is -I.
but it looks it is working I have a linking error RTserial2FIFO.c:(.text.startup+0x414): undefined reference to
rtf_put'... if I run`rtai-config --lxrt-ldflags`I get`-L/usr/realtime/lib -lpthread
which is fine so I do not understand why is giving the error...can you help me?
I was used as you understood to write Kernel modules on Kernel version before 2.6 and using an older version of RTAI so that's why now I am having troubles...I know it is a pain in the ass sometimes because it is possible to stuck the whole system and the only solution is to unplug the power plug and replug it if something is wrong with the module :-) Can you help me with going on?
Thanks a lor I very appreciated
Ugo
Ok I was missing -llxrt
and I added the static linking, but now I get even more errors though any idea?
This is the output:
gcc -o RTserial2FIFO RTserial2FIFO.o -L/usr/realtime/lib -lpthread -llxrt -static /usr/realtime/lib/liblxrt.a(services.o): In function
rt_thread_create':
services.c:(.text+0x653): undefined reference to pthread_attr_init' services.c:(.text+0x66d): undefined reference to
pthread_attr_setstacksize'
services.c:(.text+0x6e5): undefined reference to pthread_create' /usr/realtime/lib/liblxrt.a(services.o): In function
rt_thread_join':
services.c:(.text+0x773): undefined reference to pthread_join' /usr/realtime/lib/liblxrt.a(services.o): In function
support_posix_timer':
services.c:(.text+0x1eec): undefined reference to pthread_kill' /usr/realtime/lib/liblxrt.a(services.o): In function
signal_suprt_fun_mq':
services.c:(.text+0x2184): undefined reference to pthread_kill' /usr/realtime/lib/liblxrt.a(services.o): In function
rt_request_signal_mq':
services.c:(.text+0x59b6): undefined reference to pthread_self' /usr/realtime/lib/liblxrt.a(services.o): In function
wrap_sem_wait':
services.c:(.text+0x7e4e): undefined reference to pthread_setcanceltype' services.c:(.text+0x7e53): undefined reference to
pthread_testcancel'
services.c:(.text+0x7e95): undefined reference to pthread_testcancel' services.c:(.text+0x7ea9): undefined reference to
pthread_setcanceltype'
/usr/realtime/lib/liblxrt.a(services.o): In function `wrap_sem_timedwait':
services.c:(.text+0x7fc2): undefined reference to pthread_setcanceltype' services.c:(.text+0x7fc7): undefined reference to
pthread_testcancel'
services.c:(.text+0x8013): undefined reference to pthread_testcancel' services.c:(.text+0x8027): undefined reference to
pthread_setcanceltype'
/usr/realtime/lib/liblxrt.a(services.o): In function __wrap_pthread_cond_wait': services.c:(.text+0x87c9): undefined reference to
pthread_setcanceltype'
services.c:(.text+0x87ce): undefined reference to pthread_testcancel' services.c:(.text+0x880b): undefined reference to
pthread_register_cancel'
services.c:(.text+0x8862): undefined reference to `pthread_unregister_cancel'
services.c:(.text+0x886e): undefined reference to pthread_testcancel' services.c:(.text+0x8882): undefined reference to
pthread_setcanceltype'
/usr/realtime/lib/liblxrt.a(services.o): In function __wrap_pthread_cond_timedwait': services.c:(.text+0x88dd): undefined reference to
pthread_setcanceltype'
services.c:(.text+0x88e2): undefined reference to pthread_testcancel' services.c:(.text+0x890a): undefined reference to
pthread_testcancel'
services.c:(.text+0x891e): undefined reference to pthread_setcanceltype' services.c:(.text+0x895a): undefined reference to
pthread_register_cancel'
services.c:(.text+0x89b6): undefined reference to `pthread_unregister_cancel'
/usr/realtime/lib/liblxrt.a(services.o): In function __wrap_clock_nanosleep': services.c:(.text+0x9451): undefined reference to
pthread_setcanceltype'
services.c:(.text+0x94fd): undefined reference to pthread_setcanceltype' /usr/realtime/lib/liblxrt.a(services.o): In function
__wrap_nanosleep':
services.c:(.text+0x954f): undefined reference to pthread_setcanceltype' services.c:(.text+0x95dd): undefined reference to
pthread_setcanceltype'
/usr/realtime/lib/liblxrt.a(services.o): In function __wrap_timer_settime': services.c:(.text+0x97d9): undefined reference to
pthread_self'
/usr/realtime/lib/liblxrt.a(services.o): In function rt_spset_callback_fun': services.c:(.text+0xa119): undefined reference to
pthread_create'
/usr/realtime/lib/liblxrt.a(services.o): In function rt_spset_err_callback_fun': services.c:(.text+0xa1e9): undefined reference to
pthread_create'
collect2: ld returned 1 exit status
make: *** [RTserial2FIFO] Error 1`
Please take a minute to learn Markdown, it's really not difficult. It's quite hard to read text formatted like that!
Nevertheless, the problem is that -lpthread
should come after -llxrt
. It's strange that rtai-config --lxrt-ldflags
doesn't already put that. Perhaps it's a bug with RTAI 4.0 release. Make sure you are using the latest release!
it puts that the problem is with the static linking the linker cannot find lipthread.a that is located /usr/lib/i386-linux-gnu/libpthread.a, how can I add another path for the ldflags?
I have tried in this way EXTRA_LDFLAGS += -L/usr/lib/i386-linux-gnu $(shell rtai-config --lxrt-ldflags) -llxrt -static
but it did not work :-(
If I compile it without static link, it compiles but then when it comes to compile the module I get another funny error the compiler cannot find stdio.h...How can I add in the CFLAGS other paths?
I am trying in this way but it does not work
EXTRA_CFLAGS += $(shell rtai-config --module-cflags) -I$(KERNEL_SOURCE)/include -D_DEBUG_
I never tried -static
and I don't know why you would want that either. But if it works without it, then just don't put it. Like I said, you need to put -llxrt
before -lpthread
. That's just how the linker works. So in your case, you can do:
EXTRA_LDFLAGS += $(shell rtai-config --lxrt-ldflags) -llxrt -lpthread -static
But anyway rtai-config --lxrt-ldflags
should already give you the correct flags and since it doesn't, I suspect you are using a bad version of RTAI.
About kernel modules, you don't need to add -I$(KERNEL_SOURCE)/include
. The kernel build system (that you call with $(MAKE) -C $(KERNEL_SOURCE)
) already sets all flags necessary. You can't include stdio.h
because that's a user-space header. In the kernel, there is no such thing as printf
for example. In kernel space, you should use kernel space headers and functions.
Again, please take some time getting acquainted with the newer kernels (a LOT has changed since Linux 2.4), especially when it comes to building, logging, procfs
etc and then start with RTAI.
-lpthread is inserted by the rtai-config since it gives as output -L/usr/realtime/lib -lpthread
About the static I guess the idea is that the executable already contains the libraries that are needed these speed ups the computation and probably avoid problems in accessing dynamic libraries. I have this problem also with the HART toolbox when it generates the executable from the xcos simulator.
Actually I have ran my application communicating with the xcos with a real-time FIFO and I have stuck the PC. I suspect the problem is exactly on the failing of compiling everything in a static way.
Any idea about how to compile in a static way?I ask because the static version there is, it is only a matter on link it :-)
About RTAI not sure if it is a bad version or not I have followed this link to install it: http://hart.sourceforge.net/rtai/installation_12_04.html Do you think is a bad version of RTAI?
-lpthread
is inserted by rtai-config
, but you are adding -llxrt
after it. The order matters. I repeated -lpthread
because the linker should see pthread
after trying to resolve symbols from lxrt
.
It looks like you got the latest version from vulcano
. I don't really know what bugs it may have since we are maintaining an unofficial improved version based on magma
here. You could try getting the released package of RTAI from it's official website: http://rtai.org/ (right panel where it says RTAI 4.0 released) and see what happens.
Ok inverting the order made me compile it also statically! Thanks a lot for your help! About RTAI I will see how I go because reinstalling everything can be a pain in the ass... I still miss a static library for portaudio fortunatly I do not need it for the automatically RTAI code generation using Scilab/Xcos...just in case you probably know, how can I install it? I have also another problem after installing this version of RTAI with the kernel 3.8.13 I have problems also with the sound card that does not work properly it stucks and then restart making a jumping sound...do you know anything about that?
I will tell you how I go if I can realize what I need! Really thanks a lot you made my day :-)
After muddling through a bunch of other problems, packages finally build, but building Machinekit, I've hit the wall. AFAICT, the two things colliding here are the 3.8 kernel and the update to magma.
Here's a sampling of some errors and warnings:
Removing
asm/system.h
from those header files isn't a working hack:(...and many more)
This could be a simple fix, but I can't spend more time on this now.