[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [microblaze-uclinux] c++ non-constant initializers
I tried your source code, after using petalinux-new-app to create the
application, I changed the filename to .cpp and did the same in the
makefile rule:
%.o: %.cpp
$(CC) -c $(CFLAGS) -o $@ $<
It worked fine.
Here's the source:
#include <stdio.h>
const unsigned char seq[] = { 0x54, 0x45, 0x53, 0x54 }; // TEST
const unsigned char seq2[] = { seq[0], seq[1], seq[2], seq[3] };
int main() {
printf("%x %x %x %x\n", seq[0], seq[1], seq[2], seq[3]);
printf("%x %x %x %x\n", seq2[0], seq2[1], seq2[2], seq2[3]);
return 0;
}
Here's the makefile:
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 = mltcpp
# Add any other object files to this list below
APP_OBJS = mltcpp.o
all: $(APP)
$(APP): $(APP_OBJS)
$(CC) $(LDFLAGS) -o $@ $(APP_OBJS) $(LDLIBS)
clean:
-rm -f $(APP) *.elf *.gdb *.o
romfs:
$(ROMFSINST) $(APP) /bin/$(APP)
%.o: %.cpp
$(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
Here's the output when run on the microblaze:
# ./mltcpp
54 45 53 54
54 45 53 54
#
Cheers.
-----Original Message-----
From: owner-microblaze-uclinux@xxxxxxxxxxxxxx
[mailto:owner-microblaze-uclinux@xxxxxxxxxxxxxx] On Behalf Of Nicolas
Schier
Sent: 11 September 2008 07:17
To: microblaze-uclinux@xxxxxxxxxxxxxx
Subject: Re: [microblaze-uclinux] c++ non-constant initializers
Hei!
Are you sure that you are compiling C++-Code? The sample code provided
seems to confirm to usual C; thus compiling it with gcc on a x86 results
in:
~# gcc test.c
test.c:4: error: initializer element is not constant
test.c:4: error: (near initialization for 'seq2[0]')
test.c:4: error: initializer element is not constant
test.c:4: error: (near initialization for 'seq2[1]')
test.c:4: error: initializer element is not constant
test.c:4: error: (near initialization for 'seq2[2]')
test.c:4: error: initializer element is not constant
test.c:4: error: (near initialization for 'seq2[3]')
Regards,
Nicolas
On Wednesday, 09/10/08 at 17:37 (+0200), Torsten Schmutzler wrote:
> From: Torsten Schmutzler <s6757418@xxxxxxxxxxxxxxxxx>
> To: microblaze-uclinux@xxxxxxxxxxxxxx
> Date: Wed, 10 Sep 2008 17:37:28 +0200
> Subject: [microblaze-uclinux] c++ non-constant initializers
> User-Agent: Thunderbird 2.0.0.16 (X11/20080724)
>
> Hi,
>
> I'm trying to port a c++ Framework to microblaze, but there are
problems
> with the generated binaries.
>
> Here is some code to demonstrate the problem:
>
> #include <stdio.h>
>
> const unsigned char seq[] = { 0x54, 0x45, 0x53, 0x54 }; // TEST
> const unsigned char seq2[] = { seq[0], seq[1], seq[2], seq[3] };
>
> int main() {
> printf("%x %x %x %x\n", seq[0], seq[1], seq[2], seq[3]);
> printf("%x %x %x %x\n", seq2[0], seq2[1], seq2[2], seq2[3]);
> return 0;
> }
>
> Compiling and running on a pc gives:
> 54 45 53 54
> 54 45 53 54
>
> builing for mb results in:
> 54 45 53 54
> 0 0 0 0
>
> So it seems the initializers are not run. The code above is legal C++,
so:
> - can somebody reproduce this behavior?
> - Are there compiler switches to make the code work?
> - Or is this just a bug in microblaze-uclinux-g++?
>
> Thanks
> Torsten
>
--
gpg public key: ID 0xACBC3B35, jabber: nicolas@xxxxxxxxx
-- frykten for herren er opphav til kunnskap --
**********************************************************************
This communication is confidential and intended solely for the
addressee(s). Any unauthorized review, use, disclosure or distribution
is prohibited. If you believe this message has been sent to you in
error, please notify the sender by replying to this transmission and
delete the message without disclosing it. Thank you.
E-mail including attachments is susceptible to data corruption,
interception, unauthorized amendment, tampering and viruses, and we
only send and receive e-mails on the basis that we are not liable for
any such corruption, interception, amendment, tampering or viruses or
any consequences thereof.
This email, its content and any attachments is PRIVATE AND
CONFIDENTIAL to TANDBERG Television, Part of the Ericsson Group.
www.tandbergtv.com
**********************************************************************
___________________________
microblaze-uclinux mailing list
microblaze-uclinux@xxxxxxxxxxxxxx
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive : http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/