when I build my source code in linux I got an error like
qstring.cpp:(.text+0x2c01): undefined reference to `terminate(void)'
collect2: ld returned 1 exit status
How to solve this problem?
The C++ [Error]: Id returned 1 exit status is not a common error. It usually means that the program crashed, and it will be challenging to determine why without looking at the stack trace. The C++ compiler will display this message when an error occurs in your code.
Collect2.exe is considered a type of Windows Executable file. It is most-commonly used in C-Free 5.0 Pro developed by Program Arts. It uses the EXE file extension and is considered a Win32 EXE (Windows Executable) file.
terminate
is defined in the C++ standard library, so make sure that you're linking that in. Assuming you're using gcc to compile, you should use the g++
executable to compile your source code, not the gcc
executable:
g++ source.cc -o output
When executed as g++
, the linker automatically links in the C++ standard library (libstdc++) for you. If you instead execute gcc as plain gcc
, or you directly invoke the linker ld
, then you need to add -lstdc++
yourself to link in the library, e.g.:
gcc source.cc -o output -lstdc++ # Compile directly from source
ld source1.o source2.o -o output -lstdc++ # Link together object files
You need to find out which object file or library terminate
lives in and include it in your compile/link command.
If it's in an object or source file, just give it to your gcc
(assuming you're actually using gcc
, if not, the method will probably be similar) command as per normal. If it's in a library, you should look into the -L
(library path) and -l
(library name) options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With