"Undefined reference" 包含 <iostream> 时出错

"Undefined reference" errors when including <iostream>

我在 Code::Blocks 17.12 中使用 Cygwin 编译器和 g++ 7.3.0 启动了一个新的控制台应用程序 (C++),但我只有 "main.cpp",其中的代码非常少:

#include<iostream>
using namespace std;
int main(){
cout<<"test";
return 0;
}

我点击构建并出现 16 个错误,这是构建日志:

-------------- Build: Debug in 1 (compiler: Cygwin g++)---------------

g++.exe -Wall -fexceptions -g -std=c++14 -IC:\cygwin\usr\include -c C:\Users\Windows7\Desktop\BASIL\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LC:\cygwin\lib -o bin\Debug.exe obj\Debug\main.o   
obj\Debug\main.o: In function `_static_initialization_and_destruction_0':
/usr/lib/gcc/i686-pc-cygwin/7.3.0/include/c++/iostream:74: undefined reference to `__dso_handle'
/usr/lib/gcc/i686-pc-cygwin/7.3.0/include/c++/iostream:74: undefined reference to `__cxa_atexit'
C:\cygwin\lib/libpthread.a(t-d001702.o):fake:(.text+0x2): undefined reference to `_imp__pthread_mutex_destroy'
C:\cygwin\lib/libpthread.a(t-d001704.o):fake:(.text+0x2): undefined reference to `_imp__pthread_mutex_init'
C:\cygwin\lib/libpthread.a(t-d001709.o):fake:(.text+0x2): undefined reference to `_imp__pthread_mutex_unlock'
C:\cygwin\lib/libpthread.a(t-d001720.o):fake:(.text+0x2): undefined reference to `_imp__pthread_once'
C:\cygwin\lib/libpthread.a(t-d001705.o):fake:(.text+0x2): undefined reference to `_imp__pthread_mutex_lock'
C:\cygwin\lib/libpthread.a(t-d001699.o):fake:(.text+0x2): undefined reference to `_imp__pthread_key_create'
C:\cygwin\lib/libpthread.a(t-d001697.o):fake:(.text+0x2): undefined reference to `_imp__pthread_getspecific'
C:\cygwin\lib/libpthread.a(t-d001741.o):fake:(.text+0x2): undefined reference to `_imp__pthread_setspecific'
C:\cygwin\lib/libpthread.a(t-d001679.o):fake:(.text+0x2): undefined reference to `_imp__pthread_cond_wait'
C:\cygwin\lib/libpthread.a(t-d001674.o):fake:(.text+0x2): undefined reference to `_imp__pthread_cond_broadcast'
C:\cygwin\lib/libpthread.a(t-d001700.o):fake:(.text+0x2): undefined reference to `_imp__pthread_key_delete'
C:\cygwin\lib/libpthread.a(t-d001675.o):fake:(.text+0x2): undefined reference to `_imp__pthread_cond_destroy'
C:\cygwin\lib/libpthread.a(t-d001677.o):fake:(.text+0x2): undefined reference to `_imp__pthread_cond_signal'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 3 second(s))
16 error(s), 0 warning(s) (0 minute(s), 3 second(s))

我还根据文档在搜索目录选项卡中编辑了编译器、链接器和资源编译器,但这没有用。 请帮助我! 谢谢,

终于修好了!只是给仍在搜索的人答案, 只需安装 Cygwin 并转到 code::blocks 中的 settings -> compiler 并选择 Cygwin GCC 而不是 GNU GCC 编译器,转到工具链可执行文件并将 "Compiler's Installation Directory" 更改为您的 Cygwin 目录并更改 "Program files" 到您的 cygwin 程序(如果它们尚未修改),编译器 window 应该看起来像附加的 screenshot。