[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [microblaze-uclinux] C++ link issues



Well, this doesn't work on my system.  I'm using petalinux-v0.40-rc3.tar.gz as obtained from svn.
I removed libstdc++.a from $(ROOTDIR)/lib as recommended, then generated a new ulocate project, using petalinux-new-app.
I copied my ulocate.cpp file to the project directory, then made the changes recommended below to my makefile (which will be attached here as ulocate.mak, though it was just Makefile when I ran it).  The result I get, as previously, is:

#********************************************
root@damien:/home/petalinux-v0.40-rc3/software/user-apps/ulocate# make
mb-linux-g++  -Os -g -fomit-frame-pointer -pipe -fno-common -fno-builtin -Wall  -mno-xl-soft-div -mxl-barrel-shift -mcpu=v7.20.a -mxl-multiply-high -mno-xl-soft-mul -mhard-float  -DEMBED -I/home/petalinux-v0.40-rc3/software/petalinux-dist -I/home/petalinux-v0.40-rc3/software/petalinux-dist/include -I/home/petalinux-v0.40-rc3/software/petalinux-dist/include -Dlinux -D__linux__ -Dunix -DLINUX    -c -o ulocate.o ulocate.cpp
mb-linux-g++   -o ulocate ulocate.o  -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
/home/petalinux-v0.40-rc3/tools/linux-i386/microblaze-glibc-root/bin/../lib/gcc/microblaze-linux-elf/4.1.1/../../../../microblaze-linux-elf/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
make: *** [ulocate] Error 1
#********************************************

BTW, Notice that CXX_LDFLAGS appears to not exist on my platform; I suspect this is the fundamental problem that I have, do you agree??  So, where is that macro supposed to come from?

Dan Miller

BTW, I tried manually creating CXX_LDFLAGS in my makefile, and pointing it to
/home/petalinux-v0.40-rc3/tools/linux-i386/microblaze-uclinux-tools/microblaze-uclinux/lib/

However, *this* fails because of the libstdc++.la file in that directory, which references several *very* non-existent directories.




John Williams wrote:
Hi again,

Here's the only two tweaks required on a petalinux-new-app Makefile template to build a C++ binary:

 $(APP): $(APP_OBJS)
-       $(CC) $(LDFLAGS) -o $@ $(APP_OBJS) $(LDLIBS)
+       $(CXX) $(CXX_LDFLAGS) -o $@ $(APP_OBJS) $(LDLIBS) $(CXXLIBS)
 
 clean:
        -rm -f $(APP) *.elf *.gdb *.o
@@ -41,6 +41,8 @@
 %.o: %.c
        $(CC) -c $(CFLAGS) -o $@ $<
 
+%.o: %.cxx
+       $(CXX) -c $(CXXFLAGS) -o $@ $<

Basically, indicate to use the C++ compiler for the final link, using CXX_LDFLAGS and CXXLIBS, and provide a rule so Make knows how to produce .o files from .cxx sources.

This build tested in most recent PetaLinux.  No need to copy libstdc++.a into your build dir, as far as I can see.

Cheers,

John


On Thu, Jun 11, 2009 at 8:37 AM, John Williams <john.williams@xxxxxxxxxxxxx> wrote:
Hi Dan,

On Thu, Jun 11, 2009 at 8:06 AM, Dan Miller <dan@xxxxxxxxxx> wrote:
What I did, to get C++ files to link successfully, is I copied
/home/petalinux-v0.40-rc3/tools/linux-i386/microblaze-uclinux-tools/microblaze-uclinux/lib//libstdc++.a
to
$(ROOTDIR)/lib

and then everything just built!!  The trick was, to copy *only* libstdc++.a, NOT libstdc++.la
(otherwise I get a bunch of errors about non-existent paths that are in the .la file).

I'm surprised it was necessary to copy libstdc++ into place, I'll try to get a look at this today and figure out what's going on.

Now, the one thing I *don't* know is if that particular copy of the library is actually valid or not, since it was buried down in the middle of nowhere.  I confirmed that the executable does not run on the host platform, which confirms that it didn't use the host compiler/linker.  Beyond that, I'll have to wait until our Microblaze board is up and running to test further.

What's cool is that I next imported a 13-file, 5000-line application, made the same couple of changes in the petalinux-generated Makefile, and the whole thing just compiled and linked with no arguments!! 

Can I quote you on that? :)  That's why you use embedded Linux!

John


--
John Williams, PhD, B.Eng, B.IT
PetaLogix - Linux Solutions for a Reconfigurable World
w: www.petalogix.com  p: +61-7-30090663  f: +61-7-30090663



--
John Williams, PhD, B.Eng, B.IT
PetaLogix - Linux Solutions for a Reconfigurable World
w: www.petalogix.com  p: +61-7-30090663  f: +61-7-30090663

ifndef PETALINUX
$(error You must source the petalinux/settings.sh script before working with PetaLinux)
endif

# Point to default PetaLinux root directory
ifndef ROOTDIR
ROOTDIR=$(PETALINUX)/software/petalinux-dist
endif

PATH:=$(PATH):$(ROOTDIR)/tools

UCLINUX_BUILD_USER = 1
-include $(ROOTDIR)/.config
-include $(ROOTDIR)/$(CONFIG_LINUXDIR)/.config
LIBCDIR = $(CONFIG_LIBCDIR)
-include $(ROOTDIR)/config.arch
ROMFSDIR=$(ROOTDIR)/romfs
ROMFSINST=$(ROOTDIR)/tools/romfs-inst.sh

APP = ulocate

# Add any other object files to this list below
APP_OBJS = ulocate.o

all: $(APP)

#	$(CC) $(LDFLAGS) -o $@ $(APP_OBJS) $(LDLIBS)
$(APP): $(APP_OBJS)
	$(CXX) $(CXX_LDFLAGS) -o $@ $(APP_OBJS) $(LDLIBS) $(CXXLIBS)

clean:
	-rm -f $(APP) *.elf *.gdb *.o

.PHONY: romfs image

romfs:
	$(ROMFSINST) $(APP) /bin/$(APP)

image: romfs
	make -C ${PETALINUX}/software/petalinux-dist image

%.o: %.cxx
	$(CXX) -c $(CXXFLAGS) -o $@ $<

%.o: %.c
	$(CC) -c $(CFLAGS) -o $@ $<


# Targets for the required .config files - if they don't exist, the tree isn't
# configured.  Tell the user this, how to fix it, and exit.
${ROOTDIR}/config.arch ${ROOTDIR}/.config:
	@echo "Error: You must configure the PetaLinux tree before compiling your application"
	@echo ""
	@echo "Change directory to ../../petalinux-dist and 'make menuconfig' or 'make xconfig'"
	@echo ""
	@echo "Once the tree is configured, return to this directory, and re-run make."
	@echo ""
	@exit -1