Undefined link to `libintl_gettext 'using MinGW / MSYS and CMake

I am trying to add gettext to a C ++ project. It compiles and works fine under Linux, but I get a linker error with MinGW32 on the 64-bit version of Windows 7. I compile with cmake -G "MSYS Makefiles" ..because MinGW does not work due to nebula. I also tried a ninja.

In CMakeLists.txti have

find_package(Gettext REQUIRED
include_directories(${GETTEXT_INCLUDE_DIR})
if (INTL_FOUND)
    find_package(INTL REQUIRED)
    include_directories(${INTL_INCLUDE_DIR})
endif()

What is like

 GETTEXT_INCLUDE_DIR = C:/MinGW/msys/1.0/local/include

The project compiles without problems, but then at the build 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'

and etc.

I looked at https://www.gnu.org/software/gettext/FAQ.html#integrating_undefined

and added to the CMakeLists.txtfollowing:

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 did not work.

+4
1

Win-, . Hello World, gettext.

, , , :

gcc -lintl.dll -D__USE_MINGW_ANSI_STDIO -Wall -Wextra -Werror -std=gnu99 -o testGettex.exe testGettex.c

:

C:\Users\Julien\AppData\Local\Temp\ccAvCaR2.o:testGettex.c:(.text+0x1a): undefined reference to `libintl_setlocale'
C:\Users\Julien\AppData\Local\Temp\ccAvCaR2.o:testGettex.c:(.text+0x2b): undefined reference to `libintl_setlocale'
C:\Users\Julien\AppData\Local\Temp\ccAvCaR2.o:testGettex.c:(.text+0x3e): undefined reference to `libintl_bindtextdomain'
C:\Users\Julien\AppData\Local\Temp\ccAvCaR2.o:testGettex.c:(.text+0x4a): undefined reference to `libintl_textdomain'
C:\Users\Julien\AppData\Local\Temp\ccAvCaR2.o:testGettex.c:(.text+0x56): undefined reference to `libintl_gettext'
C:\Users\Julien\AppData\Local\Temp\ccAvCaR2.o:testGettex.c:(.text+0x5e): undefined reference to `__printf__'
d:/prog/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Julien\AppData\Local\Temp\ccAvCaR2.o: bad reloc address 0x0 in section `.pdata'
d:/prog/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

, , .dll, .dll.a, :

gcc -D__USE_MINGW_ANSI_STDIO -Wall -Wextra -Werror -std=gnu99 -o testGettex.exe D:\Prog\Win-builds\bin\libintl-8.dll testGettex.c

, , CMake, .dll... , MinGW libintl.dll.a.

: , , , , -l

gcc -D__USE_MINGW_ANSI_STDIO -Wall -Wextra -Werror -std=gnu99 -o testGettex.exe testGettex.c -lintl.dll -liconv

, CMake .

+1

Source: https://habr.com/ru/post/1616022/


All Articles