help-gplusplus
[Top][All Lists]
Advanced

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

Const symbols suppressed


From: PlayDough
Subject: Const symbols suppressed
Date: Thu, 17 Jan 2008 11:48:03 -0800 (PST)
User-agent: G2/1.0

I'm not sure if this is a C++ standard, Gnu-ism, or just a bug in the
specific tools I am using.  I can't find anything with web searches
(perhaps bad terms) or anything on the GCC bugzilla, so I'll ask here.

I am using the Xilinx EDK 9.2, which is based upon 4.1.1 of gcc.
Here's the version info:

mb-g++ (GCC) 4.1.1 20060524 (Xilinx EDK 9.2.02 Build EDK_Jm_SP2.2 5
Nov 2007)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

So I'm trying to narrow down if this is an Xilinx issue, gcc issue, or
I'm just being C++ dense.  Here's the problem.

Say I have this basic file:

test.cpp:
const char test_str[] = "abcd";

And I compile with g++ (mb-g++ in my case).  So I do a "mb-g++ -c
test.cpp".  I'd expect test_str to be visible in the output.  So, I do
nm (mb-nm in my case), and get....nothing.

The test_str is not exported and is not visible.  In fact, dumping the
output (objdump -s) shows nothing.  And dumping the headers (objdump -
h) shows zero lengths for .text, .data, and .bss.  No output at all.

But change things up.  Change the filename to test.c and recompile
using gcc (mb-gcc).  Now test_str is exported, and is placed in
the .rodata section.  Exactly as expected.

The only fix I have found for this is to do one of two things.

test.cpp:
extern const char test_str[];
const char test_str[] = "abcd";

or

test.cpp:
extern const char test_str[] = "abcd";

I dislike the latter case, since we only use extern with declarations,
and leave off the extern for allocations.  That is, we'll put the
extern statement in a header, and leave off the extern in the source
file.

So, only with the extern keyword does the symbol get exported.

Is this a C++-ism, gcc (4.1.1)-ism, or a Xilinx-ism?

Thanks,
Pete


reply via email to

[Prev in Thread] Current Thread [Next in Thread]