When I try to use Boost::locale package in my C++ project (something as simple, as this is):
#include <boost/locale.hpp>
. . . . . .
boost::locale::generator gen;
std::locale lx = gen("rus");
std::locale::global(lx);
I got a link error:
[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
My setup:
Windows 10 x64
Mingw x86_64-8.1.0-posix-seh-rt_v6-rev0 (gcc 8.1.0)
CMake 3.17.0-rc2, its options: -DBOOST_LIBRARYDIR="valid-path-to-built-boost-libs" -DBoost_COMPILER=mgw81
Boost 1.72.0 built with gcc 8.1.0 from above (command to build was 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)
So, the question is: how can I make it to link properly? I already tried to google this problem, but nothing seems as the solution to my problem.
Maybe it's a kbown problem, a bug?
I haven't installed ICU on my system, maybe it's the case?
Maybe I should link Boost.locale library dynamically instead of doing it statically? If so, how can I do it (because there is a plenty of boost locale libs in its build directory)?
You probably need to link against iconv, worked in my case.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.