Home undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
Post
Cancel

undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'

문제

undefined reference to std::ostream::operator<<(std::ostream& (*)(std::ostream&))'라는 메세지와 함께 컴파일이 되지 않았다.

#include <iostream>도 제대로 선언했었고, namespace도 제대로 지정해주었으나, 계속 같은 문제가 발생하였다.

해결

검색을 해보니 컴파일러의 지정이 제대로 되어있지 않았던 문제였다.

tasks.json을 가보니 command 블럭에 /usr/bin/gcc로 되어있는 것을 확인했다.

/usr/bin/g++로 수정하여 c++로 컴파일하도록 수정하는 것으로 정상작동하는 것을 확인하였다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
  "tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: gcc 활성 파일 빌드",
      "command": "/usr/bin/g++",
      "args": [
        "-fdiagnostics-color=always",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": ["$gcc"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "디버거에서 생성된 작업입니다."
    }
  ],
  "version": "2.0.0"
}

Reference

기린의 공부 블로그

This post is licensed under CC BY 4.0 by the author.

OpenCV 트랙바 생성

연산자 오버로딩