0

The build code of binutils:

echo -e "${BLUE}===================== build gas && gold ===========================${NC}"
echo

if [ ! -f ${PWD_PATH}/succeed/binutils ]; then
    wget -c 'https://ftp.gnu.org/gnu/binutils/binutils-2.30.tar.xz'
    tar xvJf binutils-2.30.tar.xz
    rm -r binutils-2.30/gas
    rm -r binutils-2.30/gold

    cp -r ${SRC_PATH}/binutils/gas-2.30 ${GAS_DIR}

    cp -r ${SRC_PATH}/binutils/gold-2.30 ${GOLD_DIR}

    cp $PROTODEF_DIR/$C_HDR $GAS_DIR

    cp $PROTODEF_DIR/$CC_HDR ${GOLD_DIR}/
    cp $PROTODEF_DIR/$PROTO_C ${GOLD_DIR}/

    eval "cd $PWD_PATH/binutils-2.30 && mkdir -p build && cd build"

    CFLAGS="`pkg-config --cflags 'libprotobuf-c >= 1.0.0'`" LDFLAGS=`pkg-config --libs 'libprotobuf-c >= 1.0.0'` \
            ../configure --enable-gold --prefix=${PWD_PATH}/executable_binutils \
            --disable-werror --enable-shared \
             --enable-ld=default \
             --fcommon \
         --enable-plugins    \
             --enable-64-bit-bfd \
             --with-system-zlib \
            && make -j$(nproc)
            # && make install
    echo "done" > ${PWD_PATH}/succeed/binutils
fi

echo
echo -e "${GREEN}[*] build gas&&gold succeed!${NC}"

GAS_PATH=$PWD_PATH/binutils-2.30/build/gas/as-new
GOLD_PATH=$PWD_PATH/binutils-2.30/build/gold/ld-new

# get gcc-8.1.0
GCC_PATH="$PWD_PATH/gcc-8.1.0"
# GCC_EXE_PATH="$PWD_PATH/gcc_executable"
#GCC_EXE_PATH=""
GCC_BUILD_PATH="$PWD_PATH/build_gcc"
GCC_EXE_PATH="$PWD_PATH/executable_gcc"


# soft link gas
eval " sudo cp /usr/bin/as /usr/bin/as.old"
echo

Here I want to pass the -fcommon flag in CFLAGS as I'm getting the multiple definitions error. But not sure how to pass this flag. I'd tried to add as --fcommon in the configure line and below it but it is not working.

The error message:

binutils-2.30/depcomp
binutils-2.30/config.guess
binutils-2.30/ltmain.sh
binutils-2.30/ltsugar.m4
configure: error: unrecognized option: `--fcommon'
Try `../configure --help' for more information.

[*] build gas&&gold succeed!
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
NobinPegasus
  • 545
  • 2
  • 16

1 Answers1

0

configure is not a compiler. You can't pass it compiler flags.

It does configure the compiler. If you check the autoconf documentation, or run configure --help, you'll find:

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.
  ...
Some influential environment variables:
  ...
  CFLAGS      C compiler flags
  ...

So, you can add CFLAGS=-fcommon to the configure command line.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • ``` CFLAGS="`pkg-config --cflags 'libprotobuf-c >= 1.0.0'`" LDFLAGS=`pkg-config --libs 'libprotobuf-c >= 1.0.0'` \ ../configure --enable-gold --prefix=${PWD_PATH}/executable_binutils \ --disable-werror --enable-shared \ --enable-ld=default \ --fcommon \ --enable-plugins \ --enable-64-bit-bfd \ --with-system-zlib \ ``` should I pass it above the configure? like exact on which line? there's already CFLAGS in the script – NobinPegasus Apr 04 '23 at 21:30
  • Got it. I was getting confused with the ` " ' and mixing up the scopes. CFLAGS="`pkg-config --cflags 'libprotobuf-c >= 1.0.0'` -fcommon " – NobinPegasus Apr 04 '23 at 21:41