[macstl-dev] template with C linkage
Glen Low
glen.low at pixelglow.com
Sun Feb 6 08:57:47 WST 2005
David:
On 06/02/2005, at 2:28 AM, David Chilton wrote:
> Glen,
> After much tinkering, it seems the problem comes in with the
> -Wp,-header-mapfile,... option that is passed by Xcode. I couldn't
> get benchmark.cpp to compile from the command line so i started
> putting in options from the Xcode build results window until it built.
> Finally, and tried to compile the main.cpp given below. It works
> with the std valarray straight away, but gives errors when i try to
> use macstl/valarry. But It works when I add
> -Wp,-header-mapfile,[PATH_TO_BENCHMARK_BUILD]/benchmark.hmap to the
> gcc call, without that it gives loads of errors. I can't seem to find
> any documentation on the hmap file or how to make one work, or why it
> deosn't work without it.
>
> Here's the command line that does build properly:
> /usr/bin/gcc-3.3 /Users/chiltie/Desktop/main.cpp -o
> /Users/chiltie/Desktop/main -lstdc++ -DUSE_MACSTL
> -Wp,-header-mapfile,/Users/chiltie/Desktop/macstl/mac/build/
> macstl.build/benchmark.build/benchmark.hmap
>
> here's the one that doesn't:
> /usr/bin/gcc-3.3 /Users/chiltie/Desktop/main.cpp -o
> /Users/chiltie/Desktop/main -lstdc++ -DUSE_MACSTL
It's rather perplexing. I use almost the same command line as yours:
/usr/bin/gcc-3.3 main.cpp -lstdc++ -DUSE_MACSTL -I../macstl -o main.o
where the -I is the path to the base of the outermost macstl directory,
and I get no errors.
Googling for "template with C linkage" turns up about 700+ pages, some
detailing issues even with system headers on certain combinations of
operating systems and machines.
So my trusty C++ detective says :-), it's because a (possibly system)
header has an unterminated
extern "C" {
which then infects all subsequent headers that were #included after.
Now if
>
> And Here's a few lines of the error output (it gives over a thousand
> total errors):
> In file included from /usr/include/macstl/valarray.h:86,
> from /Users/chiltie/Desktop/main.cpp:3:
> /usr/include/macstl/impl/valarray_vec.h:45: error: template with C
> linkage
> /usr/include/macstl/impl/valarray_vec.h:150: error: template with C
> linkage
> /usr/include/macstl/impl/valarray_vec.h:254: error: template with C
> linkage
>
is the first lot of errors you get back from the compile, then all the
#includes before line 86 were OK and the culprit should be #included
from somewhere in vec.h header.
I suspect that one of your system headers inadvertently had its last
line or so chopped off, thus causing an unterminated extern "C"
directive, or perhaps it was some interaction with a macro definition.
The #include <valarray> might not have gone through the exact same
route and thus not triggered it. To narrow it down, try putting a
simple template definition at various points in the my source along the
#include path to see if you can trigger the error sooner:
e.g.
template <typename T> struct make_my_day
{
};
Some configuration questions that might be useful:
1. What's the exact version of gcc? (Try gcc --version)
2. Have you made any changes at all to the /usr/include/gcc headers?
3. Did you install macstl at /usr/include/ or somewhere else? If the
former, try putting it somewhere else and using an -I option like I did
to see if the error goes away.
Anyone else try out David's code and got errors?
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
More information about the macstl-dev
mailing list