0

I'm getting this weird linker error using gcc, thought the code works fine when I use Visual Studio..

/tmp/ccfcdCxg.o: In function `global constructors keyed to main':
codechef_permut2.cpp:(.text+0xa): undefined reference to `std::ios_base::Init::Init()'
codechef_permut2.cpp:(.text+0x19): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccfcdCxg.o: In function `ambig(unsigned long)':
codechef_permut2.cpp:(.text+0x47): undefined reference to `operator new[](unsigned long)'
codechef_permut2.cpp:(.text+0x52): undefined reference to `operator new[](unsigned long)'
/tmp/ccfcdCxg.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

I dint post any code, because I think its not required but if someone feels I'll post it.

5
  • 1
    In that case, I won't post the answer, because I think it's not required
    – jalf
    Apr 13, 2012 at 11:22
  • 2
    Are you linking with gcc or g++? Apr 13, 2012 at 11:23
  • 1
    Could you please show how the compiler is invoked? There could be linking errors when you compile C++ code with gcc instead of g++. Apr 13, 2012 at 11:23
  • Why? The code is unnecessary. The only one thing I think that is needed are maybe parameters for gcc.
    – nothrow
    Apr 13, 2012 at 11:24
  • @DavidSchwartz- Yes, using gcc...
    – questions
    Apr 13, 2012 at 11:28

1 Answer 1

8

My guess is that you're using gcc rather than g++ to link your program. gcc won't include the C++ library unless you tell it to; g++ will.

1
  • 1
    @questions: It will compile C++; but if you use it to link your program, it won't include the C++ library. In general, you should use g++ for C++, and gcc for C. Apr 13, 2012 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.