tags:

views:

35

answers:

1

Hi! I'm working on a ia64-machine using ICC 11.1. The following program compiles nicely:

#include <pthread.h>
#include <iostream>
using namespace std;
int main()
{
    cout << PTHREAD_STACK_MIN << '\n';
    return 0;
}

When I compile it with icc test.cpp -o test

BUT when I change the contents of the file to to:

#include <pthread.h>
#include <stdio.h>
int main()
{
    printf("%d\n", PTHREAD_STACK_MIN);
    return 0;
}

I suddenly get:

icc -c test.cpp -o test.o test.cpp(6): error: identifier "PTHREAD_STACK_MIN" is undefined printf("%d\n", PTHREAD_STACK_MIN); ^

compilation aborted for test.cpp (code 2)

Can anyone explain to me why? Or more importantly: how I can work around this issue so that the second code example will also compile?

A: 

Well, that's easy: you forgot to include <limits.h> where the PTHREAD_STACK_MIN is supposed to be declared (as per POSIXv6/SUSv3).

And from the error one can conclude that <iostream> internally also includes the <limits.h> why in C++ mode the error doesn't happen.

Dummy00001
Thanks a lot, that was helpful. :)Unfortunately in the code that this minimal example was extrapolated from, <limits.h> is included but I still get an error about PTHREAD_STACK_MIN being undefined. Oh well, I guess I'll have to dig deeper, but thanks anyways! :)
Tom
@Tom: It would have helped if you specified your OS. HP-UX? Linux? The headers are OS dependent, not compiler. Try to run the file through preprocessor with max verbosity (in gcc: gcc -E -dD test.cpp > test.i) and see what's going wrong. Also try to give `-mpthreads` (or its ICC's analog) command line option to your compiler (shouldn't matter in the case, but what if).
Dummy00001
Oh, sorry... the OS is SUSE Linux Enterprise Server 10 (ia64). Well, thanks to Dummy00001's answer, both minimal examples run now. However I am having problems compiling a library I need, where the examples were just extrapolated from. But I guess at this point I'll just contact the devs in charge of that library. Cheers :)
Tom