[macstl-dev] template with C linkage
David Chilton
David-Chilton at utc.edu
Sun Feb 6 02:28:56 WST 2005
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
And finally here's my updated main.cpp to give some test output:
#include <iostream>#ifdef USE_MACSTL
#include <macstl/valarray.h>
using stdext::valarray;
#else
#include <valarray>
using std::valarray;
#endif
class TestClass
{
public:
static size_t testStatic;
TestClass(size_t n):index(n) {}
TestClass():index(0){}
size_t getindex() { return index;}
valarray<size_t> testFunc(valarray<TestClass>& input){
valarray<size_t> d(input.size());
for(size_t i =0; i<input.size();i++)
d[i]=input[i].getindex(); // no
conversion to size_t, I assume you left out getindex
return d;
}
TestClass& operator=(size_t n)
{
index=n;
return *this;
}
private:
size_t index;
};
size_t TestClass::testStatic = size_t(0); // needs the ::
int main(int argc, char *argv[])
{
valarray<TestClass> test(10);
test=size_t(0);
TestClass testvar = size_t(0);
size_t i;
for(i = 0;i<test.size();i++)
std::cout<<test[i].getindex()<<std::endl;
std::cout<<std::endl;
valarray<size_t> test2 = testvar.testFunc(test);
for(i=0;i<test2.size();i++)
std::cout<<test2[i]<<std::endl;
return 0;
}
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
Anyway, like Paul, I'm not really expecting support, I just thought you
should know what's going on. I'll keep poking and see if I can find a
work around or fix.
In the part of my code that really needs optimization, I use floats and
ints, this was just a sample from part that uses size_t, although I
will probably start using unsigned ints instead so it can be optimized
by macstl.
David
On Feb 5, 2005, at 7:24 AM, Glen Low wrote:
> On 05/02/2005, at 11:27 AM, David Chilton wrote:
>
>> Glen,
>>
>> I successfully built and executed the benchmark target in the macstl
>> xcode project, and it looks great. Now I'm trying to test
>> incorporating macstl into the code for my honors thesis, which relies
>> heavily on valarray's read from FITS files, but I can't seem to get
>> gcc to build it. I continually get "template with C linkage" errors.
>> The same code compiles fine using the standard library valarray.
>> below is an example:
>>
>> #include <macstl/valarray.h>
>> using stdext::valarray;
>>
>> class TestClass
>> {
>> public:
>> static size_t testStatic;
>> TestClass(size_t n):index(n) {}
>> TestClass():index(0){}
>> size_t getindex() { return index;}
>> valarray<size_t> testFunc(valarray<TestClass>& input){
>> valarray<size_t> d(input.size());
>> for(size_t i =0; i<input.size();i++)
>> d[i]=input[i];
>> return d;
>> }
>> private:
>> size_t index;
>> }
>> size_t TestClass testStatic = size_t(0);
>>
>> compile with: gcc -c -o test.o test.cpp
>>
>> and tons of errors are given
>>
>> Any suggestions would be appreciated.
>>
>
> Thanks for evaluating macstl and joining the list, hope you find both
> activities useful!
>
> The program above has a few syntax errors, allow me to correct:
>
> #include <macstl/valarray.h>
> using stdext::valarray;
>
> class TestClass
> {
> public:
> static size_t testStatic;
> TestClass(size_t n):index(n) {}
> TestClass():index(0){}
> size_t getindex() { return index;}
> valarray<size_t> testFunc(valarray<TestClass>& input){
> valarray<size_t> d(input.size());
> for(size_t i =0; i<input.size();i++)
> d[i]=input[i].getindex(); // no
> conversion to size_t, I assume you left out getindex
> return d;
> }
> private:
> size_t index;
> };
> size_t TestClass::testStatic = size_t(0); // needs the ::
>
> On the macstl side there's one minor bug, valarray_vec.h:38 should read
>
> #include <macstl/vec.h>
>
> And the above, if put into main.cpp, should compile cleanly on Apple
> gcc 3.3.
>
> I'm not sure where the "template with C linkage" errors are coming
> from, perhaps you are compiling a .c file instead of a .cpp file? Or
> can you submit an example of the error?
>
> Note that valarray <size_t> is unlikely to be optimized, because
> size_t is usually a typedef for long, and only ints are Altivec
> optimized. On 32-bit gcc, long is 32 bits which is equivalent to an
> int, but on 64-bit gcc, long is 64 bits which is no longer the size of
> an int, so I didn't want to trigger the issue in macstl. (I may do
> some template metaprogramming to get 32-bit longs optimized and skip
> 64-bit longs, we'll see.)
>
> Cheers, Glen Low
>
>
> ---
> pixelglow software | simply brilliant stuff
> www.pixelglow.com
>
>
>
> _______________________________________________
> macstl-dev mailing list
> macstl-dev at pixelglow.com
> http://www.pixelglow.com/lists/listinfo/macstl-dev
>
More information about the macstl-dev
mailing list