使用Boost区域设置时出现Mingw/Boost/C++链接错误(未定义对__imp_GetACP的引用)



当我尝试在C++项目中使用Boost::locale包时(就像这样简单(:

#include <boost/locale.hpp>
. . . . . .
boost::locale::generator gen;
std::locale lx = gen("rus");
std::locale::global(lx);

我得到一个链接错误:

[100%] Linking CXX executable DBMSProject.exe
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../liblibiconv.a(localcharset.o):localcharset.c:(.text+0x63): undefined reference to `__imp_GetACP'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFilesDBMSProject.dirbuild.make:122: DBMSProject.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFilesMakefile2:92: CMakeFiles/DBMSProject.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFilesMakefile2:99: CMakeFiles/DBMSProject.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:134: DBMSProject] Error 2

我的设置:

  • Windows 10 x64

  • 明x86_64-8.1.0-posix-seh-rt_v6-rev0(gcc 8.1.0(

  • CMake 3.17.0-rc2,其选项:-DBOOST_LIBRARYDIR="valid-path-to-built-boost-libs" -DBoost_COMPILER=mgw81

  • Boost 1.72.0由上面的gcc 8.1.0构建(构建命令为b2 --build-dir="..." --prefix="..." toolset=gcc install --build-type=complete -j 4(

CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)
project(DBMSProject)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_PREFIX_PATH ${BOOST_LIBRARYDIR}\cmake)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -liconv")
find_package(Boost CONFIG REQUIRED COMPONENTS locale regex) # yes, I also tried regex, and everything was OK
include_directories(${Boost_INCLUDE_DIRS})
add_executable(DBMSProject main.cpp)
target_link_libraries(DBMSProject -static)
target_link_libraries(DBMSProject Boost::locale Boost::regex)

所以,问题是:我如何才能使它正确地链接?我已经试过用谷歌搜索这个问题,但似乎没有什么能解决我的问题。

也许这是kbown的问题,一个bug?

我的系统上还没有安装重症监护室,也许是这样吧?

也许我应该动态链接Boost.locae库,而不是静态链接?如果是,我该怎么做(因为它的构建目录中有很多boost locale lib(?

您可能需要链接到iconv,在我的案例中就是这样。

mingw64下的GetACP链接错误(mingw构建(

最新更新