Skip to content

Commit 3f808d4

Browse files
Fix -m32 unrecognized issue when compile 32-bit target on some 64-bit systems (#866)
When compile 32-bit targets on some 64-bit systems, the "-m32" flag might be unrecognized by some gcc compilers, e.g. compiling arm32 in aarch64 system, compiling riscv32 in riscv64 system. Add check before adding "-m32" flag to gcc, and only add it if it is supported.
1 parent 2af5ae5 commit 3f808d4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

build-scripts/config_common.cmake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ if (CMAKE_SIZEOF_VOID_P EQUAL 8)
6161
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
6262
endif ()
6363
else ()
64-
add_definitions (-m32)
65-
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
66-
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
64+
include(CheckCCompilerFlag)
65+
Check_C_Compiler_Flag( -m32 M32_OK )
66+
if (M32_OK)
67+
add_definitions (-m32)
68+
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
69+
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
70+
endif ()
6771
endif ()
6872
endif ()
6973

0 commit comments

Comments
 (0)