Mingw、Boost和运行时“找不到过程入口点”的问题

3

问题

我正在使用mingw在Windows上使用websocketpp制作一个简单的服务器应用程序。我已经成功编译和链接了我的代码。但是,当我启动应用程序时,它会给我以下错误窗口:

The procedure entry point _ZNSt6chrono3_V212steady_clock3nowEv could not be located in the DLL D:\work\wild_web\a.exe

我的设置

以下是我编译和链接代码的方法:

g++ -std=c++11 -march=i686 d:/work/wild_web/main.cpp -o a.exe -ID:/work/libs/boost_1_61_0 -ID:/work/websocketpp-master/websocketpp-master -LD:/work/libs/boost_1_61_0/stage/lib -lboost_system-mgw49-mt-s-1_61 -lws2_32 -lwsock32 -lboost_chrono-mgw49-mt-s-1_61

Compilation finished at Sun Jul 24 16:48:09

以下是我构建Boost的方法:

b2 --build-dir=build-directory toolset=gcc --build-type=complete stage

main.cpp:

#define _WIN32_WINNT 0x0501

#include <iostream>

#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>

#include <boost/chrono.hpp>

#include <string>
#include <sstream>
#include <vector>
#include <map>

//bunch of structs
int main() {
  //working with websocketpp
  return 0;
}

我有一种感觉,问题出在我的第一行的#define上,可能会导致dll接口的改变。但如果我删除它,代码就无法编译:

error: '::VerSetConditionMask' has not been declared
const uint64_t condition_mask = ::VerSetConditionMask(

问题

  1. #define _WIN32_WINNT 0x0501是否会影响boost库的使用?
  2. 我是否正确链接了boost库?
  3. 如果问题1和2的答案是肯定的,那么我该怎么做才能使它正常工作?

0x0501 是为 Windows XP 设计的。它需要在 XP 上运行吗?你必须将 _WIN32_WINNT 设置为某个值,以便使用 boost:asio。我发现在 Windows 10 上,使用 mingw 编译和运行时,将 _WIN32_WINNT _WIN32_WINNT_WIN7(0x0601)和 NTDDI_VERSION NTDDI_WIN7 都可以正常工作。 - kenba
我使用的是Windows 8操作系统。尝试了#define _WIN32_WINNT 0x0602#define NTDDI_VERSION NTDDI_WIN8,但遗憾的是没有起到作用。 - Kirill Daybov
1个回答

6
我解决了这个问题。使用依赖项查看器,我发现缺失的函数应该在libstd++6.dll中。显然我有两个这样的文件:一个属于Windows,另一个由MinGW提供。并且当我运行我的应用程序时,似乎使用了Windows的那个。
将.exe移动到带有MinGW库的文件夹中就可以解决问题了。但是我还发现有一个编译器标志-static-libstdc++,可以使用它来静态链接到由libstd++6提供的函数。

1
标志“-static-libstdc++”对我非常有效,谢谢!我在使用MSYS2提供的g++时也遇到了同样的问题。 - Kepler

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接