All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] shared library in xenomai ?
@ 2009-05-05  5:45 luan dinh
  2009-05-05  5:54 ` Thomas Lockhart
  0 siblings, 1 reply; 6+ messages in thread
From: luan dinh @ 2009-05-05  5:45 UTC (permalink / raw)
  To: xenomai@xenomai.org

[-- Attachment #1: Type: text/plain, Size: 666 bytes --]

Dear all.
i finished build a program and run it in xenomai. now i want to build it as shared library.
i use following commands  to create library file (.so ) from object file (.o)    
    gcc -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0   *.o
    mv libctest.so.1.0 /opt/lib
    ln -sf /opt/lib/libctest.so.1.0 /opt/lib/libctest.so
    ln -sf /opt/lib/libctest.so.1.0 /opt/lib/libctest.so.1
after that i write TEST program and use fuctions which my library
support. i can build and run TEST program but some functions in
my library doen't work ....
how to build and use my shared library in xenomai?
Thanks for any help.
Luan Dinh




      

[-- Attachment #2: Type: text/html, Size: 2078 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread
* [Xenomai-help] shared library in xenomai ?
@ 2009-05-05  6:36 luan dinh
  2009-05-05  7:55 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 6+ messages in thread
From: luan dinh @ 2009-05-05  6:36 UTC (permalink / raw)
  To: Thomas Lockhart; +Cc: xenomai@xenomai.org

[-- Attachment #1: Type: text/plain, Size: 1242 bytes --]

hi.
this is my problem :
i write a program which use raw socket and rteth0 NIC card to send data. when i build  as application it run well. then i build this program as shared libarary named  libctest.so support send() function to send data
the command to build shared lib similar to :
    gcc -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0   *.o
    mv libctest.so.1.0 /opt/lib
    ln -sf /opt/lib/libctest.so.1.0 /opt/lib/libctest.so
    ln -sf /opt/lib/libctest.so.1.0 /opt/lib/libctest.so.1 
i write a TEST program use the send() function which supported by  my library.
the command to build TEST program similar to :
gcc <xenomai options> prog.c -lctest -o TEST
when i execute by command ./TEST
the TEST program still run. the send() function seem to be right but no data sent to network adapter

Luan Dinh






Did you try running ldd on your built library to make sure that the
linking is finding all of the dependencies? Or please clarify what does
not seem to be working for you...



hth



                                   - Tom



-- 

Thomas Lockhart

Supervisor, Distributed and Real-time Group

Instrument Software and Science Data Systems

Caltech/JPL



 



      

[-- Attachment #2: Type: text/html, Size: 1788 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread
* [Xenomai-help] shared library in xenomai ?
@ 2009-05-06  6:09 luan dinh
  2009-05-06  6:27 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 6+ messages in thread
From: luan dinh @ 2009-05-06  6:09 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: xenomai-help


[-- Attachment #1.1: Type: text/plain, Size: 2933 bytes --]

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
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
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
test: demo_use.o
    $(LINKER) $(LDFLAGS) $^ -L. -lmylibra -o $@
clean:
    @( $(RM) *.o vgcore.* core core.* $(TARGET) )
# make rule
%.o : %.cpp
    $(CC) $(CFLAGS) -c $^ -o $@    

Please post an excerpt of your code exposing this issue (the library
part, and the program part).

You should note that compiling libraries or programs for Xenomai usually
involves compilation flags obtained with xeno-config.

You should also note that "send()" is a glibc function, so calling a
function with the same name is a bad idea.

-- 
                                                 Gilles.



      

[-- Attachment #1.2: Type: text/html, Size: 4990 bytes --]

[-- Attachment #2: libsock.c --]
[-- Type: text/plain, Size: 2112 bytes --]

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>

#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <arpa/inet.h>

#include <native/task.h>
#include <native/timer.h>

#include <errno.h>
#include <pthread.h>
#include <string.h>
#include <netinet/ether.h>

#include "libsock.h"

unsigned char buffer[1514];
unsigned char data[60] =
{0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x64,0x67,0x69,0x73,0x6E,0x88,0xA4,0x21,0x10,
		0x0C,0x00,0x00,0x00,0x01,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x30,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
 int sock;
RT_TASK demo_task;



void sockprintf()
{
	printf("this is Sockprintf...!\n");
}

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;
	}
	
    }	
		
}

void catch_signal(int sig)
{
	close(sock);
}

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);	
	pause();
	rt_task_delete(&demo_task);
	return 1;
}

[-- Attachment #3: demo_use.c --]
[-- Type: text/plain, Size: 490 bytes --]

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>

#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <arpa/inet.h>

#include <native/task.h>
#include <native/timer.h>

#include <errno.h>
#include <pthread.h>
#include <string.h>
#include <netinet/ether.h>

#include "testdom.hpp"
#include "libsock.h"

int main( int argc, char * argv[] )
{
	my_send();
	pause();	
	return 1;	
}

[-- Attachment #4: Makefile --]
[-- Type: application/octet-stream, Size: 1165 bytes --]

CC = gcc
AR = ar cru
#CFLAGS = -Wall -D_REENTRANT -D_GNU_SOURCE -g -fPIC
SOFLAGS = -shared -Wl
#LDFLAGS = -lstdc++

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


LINKER = $(CC)
LINT = lint -c
RM = /bin/rm -f

ifeq ($(origin version), undefined)
	version = 0.4
endif

#--------------------------------------------------------------------

LIBOBJS =  libsock.o 


TARGET =  libmylibra.so \
		test 

#TARGET =  test
#--------------------------------------------------------------------

all: $(TARGET)

#libmylibra.so: $(LIBOBJS)
#	$(LINKER) $(SOFLAGS) $^ -o $@ -lc

libmylibra.so: $(LIBOBJS)
	$(LINKER) $(SOFLAGS) -o $@ $^ -lc


#$(TARGET): $(LIBOBJS)
#	$(LINKER) $(LDFLAGS) $(LIBOBJS) -o $(TARGET)
test: demo_use.o
	$(LINKER) $(LDFLAGS) $^ -L. -lmylibra -o $@
clean:
	@( $(RM) *.o vgcore.* core core.* $(TARGET) )

#--------------------------------------------------------------------

# make rule
%.o : %.cpp
	$(CC) $(CFLAGS) -c $^ -o $@	

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-05-06  6:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-05  5:45 [Xenomai-help] shared library in xenomai ? luan dinh
2009-05-05  5:54 ` Thomas Lockhart
  -- 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-06  6:09 luan dinh
2009-05-06  6:27 ` Gilles Chanteperdrix

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.