PlayDough <[EMAIL PROTECTED]> writes: > 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.
Good. The const gives test_str internal linkage. g++ has to make sure that it can't be referenced from different translation units. > 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"; The extern declaration causes test_str to have external linkage despite the const. > test.cpp: > extern const char test_str[] = "abcd"; Ditto. > 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? This behavior is specified in the ISO C++ Standard. _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus