Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

error when compiling sample code with g++

lancekimbrough
Beginner
385 Views

I am beginning to work with the Threading Building Blocks and I'm having an issue compiling the sample program (sub_string_finder.cpp) with g++. However, when I use intel's c++ compiler, it compiles just fine.

To compile with g++, I execute:

g++ sub_string_finder.cpp -ltbb

and I get an error:
sub_string_finder.cpp:60: error: first argument of int main(size_t, char**) should be int

However, when I execute: icpc sub_string_finder.cpp -ltbb

it compiles just fine (and the compiled program works). I've never had any issues with GNU gcc (g++) before...so this is unexpected. Does anyone know what's going on here?

Thanks!
Lance

0 Kudos
3 Replies
lancekimbrough
Beginner
385 Views

Well, I did some more searching around and seem to have found the problem...

from: http://gcc.gnu.org/gcc-4.3/porting_to.html

Stricter requirements for function main signature

The two-argument signature for main has int as the first argument. GCC 4.3 rigorously enforces this.

int main(unsigned int m, char** c) 
{ return 0; }

Gives:

error: first argument of 'int main(unsigned int, char**)' should be 'int'

Fixing this is straightforward: change the first argument to be of type int, not unsigned int. As transformed:

int main(int m, char** c) 
{ return 0; }


So, I just changed line 60 in sub_string_finder.cpp to:
int main(int argc, char *argv[]) {

and it now compiles just fine with g++. Problem solved.
0 Kudos
Wooyoung_K_Intel
Employee
385 Views
Quoting - lance.kimbrough

Well, I did some more searching around and seem to have found the problem...

from: http://gcc.gnu.org/gcc-4.3/porting_to.html

Stricter requirements for function main signature

The two-argument signature for main has int as the first argument. GCC 4.3 rigorously enforces this.

int main(unsigned int m, char** c) 
{ return 0; }

Gives:

error: first argument of 'int main(unsigned int, char**)' should be 'int'

Fixing this is straightforward: change the first argument to be of type int, not unsigned int. As transformed:

int main(int m, char** c) 
{ return 0; }


So, I just changed line 60 in sub_string_finder.cpp to:
int main(int argc, char *argv[]) {

and it now compiles just fine with g++. Problem solved.

Thanks for reporting an issue. I checked 'sub_string_finder.cpp' and the version I saw has

'int main( int argc, char *argv[])' on line 60.

Could you tell us what TBB release you are using?

best regards

0 Kudos
lancekimbrough
Beginner
385 Views

Thanks for reporting an issue. I checked 'sub_string_finder.cpp' and the version I saw has

'int main( int argc, char *argv[])' on line 60.

Could you tell us what TBB release you are using?

best regards

Well, I somehow ended up with TBB version 2.0 (tbb20_020_lin.tgz). Not sure how, as I just downloaded it a week ago. I just downloaded the most recent version on the site (version 2.1), and sure enough, line 68 now uses "int argc". Atleast it taught me something new about gcc. :) Thanks for the help.

Best Regards,

Lance

0 Kudos
Reply