【发布时间】:2013-04-22 13:51:45
【问题描述】:
我正在尝试使用 MinGW 编译 DLL,并从使用 Visual Studio 编译器编译的可执行文件中使用它。
DLL中的一个源文件正在使用hash_map,它可以用MinGW成功编译。
当我将 hash_map<> 更改为 std::tr1::unordered_map<> 并将 #include <tr1/unordered_map> 添加到我的代码中时,它正在为 Visual Studio 编译器成功编译。(How can I force MinGW to use tr1 namespace?)
但是当我尝试使用 MinGW 将代码编译为 DLL 并从使用 Visual Studio 编译器编译的可执行文件中使用它时,它会给出错误:无法打开包含文件 'tr/unordered_map'
My DLL 必须同时兼容 cl 和 MinGW 吗?
编辑: 我的编译命令如下:
g++ -shared -o stemming.dll stemming.cpp alphabet.cpp basic.cpp determinise.cpp fst.cpp hopcroft.cpp operators.cpp utf8.cpp -Wl,--output-def,stemming.def,--out-implib,libstemming.a
lib /machine:i386 /def:stemming.def
cl sfstMinGW.cpp SFST/stemming.lib
【问题讨论】:
-
所有这些容器都应该是 Dll 实现的一部分,而不是接口。在这种情况下,它们的标头应仅包含在 .cpp 文件中,并且不应影响使用其他编译器构建的 Dll 客户端。如果您尝试将模板化容器包含到 Dll 接口中,这是错误的,即使对于相同的编译器也是如此。
-
您实际上是在尝试
#includetr /unordered_map 还是您的问题中的拼写错误?
标签: c++ compiler-construction hashmap mingw unordered-map