minjoonist   3년 전

이 코드에서 컴파일 에러가 나는데 왜 그런지 모르겠습니다. 도데체 뭐가 문제일까요? 

컴파일 에러 메시지는 이렇습니다

/tmp/ccpewNpt.o: In function `_GLOBAL__sub_I_n':
Main.cc:(.text.startup+0x12): relocation truncated to fit: R_X86_64_32 against `.bss'
Main.cc:(.text.startup+0x21): relocation truncated to fit: R_X86_64_32 against `.bss'
gcc-8.3.0/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../lib64/libstdc++.a(ios_init.o): In function `std::basic_streambuf<char, std::char_traits<char> >::basic_streambuf()':
/root/temp/language/gcc-8.3.0-build/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:473:(.text._ZNSt8ios_base4InitC2Ev+0x42): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in gcc-8.3.0/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../lib64/libstdc++.a(globals_io.o)
/root/temp/language/gcc-8.3.0-build/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:473:(.text._ZNSt8ios_base4InitC2Ev+0x49): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in gcc-8.3.0/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../lib64/libstdc++.a(globals_io.o)
/root/temp/language/gcc-8.3.0-build/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:473:(.text._ZNSt8ios_base4InitC2Ev+0x54): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in gcc-8.3.0/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../lib64/libstdc++.a(globals_io.o)
/root/temp/language/gcc-8.3.0-build/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:473:(.text._ZNSt8ios_base4InitC2Ev+0x69): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in gcc-8.3.0/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../lib64/libstdc++.a(globals_io.o)
/root/temp/language/gcc-8.3.0-build/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:473:(.text._ZNSt8ios_base4InitC2Ev+0x74): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in gcc-8.3.0/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../lib64/libstdc++.a(globals_io.o)
/root/temp/language/gcc-8.3.0-build/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:473:(.text._ZNSt8ios_base4InitC2Ev+0x89): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in gcc-8.3.0/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../lib64/libstdc++.a(globals_io.o)
/root/temp/language/gcc-8.3.0-build/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:473:(.text._ZNSt8ios_base4InitC2Ev+0x94): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in gcc-8.3.0/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../lib64/libstdc++.a(globals_io.o)
/root/temp/language/gcc-8.3.0-build/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:473:(.text._ZNSt8ios_base4InitC2Ev+0xa3): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in gcc-8.3.0/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../lib64/libstdc++.a(globals_io.o)
/root/temp/language/gcc-8.3.0-build/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:473:(.text._ZNSt8ios_base4InitC2Ev+0xb6): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status

julysky   3년 전

mp[MAX][MAX] 가 거의 40기가를 차지하는데 의도하신건가요?

minjoonist   3년 전

사칙연산부터 다시 공부하고 오겠습니다.

minjoonist   3년 전

근데 왜 메모리 초과가 아닌 컴파일 에러로 뜰까요?

bupjae   3년 전

컴파일 에러가 난 이유는 컴파일러(*)가 mp 의 메모리 주소를 정하고 프로그램에서 mp를 참조하는 부분의 주소를 확정하는 작업에 실패했기 때문입니다.

정말로 저 정도의 큰 정적 메모리가 필요하다면 컴파일 할 때 메모리 주소를 정하는 방식을 바꾸는 옵션(-mmodel)을 사용해야 합니다만, BOJ에서는 불가능합니다.

이 문제에 대해 자세히 알아보고 싶으면 Relocation truncated to fit - WTF? 를 읽어보는 것도 좋습니다.

   

(*) 엄밀하게 이야기하면 이 에러는 '컴파일러' (C/C++ 소스 코드를 중간 파일로 번역하는 작업) 이 아니라 '링커' (컴파일러가 만든 중간 파일을 각종 라이브러리와 한데 묶어 실행할 수 있는 형태로 이어주는 작업) 가 내뱉은 에러입니다만, BOJ 에서는 링커 에러도 '컴파일 에러'로 취급합니다.

댓글을 작성하려면 로그인해야 합니다.