Makefile for user space hal componet

More
25 Jan 2013 14:12 - 25 Jan 2013 16:24 #29123 by maculata
I am trying to develop a user space c/c++ component. I have been successful with python components. I can find documentation on the the c functions to call and many examples. Good - if a little uneven documentation. I installed 2.5.1 using the quick start CD. It went flawlessly. I have developed and am running a both a Linux servo driver and parallel port drivers for the dmm-tech AC servos. (I have no affiliation with the company) I will at some point share the code it there is interest.

I have been unable to get a makefile that will compile a c/c++ hal component. I have found some of the needed include files but not the correct libraries. I am not wanting to put the component into the linuxcnc area yet - I want to develop it in a separate area and use it first. I think that this is o.k. as it is a user space component (like the python ones I have).

I have looked at the linuxcnc Makefile and can glean almost nothing from it. I hope my Makefile is very simple by comparison. Here is what I currently have:

Makefile:
all : get_linux_time

get_linux_time : get_linux_time.cc
g++ -Wno-write-strings -o get_linux_time -I/home/cnc/linuxcnc/linuxcnc-dev/src/hal -I/home/cnc/linuxcnc/linuxcnc-dev/src/rtapi -L/usr/lib/liblinuxcnchal.so -L/usr/lib/liblinuxcnchal.so.0 -L/usr/lib/libhal-storage.so -L/usr/lib/libhal.so get_linux_time.cc

clean :
rm get_linux_time


Here is my C componet: "get_linux_time.cc"

#include <stdio.h>
#include <stdlib.h>

#define ULAPI
#include <hal.h>

void user_mainloop(void)
{
int cid; // Hal componet ID

printf("Hello world!\n");

cid = hal_init("New_clk");

printf("Hal componet id %i\n",cid);
}

And here is my error:
cnc@ubuntucnc:~/ptest$ make get_linux_time
g++ -Wno-write-strings -o get_linux_time -I/home/cnc/linuxcnc/linuxcnc-dev/src/hal -I/home/cnc/linuxcnc/linuxcnc-dev/src/rtapi -L/usr/lib/liblinuxcnchal.so -L/usr/lib/liblinuxcnchal.so.0 -L/usr/lib/libhal-storage.so -L/usr/lib/libhal.so get_linux_time.cc
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
/tmp/cczIcglj.o: In function `user_mainloop()':
get_linux_time.cc:(.text+0x1a): undefined reference to `hal_init'
collect2: ld returned 1 exit status
make: *** [get_linux_time] Error 1
cnc@ubuntucnc:~/ptest$

-->> What do I need in the make files for includes and libraries?

Thanks for any help. I have spent several hours on this already.

-->> One other question. where is comp ? or how do I build it?

cnc@ubuntucnc:~/ptest$ comp
The program 'comp' can be found in the following packages:
* mailutils-mh
* nmh

I can not find a "comp" the target in the big Makefile. And "comp" matches about 1000 files using the linux "locate comp". Is there something I did not get installed correctly? I have found most things work with my install: Step conf, glade, gtk, all the hal components, python API, ... "comp" is the only thing that has not worked. I can even find the comp.c code. I have been unwilling to risk a make all of the entire linuxcnc tree without some advice.

Thanks again,
Tim
Last edit: 25 Jan 2013 16:24 by maculata.

Please Log in or Create an account to join the conversation.

More
25 Jan 2013 15:30 - 25 Jan 2013 15:32 #29124 by ArcEye
Hi

I think you are looking in the wrong place. comp is a python script and installed in /usr/bin
see this for usage
linuxcnc.org/docs/2.5/html/hal/comp.html

If you already have a C file to compile the below should also work
gcc -Os -g -I. -I/usr/realtime-2.6.32-122-rtai/include -I. -I/usr/realtime-2.6.32-122-rtai/include -D_FORTIFY_SOURCE=0 \
	    -mhard-float -DRTAI=3 -fno-fast-math -mieee-fp -fno-unsafe-math-optimizations -DRTAPI -D_GNU_SOURCE -Drealtime \
	    -D_FORTIFY_SOURCE=0 -D__MODULE__ -I/usr/include/emc2 -Wframe-larger-than=2560 -URTAPI -U__MODULE__ -DULAPI -Os \
	     -o foo foo.c -Wl,-rpath,/lib -L/lib -lemchal

If your code is C++ you may need to use g++ instead of gcc

regards
Last edit: 25 Jan 2013 15:32 by ArcEye.

Please Log in or Create an account to join the conversation.

More
25 Jan 2013 16:16 #29125 by maculata
I do not find comp in /usr/bin .... I did find classicladder, several glade*, and many hal* executables in /usr/bin. Is there anywhere else in the linuxcnc distribution I could find the comp file? I can always copy it to /usr/bin.

Thanks for the makefile help. I will try it Friday. I an a little surprised that there is a reference to /usr/include/emc2 in it as I thought that emc2 had been purge from most every thing. I have tried to use linuxcnc branded files and avoid emc2 files.

Please Log in or Create an account to join the conversation.

More
25 Jan 2013 20:54 #29133 by BigJohnT


-->> One other question. where is comp ? or how do I build it?

Thanks again,
Tim


Tim,

The comp script is not installed by default, you have to install dev as described here .

John

Please Log in or Create an account to join the conversation.

More
26 Jan 2013 00:39 - 27 Jan 2013 18:36 #29142 by ArcEye

an a little surprised that there is a reference to /usr/include/emc2 in it as I thought that emc2 had been purge from most every thing. I have tried to use linuxcnc branded files and avoid emc2 files


That is because I use my house machine for development and have done since long before the name change. I just symlinked everything emc to the equivalent linuxcnc and carried on as previously!
You may want to change -lemchal too

The comp script is not installed by default, you have to install dev


My various versions of Linuxcnc have all been built from sources, so I wasn't aware that comp was still not in the .deb, I thought it was all included together since 2.5 :unsure:
Last edit: 27 Jan 2013 18:36 by ArcEye.

Please Log in or Create an account to join the conversation.

More
10 Feb 2013 16:13 #29845 by maculata
I was able to get a c hal user space componet working. The proceedure I used:

(1) fully installed the linuxcnc dev as per BigJohnT link (it worked just fine)
(2) created a componet *.comp version of what I wanted
(3) debugged it
(4) used the comp <myfile>.comp to create the c code
(5) Used the comp generated C does to understand he HAL c interface
(6) adapted the comp generated c code to my c file
(7) used comp's build output to create my make file

Here is the Makefile:

#
#
.PHONY: all clean
CC = gcc
OPTIONS = -Os -g -I. -I/usr/realtime-2.6.32-122-rtai/include -I. -I/usr/realtime-2.6.32-122-rtai/include -D_FORTIFY_SOURCE=0 -mhard-float -DRTAI=3 -fno-fast-math -mieee-fp -fno-unsafe-math-optimizations -DRTAPI -D_GNU_SOURCE -Drealtime -D_FORTIFY_SOURCE=0 -D__MODULE__ -I/usr/include/linuxcnc -Wframe-larger-than=2560 -URTAPI -U__MODULE__ -DULAPI -Wl,-rpath,/lib -L/lib -llinuxcnchal

all : ltime

ltime : ltime.c
${CC} ${OPTIONS} -o ltime ltime.c

Please Log in or Create an account to join the conversation.

Time to create page: 0.077 seconds
Powered by Kunena Forum