This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: statically linking standard libraries
Hi Jerin,
> I'm having some issues trying to compile a standalone library.
>
> I first create my object files without linking:
> cross-g++ -c -o abc.o -fno-use-cxa-atexit abc.cc
> cross-g++ -c -o cppfunc.o -fno-use-cxa-atexit cppfunc.cc
> cross-g++ -c -o assemble.o -fno-use-cxa-atexit assemble.cc
>
> I'm unable to link them together. When I run:
> cross-ld -T test.ld assemble.o cppfunc.o abc.o -o standalone_program
>
> The linker throws errors:
> : undefined reference to `printf'
> : undefined reference to `free'
> : undefined reference to `strcpy'
> ..
>
> I'm trying to cross compile the code. I'm compiling on an x86 machine
> but the binary has to run on a different architecture. The "cross-g++"
> and "cross-ld" binaries compile code for the different architecture.
>
> I want to build a standalone binary. I tried passing a couple of
> options to the g++ and ld:
> -Bstatic
> -L/path to libstdc++.a
>
> but that did not help.
The errors result from the fact that some libraries are missing. At
least "-lcstd" is needed (this includes "printf"). Did you try
cross-g++ -static assemble.o cppfunc.o abc.o -o standalone_program
?
This would leave cross-g++ the decision, which libraries have to be
passed to "ld" exactly.
HTH,
Axel