Fatal error: iostream: No such file or directory in compiling C program using GCC

后端 未结 2 1442
清酒与你
清酒与你 2020-12-30 08:33

Why when I wan to compile the following multi thread merge sorting C program, I receive this error:

ap@sharifvm:~/forTHE04a$ gcc -g -Wall -o mer mer.c -lpth         


        
2条回答
  •  旧巷少年郎
    2020-12-30 09:13

    Seems like you posted a new question after you realized that you were dealing with a simpler problem related to size_t. I am glad that you did.

    Anyways, You have a .c source file, and most of the code looks as per C standards, except that #include and using namespace std;

    C equivalent for the built-in functions of C++ standard #include can be availed through #include

    1. Replace #include with #include , delete using namespace std;
    2. With #include taken off, you would need a C standard alternative for cout << endl;, which can be done by printf("\n"); or putchar('\n');
      Out of the two options, printf("\n"); works the faster as I observed.

      When used printf("\n"); in the code above in place of cout<

      $ time ./thread.exe
      1 2 3 4 5 6 7 8 9 10
      
      real    0m0.031s
      user    0m0.030s
      sys     0m0.030s
      

      When used putchar('\n'); in the code above in place of cout<

      $ time ./thread.exe
      1 2 3 4 5 6 7 8 9 10
      
      real    0m0.047s
      user    0m0.030s
      sys     0m0.030s
      

    Compiled with Cygwin gcc (GCC) 4.8.3 version. results averaged over 10 samples. (Took me 15 mins)

提交回复
热议问题