为什么 boost 文件系统和 libpq-fe 标头不会在同一个文件中编译



当 boost/filesystem.hpp 和 libpq-fe.h 标头位于同一文件中时,我在链接我的文件时遇到挑战,请参阅下面的代码:

#include <boost/filesystem.hpp>
#include <iostream>
#include <stdio.h>
#include <string>
#include <windows.h>
#include <getopt.h>
#include <libpq-fe.h>
#include <sqlite3.h>
using namespace boost::filesystem;
int main()
{
return 0;
}

我的编译命令:

/d/MinGW/bin/g++ -o filesys filesys.cpp -Ilib/sqlite3/ -I"/c/Program Files/PostgreSQL/9.5/include/" -I/c/local/boost_1_71_0/

请注意,如果我注释掉#include <boost/filesystem.hpp>using namespace boost::filesystem;然后使用相同的命令行参数进行编译,则文件编译时没有错误!

这是我得到的错误:

-I"/c/Program Files/PostgreSQL/9.5/include/" -I/c/local/boost_1_71_0/
d:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersADMINI~1AppDataLocalTempcc6BrwZR.o:filesys.cpp:(.text+0x7b): undefined reference to `__imp_pthread_mutex_init'
d:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersADMINI~1AppDataLocalTempcc6BrwZR.o:filesys.cpp:(.text+0xa9): undefined reference to `__imp_pthread_mutex_destroy'
d:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersADMINI~1AppDataLocalTempcc6BrwZR.o:filesys.cpp:(.text+0xdd): undefined reference to `__imp_pthread_mutex_lock'
d:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersADMINI~1AppDataLocalTempcc6BrwZR.o:filesys.cpp:(.text+0x111): undefined reference to `__imp_pthread_mutex_unlock'
collect2.exe: error: ld returned 1 exit status

我的环境:

  • 视窗 7
  • MinGW/gcc 版本 8.2.0
  • 速推版 1_71

问候 噗嗤

编译时附加-pthread选项。

我想出了我的问题! 我使用的是来自Stephan T. Lavavej网站nuwen的MinGW发行版,其中包括1.69个库。然后我有自己的 boost 安装版本 1.71,我试图与之链接,猜测这导致了冲突。1

这是我编译应用程序的方式:

/d/MinGW/bin/g++ -o filesys filesys.cpp -Ilib/sqlite3/ -I"/c/Program Files/PostgreSQL/9.5/include/" -I/d/MinGW/include/ -lpthread -std=c++17

现在它编译得很好。

最新更新