&#34;未定义的参考&#34;包含<iostream>时出错

时间:2018-06-18 19:08:19

标签: c++ g++ cygwin codeblocks undefined-reference

我已经使用Cygwin编译器和g ++ 7.3.0在Code :: Blocks 17.12中启动了一个新的控制台应用程序(C ++),而且我只有#34; main.cpp&#34;它的代码非常小:

#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\1\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LC:\cygwin\lib -o bin\Debug\1.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))

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

1 个答案:

答案 0 :(得分:0)

终于修好了!只是给仍在搜索的人提供答案, 只需安装Cygwin并转到code :: blocks中的settings -> compiler并选择Cygwin GCC而不是GNU GCC编译器,转到Toolchain excutables并将“Compiler's Installation Directory”更改为Cygwin目录并更改“Program files”对于你的cygwin程序(如果它们尚未被修改),编译器窗口应该看起来像screenshot