如何在 windows (MinGW) 上将 posix 个线程添加到 eclipse 中
How to add posix threads into eclipse on windows (MinGW)
好的,所以我在 windows 8.1 OS 上 运行 Eclipse Mars.1(带有 MinGW 编译器)并且我正在尝试启用 POSIX 线程。
我已经从 https://www.sourceware.org/pthreads-win32 下载了 pthreads win32,因为 windows 没有像 linux 那样包含 pthread 库。下载 .zip 文件后,我解压了这样的文件:
- pthreadGC2.dll 到 C:\MinGW\bin
- pthread.h , sched.h, semaphore.h 到 C:\MinGW\include
- libpthreadGC2.a 到 C:\MinGW\lib
回到 Eclipse,我右击了项目 -> 属性 -> C/C++ 构建 -> 设置 -> MinGW C 链接器,现在问题来了,我不知道是什么我应该放入 Libraries/Miscellaneous 部分吗? Eclipse 正在识别 #include <pthread.h>
(它不是红色 - 在其下划线)和 pthread.h 函数,但是一旦我尝试构建它,它就会这样说:
15:10:11 **** 项目 ASD 的配置调试增量构建 ****
信息:Internal Builder 用于构建
gcc -o ASD.exe qweqwe.o -lpthread
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: 找不到-lpthread
collect2.exe:错误:ld 返回了 1 个退出状态
15:10:11 构建完成(耗时 122 毫秒)
我不知道我做错了什么,我试过将库名称(在链接器设置选项卡中)更改为 pthreadGC2,但如果我这样做,Eclipse 只是下划线 pthread_create 并说它是对 _imp_pthread_create 的未定义引用。
如果有人尝试并成功地做到了这一点,请分享您的智慧。提前致谢!
Is there any compiler suitable for eclipse that has pthread integrated in itself?
是的。从 mingw-w64 or from TDM-GCC 获取 GCC(适用于 Windows)。然后在 Eclipse-CDT 中将 -pthread
(不是 -lpthread
)添加到 Miscellaneous -> Linker flags.正如@FelixPalmen 所说, -pthread
是一个链接器选项,负责 pthread
链接。不需要其他设置。默认的包含和库路径就足够了。
或者您可以使用 MinGW 安装程序下载它。
好的,所以我在 windows 8.1 OS 上 运行 Eclipse Mars.1(带有 MinGW 编译器)并且我正在尝试启用 POSIX 线程。 我已经从 https://www.sourceware.org/pthreads-win32 下载了 pthreads win32,因为 windows 没有像 linux 那样包含 pthread 库。下载 .zip 文件后,我解压了这样的文件:
- pthreadGC2.dll 到 C:\MinGW\bin
- pthread.h , sched.h, semaphore.h 到 C:\MinGW\include
- libpthreadGC2.a 到 C:\MinGW\lib
回到 Eclipse,我右击了项目 -> 属性 -> C/C++ 构建 -> 设置 -> MinGW C 链接器,现在问题来了,我不知道是什么我应该放入 Libraries/Miscellaneous 部分吗? Eclipse 正在识别 #include <pthread.h>
(它不是红色 - 在其下划线)和 pthread.h 函数,但是一旦我尝试构建它,它就会这样说:
15:10:11 **** 项目 ASD 的配置调试增量构建 **** 信息:Internal Builder 用于构建 gcc -o ASD.exe qweqwe.o -lpthread c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: 找不到-lpthread collect2.exe:错误:ld 返回了 1 个退出状态
15:10:11 构建完成(耗时 122 毫秒)
我不知道我做错了什么,我试过将库名称(在链接器设置选项卡中)更改为 pthreadGC2,但如果我这样做,Eclipse 只是下划线 pthread_create 并说它是对 _imp_pthread_create 的未定义引用。
如果有人尝试并成功地做到了这一点,请分享您的智慧。提前致谢!
Is there any compiler suitable for eclipse that has pthread integrated in itself?
是的。从 mingw-w64 or from TDM-GCC 获取 GCC(适用于 Windows)。然后在 Eclipse-CDT 中将 -pthread
(不是 -lpthread
)添加到 Miscellaneous -> Linker flags.正如@FelixPalmen 所说, -pthread
是一个链接器选项,负责 pthread
链接。不需要其他设置。默认的包含和库路径就足够了。
或者您可以使用 MinGW 安装程序下载它。