multiple definition of 에러가 이상하게 납니다
vio@!@#$:~/cpp/OOP/6$ g++ -o main main.o NormalAccount.o HighCreditAccount.o Account.o AccountHandler.o
AccountHandler.o:(.bss+0x0): multiple definition of `AccountHandler::account_number'
main.o:(.bss+0x0): first defined here
collect2: ld returned 1 exit status
열혈강의c++ 로 공부중인데요
AccountHandler::account_number 가 중복정의 되어있다고 나옵니다.
그런데 중복정의된 부분을 도저희 못찾겠어서 Account.h AccountHandler.cpp 에 있는 모든 account_number를 number_of_account 로 바꾸어봤습니다.
그리고 컴파일 하면
vio@!@#$:~/cpp/OOP/6$ vi AccountHandler.cpp
vio@!@#$:~/cpp/OOP/6$ g++ -c AccountHandler.cpp
vio@!@#$:~/cpp/OOP/6$ g++ -o main main.o NormalAccount.o HighCreditAccount.o Account.o AccountHandler.o
vio@!@#$:~/cpp/OOP/6$
아무런 이상없이 실행도 잘 됩니다.
그리고 난 후 main 함수에 cout문장 하나 추가해 준 뒤 다시 컴파일 해보면
vio@!@#$:~/cpp/OOP/6$ g++ -c main.cpp
vio@!@#$:~/cpp/OOP/6$ g++ -o main main.o NormalAccount.o HighCreditAccount.o Account.o AccountHandler.o
AccountHandler.o:(.bss+0x0): multiple definition of `AccountHandler::number_of_account'
main.o:(.bss+0x0): first defined here
collect2: ld returned 1 exit status
다시 중복정의가 되어있다고 나옵니다
해더파일에 #ifndef #define #define 사용하였고 AccountHandler 파일에 중복 정의가 되어있다는 변수를 다 바꿔주고 컴파일하면
다시 정상적으로 컴파일되는데
왜 이런현상이 생기는지 궁금합니다.
1개월 뒤 저를 살려주셧습니다.
extern 선언하니 전 되네요 ㅎㅎㅎ
댓글 달기