Monday, September 24, 2012

std::cout undefined issue in MacOSX

In Mac, sometimes, especially in terminal with Makefile, you would meet the error message, such as

"error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available",

even with a simple code as following:

#include <iostream>
int main(){
    std::cout << "hello world" << std::endl;
    return 0;
}

The main reason might be, the compiled being used is gcc instead of g++, in g++, not like gcc, the         -lstdc++ will be automatically added. This will link the STL library with your compiler.

No comments:

Post a Comment

prettify