[uClibc] link C++ library with C main

Ran Katzur rkatzur at lsil.com
Wed Oct 22 14:14:12 UTC 2003


I have a problem linking C++ library with C routine.

Build a static library from a c++ file, hello.cc:

#include <stdio.h>
int hello_main()
{
   printf(" one \n")    ;
  return (0)  ;
}

and build the library using the script:

arm-linux-gcc -Wall  -static -c  -msoft-float hello.cc -o hello.o
arm-linux-ar  -rvu hello_main.a hello.o
ranlib   hello_main.a

Where arm-linux-gcc is  uClibc library
My main routine, in file main.cc is the following:

extern int hello_main()   ;


int main()
{
    hello_main()   ;
}

And  link and build the executable using:

arm-linux-gcc -Wall  -static -msoft-float main.cc hello_main.a -o hello
arm-linux-strip --strip-unneeded hello

Everything is fine.

Now I copy main.cc to main.c,  and change the main.cc to main.c in the build
script above, and I get the following message:


r - hello.o
main.c: In function `main':
main.c:10: warning: control reaches end of non-void function
/tmp/ccR3JPkK.o: In function `main':
/tmp/ccR3JPkK.o(.text+0xc): undefined reference to `hello_main'
/tmp/ccR3JPkK.o(.text+0xc): relocation truncated to fit: R_ARM_PC24
hello_main
collect2: ld returned 1 exit status
arm-linux-strip: hello: No such file or directory


I assume that this is a well-known problem, though not to me. What should I
do to make the c++ library work with C code?

Ran



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/uclibc/attachments/20031022/72efeda2/attachment-0001.htm 


More information about the uClibc mailing list