How to link .a lib in my hal comp ?

More
01 Nov 2014 13:35 #52642 by blightxdm1
Hello Everyone,
I'm tring to compile a hal component from a c file , and which need to link a static lib file (.a ), and i find no any compile option for linking lib in the comp's help document .
Or if comp can't do that , is there any other way to let the comp c file use static lib ?
Thank you very much.

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

More
01 Nov 2014 15:36 #52646 by ArcEye
Hi

You need to use comp to generate a .c file then build on the commandline, including the lib you want to use.

For instance this includes the modbus lib
gcc -Os -g -I. -I/usr/realtime/include -I. -I/usr/src/linuxcnc-dev-rtai/include -I/usr/include/modbus \
	    -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 -Os \
	     -o {BINARY_NAME} {PROGRAM}.c -Wl,-rpath,/lib -L/lib -L/usr/lib -L/usr/src/linuxcnc-dev-rtai/lib -llinuxcnchal -llinuxcnc -lmodbus

All the DEFINES etc are right for building rt modules, however the paths shown need changing for yours, because mine will not exist on your machine.

regards

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

More
01 Nov 2014 16:07 #52647 by mariusl
Hi Arceye
Is there no make file in existence for components? What would one do if you used Eclipse or the likes of?
How do the guys do it that write these complex drivers or components that looks like normal C code. I mean it does not look like a component that was compiles with comp.
I looked at the hal_skeleton.c but want to use it from Eclipse with the debugger.

Regards
Marius


www.bluearccnc.com

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

More
01 Nov 2014 21:56 #52664 by ArcEye

Is there no make file in existence for components?


No. In fact there is no C SDK for linuxcnc, the nearest thing to it are the python access functions, which were written in C anyway.

The comp files are essentially macros surrounding the main program loop section of the file, to hide the complexity of the hal calls, memory allocation, creation of pins etc required to create the component.

If you create the component solely in C, you can pare all that down to the bone, so the file looks a bit different from the C code generated from comp, but the same processes need to be done.

The gcc lines I posted are exactly what comp uses, with a couple of additions

What would one do if you used Eclipse or the likes of?


You can compile rt components in Qt, which I do regularly and use the qmake system to produce a Makefile.

All the defines and compiler switches are then put into the CPPFLAGS etc of the Makefile

eg this .pro file used to create a Makefile
QT       += core
QT       += network
QT       -= gui

TARGET = tcpsocket
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

QMAKE_CXXFLAGS += -D_FORTIFY_SOURCE=0 -D_GNU_SOURCE -DULAPI -mhard-float -fno-fast-math -mieee-fp -fno-unsafe-math-optimizations -Wframe-larger-than=2560 -Os -std=c++0x
INCLUDEPATH += . /usr/include usr/include/linux /usr/include/machinekit /opt/Qt/5.3/gcc/include 
QMAKE_LIBDIR += /lib /opt/Qt/5.2.1/gcc_64/plugins/designer /usr/lib/machinekit
LIBS += -llinuxcncini -llinuxcnchal -lnml -llinuxcnc -lposemath


SOURCES += main.cpp tcpsocket.cpp

HEADERS += tcpsocket.h

This was using MachineKit and a 64 bit rt-preempt kernel build, but the principle is the same.

I don't use Eclipse, but there will be a way to specify what your compiler switches are, what the include paths are, what the lib paths are etc and use them to make a Makefile to build from within the
development environment.

regards

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

More
03 Nov 2014 09:58 #52708 by blightxdm1

Hi

You need to use comp to generate a .c file then build on the commandline, including the lib you want to use.

For instance this includes the modbus lib
gcc -Os -g -I. -I/usr/realtime/include -I. -I/usr/src/linuxcnc-dev-rtai/include -I/usr/include/modbus \
	    -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 -Os \
	     -o {BINARY_NAME} {PROGRAM}.c -Wl,-rpath,/lib -L/lib -L/usr/lib -L/usr/src/linuxcnc-dev-rtai/lib -llinuxcnchal -llinuxcnc -lmodbus

All the DEFINES etc are right for building rt modules, however the paths shown need changing for yours, because mine will not exist on your machine.

regards


Hi ArcEye,
i installed the system from live CD and linuxcnc-dev, as you said ,i try command like this:
gcc -Os -g -I. -I/usr/realtime-2.6.32-122-rtai/include -I. -I/usr/src/linuxcnc-headers-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 -Os \
	     -o mei mei.c -Wl,-rpath,/lib -L/lib -L/usr/lib -L/usr/src/linuxcnc-headers-2.6.32-122-rtai/lib -llinuxcnchal -llinuxcnc -lmeixmp
and i got error respone :
/usr/include/linuxcnc/rtapi_app.h:30:26: error: linux/module.h: No such file or directory

i'm sure the module.h in /usr/src/linux-headers-2.6.32-122-rtai/include/linux and this dir is already included in the command , did i miss something else ?

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

More
03 Nov 2014 17:11 - 04 Nov 2014 01:36 #52712 by ArcEye

i'm sure the module.h in /usr/src/linux-headers-2.6.32-122-rtai/include/linux and this dir is already included in the command , did i miss something else ?


The actual file is in the non rtai linux headers, that is just a symlink, so make sure you have both.

Try compiling the C file with comp in a terminal. It will fail due to functions that are not available because your lib is not linked in, but it should leave the gcc line which you can cut and paste, then add in your library and use that on the command line.

I don't use 10.04 and don't have a copy I can experiment on, just an old backup on my NAS.
There will be some path problem somewhere, which hopefully comp will resolve and you can copy what it does

regards
Last edit: 04 Nov 2014 01:36 by ArcEye.

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

More
04 Nov 2014 00:33 #52728 by andypugh

Hello Everyone,
I'm tring to compile a hal component from a c file , and which need to link a static lib file (.a ), and i find no any compile option for linking lib in the comp's help document


Are you compiling with comp/halcompile or with gcc?

I have occasionally compiled a .comp file with #includes, but to do that youi need to know that the .c file isn't in the same place as the .comp was when it is compiled, and you may need to use a relative path from the location of the temp file.

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

More
04 Nov 2014 09:37 #52750 by blightxdm1
i can't compile my c file with comp , coz the c file need additional static lib ,but comp don't support any compile option for additional lib . So i have to complie it with gcc as ArcEye suggested .

Unfortunately, i can't find the gcc command the comp used for compile .

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

More
04 Nov 2014 16:59 - 04 Nov 2014 17:02 #52755 by ArcEye

Unfortunately, i can't find the gcc command the comp used for compile .


Just open a terminal, (set the rip-environment , if using a RIP) and then run

comp --compile compname.comp

You will get an output like this, from which you can adapt a command line gcc call to includes your lib etc
# comp --compile threadkill.comp
	gcc -I. -pthread -DTHREAD_FLAVOR_ID=1 -DRTAPI -D_GNU_SOURCE -D_FORTIFY_SOURCE=0 -D__MODULE__ -mieee-fp \
        -I/usr/src/machinekit/include -fPIC -g -URTAPI -U__MODULE__ -DULAPI -Os  -o threadkill \
     	/ tmp/tmpyhBfYz/threadkill.c -Wl,-rpath,/usr/src/machinekit/lib -L/usr/src/machinekit/lib -llinuxcnchal

The /tmp bit is what Andy was talking about, comp parses the.comp file, creates a temporary .c file and then compiles that to produce the finished module, installs the module and deletes the temp file, if you run --install and do it all in one go

regards
Last edit: 04 Nov 2014 17:02 by ArcEye.

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

More
05 Nov 2014 13:51 #52796 by blightxdm1

Unfortunately, i can't find the gcc command the comp used for compile .


Just open a terminal, (set the rip-environment , if using a RIP) and then run

comp --compile compname.comp

You will get an output like this, from which you can adapt a command line gcc call to includes your lib etc
# comp --compile threadkill.comp
	gcc -I. -pthread -DTHREAD_FLAVOR_ID=1 -DRTAPI -D_GNU_SOURCE -D_FORTIFY_SOURCE=0 -D__MODULE__ -mieee-fp \
        -I/usr/src/machinekit/include -fPIC -g -URTAPI -U__MODULE__ -DULAPI -Os  -o threadkill \
     	/ tmp/tmpyhBfYz/threadkill.c -Wl,-rpath,/usr/src/machinekit/lib -L/usr/src/machinekit/lib -llinuxcnchal

The /tmp bit is what Andy was talking about, comp parses the.comp file, creates a temporary .c file and then compiles that to produce the finished module, installs the module and deletes the temp file, if you run --install and do it all in one go

regards


Yes , i did it as you said , but i got like this :
blight@blight-desktop:~/MEI$ comp --compile mei.c
make KBUILD_EXTRA_SYMBOLS=/home/blight/linuxcnc-add-hal-ethercat/rtlib/Module.symvers -C /usr/src/linux-headers-2.6.32-122-rtai SUBDIRS=`pwd` CC=gcc V=0 modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-122-rtai'
...

i think maybe it's the difference of linuxcnc version.
In fact i saw the makefile in the linuxcnc/src , but it's too complex for me (a fresher) . attached the makefile ,
Attachments:

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

Time to create page: 0.139 seconds
Powered by Kunena Forum