I am trying to add gettext to a C++ project. It compiles and runs fine under Linux, but I get a linker error with MinGW32 in Windows 7 64 bit. I am compiling with cmake -G "MSYS Makefiles" ..
, because MinGW doesn't work for soe nebulous reason. I also tried ninja.
In the CMakeLists.txt
, I have
find_package(Gettext REQUIRED
include_directories(${GETTEXT_INCLUDE_DIR})
if (INTL_FOUND)
find_package(INTL REQUIRED)
include_directories(${INTL_INCLUDE_DIR})
endif()
Which is found as
GETTEXT_INCLUDE_DIR = C:/MinGW/msys/1.0/local/include
The project is compiling without problems, but then in the linking stage, I get the following errors:
<source file location> undefined reference to `libintl_gettext'
<source file location> undefined reference to `libintl_setlocale'
<source file location> undefined reference to `libintl_textdomain'
etc.
I had a look at https://www.gnu.org/software/gettext/FAQ.html#integrating_undefined
and added the following to CMakeLists.txt
:
SET(GCC_COVERAGE_COMPILE_FLAGS "-s -O2 -lintl")
SET(GCC_COVERAGE_LINK_FLAGS "-lintl")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" )
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
then I tried
SET(GCC_COVERAGE_COMPILE_FLAGS "-s -O2 -lintl -liconv -LC:/MinGW/msys/1.0/local/lib -IC:/MinGW/msys/1.0/local/include")
SET(GCC_COVERAGE_LINK_FLAGS "-lintl -liconv -LC:/MinGW/msys/1.0/local/lib -IC:/MinGW/msys/1.0/local/include")
which also didn't work.
pacman
on MSYS2 (Cygwin clone) using Meson+Ninja. Here in Ninja recipe the POSIX-like libs are indicated directly, using their full path names (while WinAPI libs goes by using-l...
notation). In my case I inserted this into the middle of the command line:/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../lib/libintl.dll.a
(which I copied from the other command line which succeeded). The real path/usr/lib/libintl.dll.a
works too. Cheers! – Veron