Search code examples
cross-compilinggawkgoogle-nativeclient

NaCl port : Excluding getopt from gawk build


I've been trying to port gawk for over a few days now, but I've been stuck at this issue for some time. I'm trying to make a standalone gawk nexe that runs on my Dev Environment (so I am using a static newlib build). Actually, GNU Awk 4.1.1 has its version of getopt.c, getopt.h and and few files, the definitions of which contradict with the ones provided in GNU C Library. I'm getting a multiple definition error. Here's the relevant console output :

[... more lines ...]
Making all in .
make[2]: Entering directory '/home/agaurav77/Programs/NaCl/naclports/src/out/build/gawk/build_x86-64_newlib'
/home/agaurav77/Programs/NaCl/nacl_sdk/pepper_canary//toolchain/linux_x86_newlib/bin/x86_64-nacl-gcc  -DNDEBUG -O2 -DNDEBUG  -Dmain=nacl_main -D__GNU_LIBRARY__ -o gawk.nexe array.o awkgram.o builtin.o cint_array.o command.o debug.o dfa.o eval.o ext.o field.o floatcomp.o gawkapi.o gawkmisc.o getopt.o getopt1.o int_array.o io.o main.o mpfr.o msg.o node.o profile.o random.o re.o regex.o replace.o str_array.o symbol.o version.o     -lmpfr -lgmp -lm -lm 
/home/agaurav77/Programs/NaCl/nacl_sdk/pepper_canary/toolchain/linux_x86_newlib/bin/../lib/gcc/x86_64-nacl/4.4.3/../../../../x86_64-nacl/lib/../lib64/libcrt_common.a(lib_a-getopt.o): In function `getopt_long_only':
getopt.c:(.text+0x1600): multiple definition of `getopt_long_only'
getopt1.o:getopt1.c:(.text+0xa0): first defined here
/home/agaurav77/Programs/NaCl/nacl_sdk/pepper_canary/toolchain/linux_x86_newlib/bin/../lib/gcc/x86_64-nacl/4.4.3/../../../../x86_64-nacl/lib/../lib64/libcrt_common.a(lib_a-getopt.o):(.bss+0x4): multiple definition of `optind'
getopt.o:(.data+0x0): first defined here
/home/agaurav77/Programs/NaCl/nacl_sdk/pepper_canary/toolchain/linux_x86_newlib/bin/../lib/gcc/x86_64-nacl/4.4.3/../../../../x86_64-nacl/lib/../lib64/libcrt_common.a(lib_a-getopt.o):(.data+0x0): multiple definition of `opterr'
getopt.o:(.data+0x4): first defined here
/home/agaurav77/Programs/NaCl/nacl_sdk/pepper_canary/toolchain/linux_x86_newlib/bin/../lib/gcc/x86_64-nacl/4.4.3/../../../../x86_64-nacl/lib/../lib64/libcrt_common.a(lib_a-getopt.o):(.data+0x4): multiple definition of `optopt'
getopt.o:(.data+0x8): first defined here
/home/agaurav77/Programs/NaCl/nacl_sdk/pepper_canary/toolchain/linux_x86_newlib/bin/../lib/gcc/x86_64-nacl/4.4.3/../../../../x86_64-nacl/lib/../lib64/libcrt_common.a(lib_a-getopt.o): In function `getopt_long':
getopt.c:(.text+0x16c0): multiple definition of 'getopt_long'
getopt1.o:getopt1.c:(.text+0xe0): first defined here
/home/agaurav77/Programs/NaCl/nacl_sdk/pepper_canary/toolchain/linux_x86_newlib/bin/../lib/gcc/x86_64-nacl/4.4.3/../../../../x86_64-nacl/lib/../lib64/libcrt_common.a(lib_a-getopt.o): In function `getopt':
getopt.c:(.text+0x1780): multiple definition of `getopt'
getopt.o:getopt.c:(.text+0x1e60): first defined here
collect2: ld returned 1 exit status
Makefile:643: recipe for target 'gawk.nexe' failed
make[2]: *** [gawk.nexe] Error 1
make[2]: Leaving directory'/home/agaurav77/Programs/NaCl/naclports/src/out/build/gawk/build_x86-64_newlib'
Makefile:727: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/agaurav77/Programs/NaCl/naclports/src/out/build/gawk/build_x86-64_newlib'
Makefile:546: recipe for target 'all' failed
make: *** [all] Error 2
naclports: Building gawk: failed.

Any pointers on how to get past this?

Thanks in advance.


Solution

  • As the gawk build likely functions in the presence of other libc's with getopt, I would suggest you figure out why configure is adding in the fallback version. Most likely some sort of test executable is being built by configure and something is failing. I would suggest searching the configure script for getopt to get some idea where it might be trying to do this. Then searching the config.log file generated during configure to find out what's failing.

    One possibility is that some builds which need to run test executables to check for broken functionality have a tendency to assume the broken functionality for cross-compiled builds.

    If all else fails you could gate out the built in version by ifdefing the contents of getopt.c out when defined(native_client)