We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

AR# 24673

9.1i EDK - Error: "./ppc405_0/lib//libxil.a(init.o)(.sdata+0x0): undefined reference to 'main_shell'..." when compiling a C++ source code for a Xilkernel thread


Keyword: xilkernel, static, thread, undefined reference, C++

I have a thread that is statically defined in the Xilkernel. When I compile my C++ source code which contains this thread function, it results in the following error.

./ppc405_0/lib//libxil.a(init.o)(.sdata+0x0): undefined reference to `shell_main'
collect2: ld returned 1 exit status
make: *** [testcpp/executable.elf] Error 1

In this case, shell_main is the function defined in the static pthread table of my Xilkernel.


This is a limitation in Xilkernel C++ support. Due to name mangling in C++, the linker cannot correctly link the compiled object with the static thread function declared in xilkernel library.

To work around this issue, declare the static thread as a C function with the extern "C" attribute in the source code. An example is given below.

#ifdef __cplusplus
extern "C" {

void main_shell(void *noarg);

#ifdef __cplusplus

void main_shell (void *noarg)
/* function code here */
/* ... */

AR# 24673
Date 04/24/2007
Status Active
Type General Article