c++ 뉴비 도와주세요!1

현재 다음과 같이 오류문이 뜨고 있습니다ㅠㅜ
gcc -o magic_square main.o magic_square.o
main.o: In function main': main.cc:(.text+0x4b): undefined reference tooperator new[](unsigned long)’
main.cc:(.text+0x9c): undefined reference to operator new[](unsigned long)' main.cc:(.text+0x101): undefined reference tostd::cout’
main.cc:(.text+0x106): undefined reference to std::ostream::operator<<(int)' main.cc:(.text+0x113): undefined reference tostd::basic_ostream<char, std::char_traits >& std::operator<< <std::char_traits >(std::basic_ostream<char, std::char_traits >&, char const*)’
main.cc:(.text+0x123): undefined reference to std::cout' main.cc:(.text+0x128): undefined reference tostd::basic_ostream<char, std::char_traits >& std::operator<< <std::char_traits >(std::basic_ostream<char, std::char_traits >&, char)’
main.cc:(.text+0x178): undefined reference to operator delete[](void*)' main.cc:(.text+0x191): undefined reference tooperator delete
main.o: In function __static_initialization_and_destruction_0(int, int)': main.cc:(.text+0x1c4): undefined reference tostd::ios_base::Init::Init()’
main.cc:(.text+0x1d3): undefined reference to std::ios_base::Init::~Init()' magic_square.o: In function__static_initialization_and_destruction_0(int, int)’:
magic_square.cc:(.text+0xc5): undefined reference to std::ios_base::Init::Init()' magic_square.cc:(.text+0xd4): undefined reference tostd::ios_base::Init::~Init()’
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target ‘magic_square’ failed
make: *** [magic_square] Error 1

//Makefile
magic_square: main.o magic_square.o
gcc -o magic_square main.o magic_square.o
main.o: magic_square.h main.cc
gcc -c -o main.o main.cc
magic_square.o: magic_square.h magic_square.cc
gcc -c -o magic_square.o magic_square.cc
clean:
rm magic_square magic_square.o main main.o
//

// magic_spuare.h
#include
#include <stdlib.h>
void Make(int n, int **arr);

//magic_square.cc

#include “magic_square.h”
void Make(int n, int **arr){
for(int i=0, j=n/2,num=1; num<=(n*n); num++ ){
arr[i][j]=num;
if(num%n==0){i++;}
else{
i–, j++;
if(i<0){i=n-1;}
if(j>(n-1)){j=0;}

	}
}

}

// main.cc
#include “magic_square.h”
int main(int argc, char** argv){
int n= atoi(argv[1]);
int *arr ;
arr = new int
[n];
for(int i=0; i<n; i++){
arr[i]=new int[n];
}

Make(n,arr);
for(int i=0; i<n; i++){
	for(int j=0; j<n; j++){
		std::cout << arr[i][j] <<" ";
	}
std::cout << '\n';

}
    for(int i=0; i<n; i++){
            delete [] arr[i];
    }
    delete[] arr;
    return 0;

}

도통 무엇이 잘못인지 알수 없어서… 도와주신다면 정말 감사하겠습니다!!
사이트 처음이라 혹시 미숙한 점이 있다면 댓글로 알려주시면 시정하겠습니다.
감사합나다.

코드는 백틱`세개로 감싸면 보기 편하고 복사도 할수 있게 이쁘게 나옵니다. 보는 사람들이 편하게 해 주는게, 답글 달리는데 많이 도움이 되구요. “이글” 도 한번 읽어 보시구요.

Gcc가아니라 g++로 컴파일하세용 ^^

1 Like