Skip to contentSkip to conversation

How to use wrap-link.sh to build static app.

DISCUSSION Jan Kiszka 1 participant 2 messages May 19, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Jan Kiszka

author
#1 lore raw
Quoted 8 lines · Haiyang He

Dear Xenomai Project Team,

I try to understand how wrap-link.sh works.

I use wrap-link.sh to build static app(a simaple hello.c), with following makefile.

But ./hello always got aborted.

Thanks for reporting - I suppose no one was using static linking in a long while...

Please try the patch I just posted.

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
author
#2 lore raw
In reply to a message not in the archive
Quoted 118 lines · Haiyang He

Dear Xenomai Project Team,

I try to understand how wrap-link.sh works.

I use wrap-link.sh to build static app(a simaple hello.c), with following makefile.

But ./hello always got aborted.

makefile:

XENO_DESTDIR=/root/xenomai/xenomai-v3.2.4-install

CC = aarch64-linux-gnu-g++
CCLD = $(XENO_DESTDIR)/usr/xenomai/bin/wrap-link.sh $(CC)

XENO_CONFIG =$(XENO_DESTDIR)/usr/xenomai/bin/xeno-config

XENO_POSIX_CFLAGS =$(shell DESTDIR=$(XENO_DESTDIR) $(XENO_CONFIG) --skin=posix --cflags)

XENO_POSIX_LDFLAGS =$(shell DESTDIR=$(XENO_DESTDIR) $(XENO_CONFIG) --skin=posix --ldflags)

PROJPATH = .

EXECUTABLE := hello

src = $(wildcard ./*.c)

obj = $(patsubst %.c, %.o, $(src))

all: $(EXECUTABLE)

$(EXECUTABLE): $(obj)

	$(CCLD) -g -static -o $@ $^ $(XENO_POSIX_LDFLAGS)

%.o:%.c

	$(CC) -g -o $@ -c $< $(XENO_POSIX_CFLAGS)

.PHONY: clean
clean:

	rm -f $(EXECUTABLE) $(obj)

hello.c:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sched.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>

#ifndef __STD
#define __STD(x) x
#endif

pthread_t svtid, cltid;

static void fail(const char *reason)

{
	perror(reason);
	exit(EXIT_FAILURE);
}

static void *client(void *arg)

{
    int print_loop=0;

    while(1) {
        printf("Slave Hello World %d!\n", print_loop);
        print_loop++;
        usleep(1000000);
    }
}

static void *server(void *arg)

{
    int print_loop=0;

    while(1) {
        printf("Main Hello World %d!\n", print_loop);
        print_loop++;
        usleep(1000000);
    }
}

int main()

{
	struct sched_param svparam = {.sched_priority = 71 };
	struct sched_param clparam = {.sched_priority = 70 };
	pthread_attr_t svattr, clattr;
	sigset_t set;
	int sig;

	sigemptyset(&set);
	sigaddset(&set, SIGINT);
	sigaddset(&set, SIGTERM);
	sigaddset(&set, SIGHUP);
	pthread_sigmask(SIG_BLOCK, &set, NULL);

	pthread_attr_init(&svattr);
	pthread_attr_setdetachstate(&svattr, PTHREAD_CREATE_JOINABLE);
	pthread_attr_setinheritsched(&svattr, PTHREAD_EXPLICIT_SCHED);
	pthread_attr_setschedpolicy(&svattr, SCHED_FIFO);
	pthread_attr_setschedparam(&svattr, &svparam);

	errno = pthread_create(&svtid, &svattr, &server, NULL);
	if (errno)
		fail("pthread_create");

	pthread_attr_init(&clattr);
	pthread_attr_setdetachstate(&clattr, PTHREAD_CREATE_JOINABLE);
	pthread_attr_setinheritsched(&clattr, PTHREAD_EXPLICIT_SCHED);
	pthread_attr_setschedpolicy(&clattr, SCHED_FIFO);
	pthread_attr_setschedparam(&clattr, &clparam);

	errno = pthread_create(&cltid, &clattr, &client, NULL);
	if (errno)
Quoted 10 lines
		fail("pthread_create");

	__STD(sigwait(&set, &sig));
	pthread_cancel(svtid);
	pthread_cancel(cltid);
	pthread_join(svtid, NULL);
	pthread_join(cltid, NULL);
}

Not sure why my reply made it, your original posting not - please always use the "new" list address.

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center