0

Below is my code.

#include <bits/stdc++.h>
using namespace std;
int main() {
   //#include <string.h> from <bits/stdc++.h>
   char source[] = "new string";
   cout<<"\nGiven String is "<<strlen(source) << endl;
}

I can compile this code successfully using below command

 g++ -o file.out file.cpp

But when I am trying to compile with debug symbols (-g so I can use gdb debugger) it does not compile successfully.

 g++ -g -o file.out file.cpp 

Processes for a long time and exits with error as below:

 g++: fatal error: Killed signal terminated program cc1plus. compilation terminated.

I can compile other code without any problems. But if I use include<stdc++.h> and compile with -g option I am getting error.. Please how can I solve this?

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
Ram
  • 1
  • 7
    related [Why should I not `#include `?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) . Just include the right headers and the issue is gone – 463035818_is_not_an_ai May 23 '22 at 12:02
  • Works for me - live (with corrected headers etc) - https://godbolt.org/z/o84x3z3Tj – Richard Critten May 23 '22 at 12:06
  • works for me even when I do include `bits/stdc++.h`: https://godbolt.org/z/Gao6xoKPv – 463035818_is_not_an_ai May 23 '22 at 12:08
  • How to solve this problem: wherever you learned to do `#include `, never go there again. Instead, learn C++ from a [good C++ book](https://stackoverflow.com/a/388282/4641116). – Eljay May 23 '22 at 12:18
  • I need to do this for a project where others use this stdc++ file when they are doing the coding. I saw the other posts before and understand it has problems with long compile time etc – Ram May 23 '22 at 12:24
  • @RichardCritten I tried with online c++ compiler and it's working for me also there. But I cannot compile successfully on local machine.. Is there some difference in gcc version something that I am missing? – Ram May 23 '22 at 12:29
  • 1
    @Ram To tell if there is something wrong with your compiler version, you should include it in the question. It might be a [memory problem](https://stackoverflow.com/a/47374605/17862371) caused by all the stuff you include from that header. Debugging symbols take much space and if you include a huge header it could be too much for your local machine. How much memory does your machine have? – Jakob Stark May 23 '22 at 13:48
  • Does this answer your question? [Why should I not #include ?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) – Zephyr May 23 '22 at 19:58

0 Answers0