From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: luan dinh <dinhluanbmt@domain.hid>
Cc: xenomai-help <xenomai@xenomai.org>
Subject: Re: [Xenomai-help] shared library in xenomai ?
Date: Wed, 06 May 2009 08:27:42 +0200 [thread overview]
Message-ID: <4A012DDE.7030601@domain.hid> (raw)
In-Reply-To: <431263.25323.qm@domain.hid>
luan dinh wrote:
> hi.
> My program included :
> + libsock.c
> + demo_use.c
> + Makefile
> i build libsock.c as shared library named libmylibra.so ( support my_send() function )
> demo_use.c use my_send() and built with -lmylibra option
> Thanks for any advise.
> Luan Dinh
> PS :i also attach the source code of these files
> ######### libsock. c###
> void demo(void *agr)
> {
> int len,i;
> rt_task_set_periodic(NULL, TM_NOW, 100000000);
> while (1) {
> rt_task_wait_period(NULL);
> len = send(sock, data, sizeof(data), 0);
> if (len < 0)
> {
> printf("Sent Failed...!\n");
> break;
> }
> }
> }
> /*my_send*/
> int my_send()
> {
> struct sched_param param;// = { .sched_priority = 1 };
> struct sockaddr_ll addr;
> struct ifreq ifr;
> mlockall(MCL_CURRENT|MCL_FUTURE);
> if ((sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) {
> perror("socket cannot be created");
> return 1;
> }
> strncpy(ifr.ifr_name, "rteth0", IFNAMSIZ);
> if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0) {
> perror("cannot get interface index");
> close(sock);
> return 1;
> }
> addr.sll_family = AF_PACKET;
> addr.sll_protocol = htons(ETH_P_ALL);
> addr.sll_pkttype = PACKET_OTHERHOST;
> addr.sll_ifindex = ifr.ifr_ifindex;
>
> if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
> perror("cannot bind");
> close(sock);
> return 1;
> }
>
> rt_task_create(&demo_task, "mytask", 0, 99, 0);
> rt_task_start(&demo_task, &demo, NULL);
> return 1;
> }
>
> ### demo_use.c ###
> int main( int argc, char * argv[] )
> {
> my_send();
> pause();
> return 1;
> }
>
> ## Makefile ###
> CC = gcc
> AR = ar cru
> SOFLAGS = -shared -Wl
The -Wl means that you are going to pass a flag to the linker. So, this
declaration of SOFLAGS is a bit like a sentence which you started and
did not finish.
> CFLAGS = -I/usr/xenomai/include -I/usr/xenomai/include/posix -D_GNU_SOURCE -D_REENTRANT -D__XENO__ -Wall -g -fPIC -rdynamic -pipe -O2 -fstrict-aliasing
> LDFLAGS = -Wl,@/usr/xenomai/lib/posix.wrappers -L/usr/xenomai/lib -lpthread_rt -lpthread -lnative -lrt -lstdc++ -ldl
Bad. You should use xeno-config to obtain the CFLAGS and the LDFLAGS.
> LINKER = $(CC)
> LINT = lint -c
> RM = /bin/rm -f
> LIBOBJS = libsock.o
> TARGET = libmylibra.so \
> test
> all: $(TARGET)
> libmylibra.so: $(LIBOBJS)
> $(LINKER) $(SOFLAGS) -o $@ $^ -lc
As I told you in my previous mail, you should use LDFLAGS when linking
libmylibra.so.
Also, if you are working on an embedded system, it is a better idea to
use either the native skin or the posix skin, not use both. This way,
you can compile only one of the two skins in the kernel, and you put
only one of the two libraries on your system.
--
Gilles.
next prev parent reply other threads:[~2009-05-06 6:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-06 6:09 [Xenomai-help] shared library in xenomai ? luan dinh
2009-05-06 6:27 ` Gilles Chanteperdrix [this message]
-- strict thread matches above, loose matches on Subject: below --
2009-05-05 6:36 luan dinh
2009-05-05 7:55 ` Gilles Chanteperdrix
2009-05-05 5:45 luan dinh
2009-05-05 5:54 ` Thomas Lockhart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A012DDE.7030601@domain.hid \
--to=gilles.chanteperdrix@xenomai.org \
--cc=dinhluanbmt@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.