【发布时间】:2020-06-19 23:05:34
【问题描述】:
当我尝试在我的 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/../lib\libiconv.a(localcharset.o):localcharset.c:(.text+0x63): undefined reference to `__imp_GetACP'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\DBMSProject.dir\build.make:122: DBMSProject.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:92: CMakeFiles/DBMSProject.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:99: CMakeFiles/DBMSProject.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:134: DBMSProject] Error 2
我的设置:
Windows 10 x64
Mingw 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使用 gcc 8.1.0 从上面构建的 Boost 1.72.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 问题,一个错误?
我的系统上没有安装 ICU,可能是这种情况?
也许我应该动态链接 Boost.locale 库而不是静态链接?如果是这样,我该怎么做(因为它的构建目录中有很多 boost 语言环境库)?
【问题讨论】: