Cross compiling newlib for ARM target in mingw-w64 environment - arm

I'm trying to cross compile the newlib for ARM under the mingw-w64 environment.
Toolchain was downloaded from here: GNU Arm Embedded Toochain
Newlib cloned from its GIT repository
I'm running my configuration script from mingw64 shell:
#!/bin/sh
export PATH=$PATH:/d/Toolchain/gcc-arm-none-eabi-10.3-2021.10/bin
../newlib-cygwin/configure CROSS_COMPILE=arm-none-eabi- ARCH=arm CFLAGS="-specs=nosys.specs" \
--target=arm-none-eabi \
--prefix="/d/work/newlib-install/" \
--disable-newlib-supplied-syscalls \
--enable-newlib-reent-check-verify \
--enable-newlib-reent-small \
--enable-newlib-retargetable-locking \
--disable-newlib-fvwrite-in-streamio \
--disable-newlib-fseek-optimization \
--disable-newlib-wide-orient \
--enable-newlib-nano-malloc \
--disable-newlib-unbuf-stream-opt \
--enable-lite-exit \
--enable-newlib-global-atexit \
--enable-newlib-nano-formatted-io \
--disable-nls
And i get an error during configure:
configure: error: in `/d/work/newlib-build'
configure: error: C compiler cannot create executables
See `config.log' for more details.
And in config log:
Target: x86_64-w64-mingw32
Thread model: posix
gcc version 9.2.0 (Rev2, Built by MSYS2 project)
configure:4393: $? = 0
configure:4382: gcc -V >&5
gcc.exe: error: unrecognized command line option '-V'
gcc.exe: fatal error: no input files
compilation terminated.
configure:4393: $? = 1
configure:4382: gcc -qversion >&5
gcc.exe: error: unrecognized command line option '-qversion'; did you mean '--version'?
gcc.exe: fatal error: no input files
compilation terminated.
configure:4393: $? = 1
configure:4413: checking for C compiler default output file name
configure:4435: gcc -specs=nosys.specs conftest.c >&5
gcc.exe: fatal error: cannot read spec file 'nosys.specs': No such file or directory
compilation terminated.
It means that configure chooses my mingw64 gcc as target compiler instead of arm-none-eabi-gcc.
Is it possible to compile that in mingw64?

Related

Cross-compiling C project to PE32+ executable from within macOS using Clang

I am currently attempting to cross-compile my C source code into a PE32+ executable, which hasn't yielded the greatest results.
I'm running macOS Ventura Beta 8 (macOS 13), using Clang which is bundled with LLVM (which was installed via the Homebrew tap).
Here is the command for compiling the source files:
/usr/local/opt/llvm/bin/clang \
--target=x86_64-unknown-windows-gnu \
-Wl,-e,_KernMain \
-o kernel.o \
src/Kernel/Kernel.c \
src/Kernel/Memory/KernMem.c \
src/Kernel/Graphics/KernGraphics.c \
-I/Users/kernel/Documents/edk2-master/edk2/MdePkg/Include/ \
-I/Users/kernel/Documents/edk2-master/edk2/MdePkg/Include/X64 \
-I/Users/kernel/Documents/edk2-master/edk2/KernelOSPkg/src/Common \
-I/Users/kernel/Downloads/mingw64/x86_64-w64-mingw32/include \
-L/Users/kernel/Documents/edk2-master/edk2/MdePkg/Library/ \
-L/Users/kernel/Downloads/mingw64/x86_64-w64-mingw32/lib \
-L/Users/kernel/Downloads/mingw64/x86_64-w64-mingw32/lib/ldscripts \
-L/usr/local/lib \
-fuse-ld="/usr/local/opt/llvm/bin/ld.lld"
It throws the following error:
lld: error: unable to find library -lgcc
lld: error: unable to find library -lgcc_eh
lld: error: unable to find library -lgcc
lld: error: unable to find library -lgcc_eh
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
CLANG info:
/usr/local/opt/llvm/bin/clang --version
Homebrew clang version 15.0.2
Target: x86_64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
ld.lld info:
/usr/local/opt/llvm/bin/ld.lld --version
Homebrew LLD 15.0.2 (compatible with GNU linkers)
The issue was that I didn't include the /path/to/mingw64/lib/gcc/x86_64-w64-mingw32/<version> directory, which included the libgcc.a and libgcc_eh.a files.
Though, I still do not know how to resolve the issue with an undefined symbol: WinMain. I will update this answer if I find a solution.
Error in question:
ld.lld: error: undefined symbol: WinMain
>>> referenced by libmingw32.a(lib64_libmingw32_a-crt0_c.o):(.text.startup)
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
Compilation command (does not compile successfully due to undefined symbol):
/usr/local/opt/llvm/bin/clang \
-target x86_64-unknown-windows-gnu \
-Wl,-e,KernMain \
-fuse-ld=lld \
-ffreestanding \
-o kernel.o \
src/Kernel/Kernel.c \
src/Kernel/Memory/KernMem.c \
src/Kernel/Graphics/KernGraphics.c \
-I/Users/kernel/Documents/edk2-master/edk2/MdePkg/Include/ \
-I/Users/kernel/Documents/edk2-master/edk2/MdePkg/Include/X64 \
-I/Users/kernel/Documents/edk2-master/edk2/KernelOSPkg/src/Common \
-I/Users/kernel/Downloads/mingw64/x86_64-w64-mingw32/include \
-L/Users/kernel/Downloads/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0 \
-L/Users/kernel/Documents/edk2-master/edk2/MdePkg/Library/ \
-L/Users/kernel/Downloads/mingw64/x86_64-w64-mingw32/lib \
-fshort-wchar
EDIT: To fix the aforementioned error with the undefined symbol, simply supply -nostdlib to the compiler.

Cross-compiling older version of gcc (4.8.2) on Ubuntu 14.04 fails in configure script

I've spent quite a few days now trying to cross-compile gcc 4.8.2 so I can use that generated compiler to compile an older version of strace for a big-endian MIPS system, and I've mainly been following this guide: https://comparch-resources.ece.gatech.edu/resources/gcc-mips/gcc-from-source/
Everything in that guide works up to the point of rebuilding gcc with newlib. Upon executing that rebuild command, I get the following error:
checking for mips-linux-gnu-gcc... /opt/cross/gcc-build/./gcc/xgcc -B/opt/cross/gcc-build/./gcc/ -B/opt/cross/gcc-mips/mips-linux-gnu/bin/ -B/opt/cross/gcc-mips/mips-linux-gnu/lib/ -isystem /opt/cross/gcc-mips/mips-linux-gnu/include -isystem /opt/cross/gcc-mips/mips-linux-gnu/sys-include
checking for suffix of object files... configure: error: in `/opt/cross/gcc-build/mips-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
make[1]: *** [configure-target-libgcc] Error 1
make[1]: Leaving directory `/opt/cross/gcc-build'
make: *** [all] Error 2
Here is a partial excerpt from /opt/cross/gcc-build/mips-linux-gnu/libgcc/config.log:
Configured with: ../gcc-4.8.2/configure --target=mips-linux-gnu --prefix=/opt/cross/gcc-mips --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --disable-multilib --with-newlib
Thread model: posix
gcc version 4.8.2 (GCC)
configure:3358: $? = 0
configure:3347: /opt/cross/gcc-build/./gcc/xgcc -B/opt/cross/gcc-build/./gcc/ -B/opt/cross/gcc-mips/mips-linux-gnu/bin/ -B/opt/cross/gcc-mips/mips-linux-gnu/lib/ -isystem /opt/cross/gcc-mips/mips-linux-gnu/include -isystem /opt/cross/gcc-mips/mips-linux-gnu/sys-include -V >&5
xgcc: error: unrecognized command line option '-V'
xgcc: fatal error: no input files
compilation terminated.
configure:3358: $? = 1
configure:3347: /opt/cross/gcc-build/./gcc/xgcc -B/opt/cross/gcc-build/./gcc/ -B/opt/cross/gcc-mips/mips-linux-gnu/bin/ -B/opt/cross/gcc-mips/mips-linux-gnu/lib/ -isystem /opt/cross/gcc-mips/mips-linux-gnu/include -isystem /opt/cross/gcc-mips/mips-linux-gnu/sys-include -qversion >&5
xgcc: error: unrecognized command line option '-qversion'
xgcc: fatal error: no input files
compilation terminated.
configure:3358: $? = 1
configure:3374: /opt/cross/gcc-build/./gcc/xgcc -B/opt/cross/gcc-build/./gcc/ -B/opt/cross/gcc-mips/mips-linux-gnu/bin/ -B/opt/cross/gcc-mips/mips-linux-gnu/lib/ -isystem /opt/cross/gcc-mips/mips-linux-gnu/include -isystem /opt/cross/gcc-mips/mips-linux-gnu/sys-include -o conftest -g -O2 -Wno-error -minterlink-mips16 conftest.c >&5
/opt/cross/gcc-build/./gcc/as: 87: exec: -EB: not found
configure:3377: $? = 1
configure:3565: checking for suffix of object files
configure:3587: /opt/cross/gcc-build/./gcc/xgcc -B/opt/cross/gcc-build/./gcc/ -B/opt/cross/gcc-mips/mips-linux-gnu/bin/ -B/opt/cross/gcc-mips/mips-linux-gnu/lib/ -isystem /opt/cross/gcc-mips/mips-linux-gnu/include -isystem /opt/cross/gcc-mips/mips-linux-gnu/sys-include -c -g -O2 -Wno-error -minterlink-mips16 conftest.c >&5
/opt/cross/gcc-build/./gcc/as: 87: exec: -EB: not found
configure:3591: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "GNU C Runtime Library"
| #define PACKAGE_TARNAME "libgcc"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "GNU C Runtime Library 1.0"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL "http://www.gnu.org/software/libgcc/"
| /* end confdefs.h. */
|
| int
| main ()
| {
|
| ;
| return 0;
| }
configure:3605: error: in `/opt/cross/gcc-build/mips-linux-gnu/libgcc':
configure:3608: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
Opening up /opt/cross/gcc-build/gcc/as, we see that line 87 is exec $original ${1+"$#"}, and since exec is trying to execute -EB as opposed to <correct compiler> -EB, I think that this means $original is blank (i.e. not set) when being called by exec. However, I'm not sure what compiler $original should be set to in order for the configure script to not fail, and I've tried various options such as /opt/cross/gcc-build/./gcc/xgcc that all fail.
While superficially this post seems similar to some other ones from older times, I don't think anyone else ran into this particular obstacle with the exec issue. As such, any help would be greatly appreciated!

Failing to compile the zziplib library with MinGW on Windows 10

Good day
I am attempting to compile zziplib-0.13.69 (http://zziplib.sourceforge.net/) with MinGW, as I would like to use LuaZip for Lua 5.3.5. I have installed the dependency zlib 1.2.3. (http://www.zlib.net/), which thankfully has a windows installer. In order to create a UNIX environment and make use of the provided make files I use msys.bat, cd to the source directory and then set up the path to zlib 1.2.3 via:
export CPATH="C:\Program Files (x86)\GnuWin32\src\zlib\1.2.3\zlib-1.2.3"
As per normal I then run:
configure && make && make check && make install
The following error is then consistently generated during compiling:
checking CFLAGS for gcc -Wstrict-aliasing... -Wstrict-aliasing
checking CFLAGS for gcc -Warray-bounds... -Warray-bounds
checking CFLAGS making strings readonly... no, unknown
checking CFLAGS for strict prototypes... -Wstrict-prototypes
checking for pkg-config... no
configure: warning: pkgconfigdir=C:/mingw/lib/pkgconfig (see config.log)
configure: perhaps: make install pkgconfigdir=/
configure: warning: aclocaldir=C:/mingw/share/aclocal (see config.log)
configure: perhaps: make install aclocaldir=/mingw/share/aclocal
C:\MinGW\bin\sed.exe: -e expression #1, char 1: unknown command: `C'
configure: creating ./config.status
C:\MinGW\bin\sed.exe: -e expression #1, char 1: unknown command: `C'
config.status: creating Makefile
gawk: ./confjLOGyR/subs.awk:73: S["CFLAGS"]=" -fomit-frame-pointer -Wall -Wpointer-arith -Wsign-compare -Wmissing-declarations -Wdeclaration-after-statement -Werror-implicit-function-declarat"\
gawk: ./confjLOGyR/subs.awk:73: ^ backslash not last character on line
C:\MinGW\bin\sed.exe: couldn't write 1 item to stdout: Invalid argument
config.status: error: could not create Makefile
C:\MinGW\bin\sed.exe: -e expression #1, char 1: unknown command: `C'
C:\MinGW\bin\sed.exe: -e expression #1, char 1: unknown command: `C'
I have tried the guide "Compiling zziplib with MinGW" from: http://itsacleanmachine.blogspot.com/2012/03/compiling-zziplib-with-mingw.html
But unfortunately the error persists. New to compiling in general so excuse my ignorance.
Thanks in advance.

How to build a stm32 with cmake

I want to build a stm32 project with cmake. The host is Linux ubuntu 4.4.0-98-generic.
This is my CMakeLists.txt script file. I wrote this file refer to my Makefile. The Makefile works well.
cmake_minimum_required (VERSION 3.5)
set (CMAKE_SYSTEM_NAME Generic)
set (CMAKE_SYSTEM_PROCESSOR arm)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_ASM_COMPILER arm-none-eabi-as)
set (CMAKE_C_COMPILER arm-none-eabi-gcc)
set (CMAKE_OBJCOPY arm-none-eabi-objcopy)
set (CMAKE_OBJDUMP arm-none-eabi-objdump)
set (CMAKE_SIZE arm-none-eabi-size)
set (TARGET hUart)
set (MCU stm32f401re)
set (BOARD stm32f401re-nucleo)
set (APP uart)
set (CMAKE_ASM_FLAGS
-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
)
set (CMAKE_C_FLAGS
-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
-fno-common -fsigned-char -fmessage-length=0
-Wall -Wextra -Wshadow
-Os -ffunction-sections -data-sections
-g3
-std=c11
)
set (CMAKE_EXE_LINKER_FLAGS
-spec=nosys.specs -spec=nano.specs -u _printf_float -u _scanf_float
-Wl,--gc-sections -Wl,-map=${TARGET}.map,--cref
)
add_definitions (
-DNDEBUG
-DSTM32F401xE -DUSE_HAL_DRIVER -DUSE_FULL_ASSERT
-DUSE_STM32F4XX_NUCLEO
)
project (${TARGET})
include_directories (
drivers/${MCU}/cmsis
drivers/${MCU}/hal
bsp/${BOARD}
projects/${BOARD}
apps/${APP}
)
file (GLOB STARTUP
drivers/${MCU}/startup/*.s
)
message (STATUS "[DBG]: ${STARTUP})
file (GLOB CMSIS_SRCS
drivers/${MCU}/cmsis/*.c
drivers/${MCU}/hal/*.c
)
file (GLOB BSP_SRCS
bsp/${BOARD}/*.c
)
file (GLOB APP_SRCS
projects/${BOARD}/*.c
apps/uart/*.c
)
message (STATUS "[DBG]: ${APP_SRCS})
set (LINKER_SCRIPT drivers/${MCU}/linker/STM32F401VEHx_FLASH.ld)
add_executable (${TARGET}.elf ${STARTUP} ${CMSIS_SRCS} ${BSP_SRCS} ${APP_SRCS} ${LINKER_SCRIPT})
add_custom_target (${TARGET}.bin
DEPENDS ${TARGET}.elf
COMMAND ${CMAKE_OBJCOPY} -O binary ${TARGET}.elf ${TARGET}.bin
)
add_custom_target (${TARGET}.lst
DEPENDS ${TARGET}.elf
COMMAND ${CMAKE_OBJDUMP} -Sdh ${TARGET}.elf > ${TARGET}.lst
The error log like this.
ompiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: /usr/bin/arm-none-eabi-gcc
Build flags: -mcpu=cortex-m4;-mthumb;-mfloat-abi=hard;-mfpu=fpv4-sp-d16;-fno-common;-fsigned-char;-fmessage-length=0;-Wall;-Wextra;-Wshadow;-Os;-ffunction-sections;-data-section
Id flags:
The output was:
1
cc1: warning: unrecognized gcc debugging option: t
cc1: warning: unrecognized gcc debugging option: -
cc1: warning: unrecognized gcc debugging option: s
cc1: warning: unrecognized gcc debugging option: e
cc1: warning: unrecognized gcc debugging option: c
cc1: warning: unrecognized gcc debugging option: t
cc1: warning: unrecognized gcc debugging option: i
cc1: warning: unrecognized gcc debugging option: o
cc1: warning: unrecognized gcc debugging option: n
cc1: warning: unrecognized gcc debugging option: s
/usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libg.a(lib_a-exit.o): In function `exit':
exit.c:(.text.exit+0x16): undefined reference to `_exit'
collect2: error: ld returned 1 exit status
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.243r.c
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.253r.c
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.260r.c
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.245r.l
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.249r.l
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.231r.i
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.293r.s
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.247r.l
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.244r.r
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /usr/bin/arm-none-eabi-c++
Build flags:
Id flags:
The output was:
1
/usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2: error: ld returned 1 exit status
Determining if the C compiler works failed with the following output:
Change Dir: /home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/local/bin/make" "cmTC_ff236/fast"
/usr/local/bin/make -f CMakeFiles/cmTC_ff236.dir/build.make CMakeFiles/cmTC_ff236.dir/build
make[1]: Entering directory '/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_ff236.dir/testCCompiler.c.obj
/usr/bin/arm-none-eabi-gcc -o CMakeFiles/cmTC_ff236.dir/testCCompiler.c.obj -c /home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/CMakeTmp/te
Linking C executable cmTC_ff236
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_ff236.dir/link.txt --verbose=1
/usr/bin/arm-none-eabi-gcc CMakeFiles/cmTC_ff236.dir/testCCompiler.c.obj -o cmTC_ff236
/usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_ff236.dir/build.make:98: cmTC_ff236] Error 1
make[1]: Leaving directory '/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:126: cmTC_ff236/fast] Error 2
Now, how can I fix this?
And, how to create the dependencies? I can do it '-MM -MT' options on Makefile.
All other options are exactly same as Makefile.

"error: conflicting types for ‘sem_t’" when compiling eglibc-2.19 on Ubuntu

I was trying to build eglibc-2.19 on Ubuntu 14.04 LTS which I downloaded through
apt-get source libc6
I followed the INSTALL instructions but got this error when it ran into nptl
gcc sem_init.c -c -std=gnu99 -fgnu89-inline -fno-stack-protector -O2 -Wall -Winline -Wwrite-strings -fmerge-all-constants -frounding-math -g -Wstrict-prototypes -U_FORTIFY_SOURCE -I../include -I/home/gpanda/wksp/glibc/tmp2/glibc-build/nptl -I/home/gpanda/wksp/glibc/tmp2/glibc-build -I../sysdeps/unix/sysv/linux/x86_64/64/nptl -I../sysdeps/unix/sysv/linux/x86_64/64 -I../nptl/sysdeps/unix/sysv/linux/x86_64 -I../nptl/sysdeps/unix/sysv/linux/x86 -I../sysdeps/unix/sysv/linux/x86 -I../sysdeps/unix/sysv/linux/x86_64 -I../sysdeps/unix/sysv/linux/wordsize-64 -I../nptl/sysdeps/unix/sysv/linux -I../nptl/sysdeps/pthread -I../libpthread/sysdeps/pthread -I../sysdeps/pthread -I../ports/sysdeps/unix/sysv/linux -I../sysdeps/unix/sysv/linux -I../sysdeps/gnu -I../sysdeps/unix/inet -I../nptl/sysdeps/unix/sysv -I../ports/sysdeps/unix/sysv -I../sysdeps/unix/sysv -I../sysdeps/unix/x86_64 -I../nptl/sysdeps/unix -I../ports/sysdeps/unix -I../sysdeps/unix -I../sysdeps/posix -I../libpthread/sysdeps/posix -I../nptl/sysdeps/x86_64/64 -I../sysdeps/x86_64/64 -I../sysdeps/x86_64/fpu/multiarch -I../sysdeps/x86_64/fpu -I../sysdeps/x86/fpu -I../sysdeps/x86_64/multiarch -I../nptl/sysdeps/x86_64 -I../sysdeps/x86_64 -I../sysdeps/x86 -I../sysdeps/ieee754/ldbl-96 -I../sysdeps/ieee754/dbl-64/wordsize-64 -I../sysdeps/ieee754/dbl-64 -I../sysdeps/ieee754/flt-32 -I../sysdeps/wordsize-64 -I../sysdeps/ieee754 -I../sysdeps/generic -I../libpthread/include -I../libpthread -I../nptl -I../ports -I.. -I../libio -I. -I../libpthread/include -D_LIBC_REENTRANT -include ../include/libc-symbols.h -DNOT_IN_libc=1 -DIS_IN_libpthread=1 -DIN_LIB=libpthread -o /home/gpanda/wksp/glibc/tmp2/glibc-build/nptl/sem_init.o -MD -MP -MF /home/gpanda/wksp/glibc/tmp2/glibc-build/nptl/sem_init.o.dt -MT /home/gpanda/wksp/glibc/tmp2/glibc-build/nptl/sem_init.o
In file included from sem_init.c:20:0:
../libpthread/include/semaphore.h:28:0: warning: "SEM_FAILED" redefined [enabled by default]
#define SEM_FAILED ((void *) 0)
^
In file included from ../libpthread/include/semaphore.h:26:0,
from sem_init.c:20:
../nptl/sysdeps/unix/sysv/linux/x86/bits/semaphore.h:33:0: note: this is the location of the previous definition
#define SEM_FAILED ((sem_t *) 0)
^
In file included from sem_init.c:20:0:
../libpthread/include/semaphore.h:30:28: error: conflicting types for ‘sem_t’
typedef struct __semaphore sem_t;
^
In file included from ../libpthread/include/semaphore.h:26:0,
from sem_init.c:20:
../nptl/sysdeps/unix/sysv/linux/x86/bits/semaphore.h:40:3: note: previous declaration of ‘sem_t’ was here
} sem_t;
^
make[2]: *** [/home/gpanda/wksp/glibc/tmp2/glibc-build/nptl/sem_init.o] Error 1
make[2]: Leaving directory `/home/gpanda/wksp/glibc/tmp2/eglibc-2.19/nptl'
make[1]: *** [nptl/subdir_lib] Error 2
make[1]: Leaving directory `/home/gpanda/wksp/glibc/tmp2/eglibc-2.19'
make: *** [all] Error 2
Is this some kind of conflict between libpthread and nptl? How to fix this problem?
Thanks in advance.
Consider LinuxThreads has been superseded by NPTL, so I just removed the add-on libpthread from the eglibc directory, and re-did the configure and make, then everything seems to be ok now.
see LinuxThreads,NPTL
BTW, since I didn't use the standard /usr path as the "--prefix=" option for configure, so I need copy libstdc++.so.6 and libgcc_s.so.1 to my current build path to get "make check" pass.
see glibc Known_testsuite_failures
I got the same error because I ran a plain ./configure --prefix=/opt, so I ran apt-get source -b eglibc instead and I noted the configure flags it used:
(exec 3>&1; exit `( ( ( cd build-tree/i386-libc && CC="i686-linux-gnu-gcc-4.8" CXX="i686-linux-gnu-g++-4.8" AUTOCONF=false MAKEINFO=: /home/sashoalm/Workspace/apt-get-source/libc/eglibc-2.19/configure --host=i686-linux-gnu --build=$configure_build --prefix=/usr --without-cvs --enable-add-ons=libidn,"nptl " --enable-profile --without-selinux --enable-stackguard-randomization --enable-obsolete-rpc --with-pkgversion="Ubuntu EGLIBC 2.19-0ubuntu6.9" --with-bugurl="https://bugs.launchpad.net/ubuntu/+source/eglibc/+bugs" --with-headers=/home/sashoalm/Workspace/apt-get-source/libc/eglibc-2.19/debian/include --enable-kernel=2.6.24 --with-selinux --enable-multi-arch ) 2>&1 3>&-; echo $? >&4) | tee -a build-tree/log-build-i686-linux-gnu-libc >&3) 4>&1`)
The command is rather involved, more complex than usual for apt-get source, since glibc insists on being built from a separate directory. The actual configure flags are:
--host=i686-linux-gnu --build=$configure_build --prefix=/usr --without-cvs --enable-add-ons=libidn,"nptl " --enable-profile --without-selinux --enable-stackguard-randomization --enable-obsolete-rpc --with-pkgversion="Ubuntu EGLIBC 2.19-0ubuntu6.9" --with-bugurl="https://bugs.launchpad.net/ubuntu/+source/eglibc/+bugs" --with-headers=/home/sashoalm/Workspace/apt-get-source/libc/eglibc-2.19/debian/include --enable-kernel=2.6.24 --with-selinux --enable-multi-arch
It works with those arguments of course, since that's what Ubuntu maintainers used to compile the package with.
I don't really know which of those flags prevents the error, but if you use that command, or the exact arguments provided by apt-get source -b eglibc on your Ubuntu system, it should work well enough.

Resources