0

I just compiled a cross gdb by compiling the source on MSYS2/MINGW64. But when I run gdb it throws an error and complains that it can not start because it needs libexpat-1.dll.

This is what I did to compile the gdb:

  • Got the source code git clone git://sourceware.org/git/binutils-gdb.git
  • In a different directory:
    • export TARGET=x86_64-amd-linux-gnu

    • export PREFIX=/tmp/myToolChain

    • binutils/gdb/path/configure --with-python=/mingw64/bin/python --target=${TARGET} --prefix=${PREFIX} --disable-shared --enable-static

    • and make && make install

It compiles without any problems. But I don't know why it needs the libraries while I've compiled it statically and disabled the shared libraries.

I also tried to use libexpat during compilation but then it complains about another library libiconv-2.dll.

What have I messed up?

Edit: I didn't have C:\msys64\mingw64\bin in my path. After adding it I'm not getting the previous error any more.

But I still have this question that why although I'm linking the libraries statically the final binary still needs some libraries?

Jinke2017
  • 49
  • 6
Ali
  • 1,001
  • 2
  • 14
  • 32
  • MSYS2 has three different shell environments: the MSYS2 Shell, the MinGW-w64 Win64 Shell, and the MinGW-w64 Win32 Shell. Which one are you using? (i.e. what is the value of `echo $MSYSTEM`?) How exactly are you running gdb and what is the exact error message that you are seeing? – David Grayson Jul 03 '16 at 19:15
  • I built the whole thing from MINGW-W64 Win64 shell; `$ echo $MSYSTEM` returns `MINGW64`. I open a CMD window in the directory and then run `x86_64-amd-linux-gnu-gdb.exe --version`. The error is `The program can't start because libexpat-1.dll is missing from your computer. Try reinstalling the program to fix this problem.` – Ali Jul 03 '16 at 19:34

1 Answers1

0

The reason the final binary is still looking for the libraries is that I was using the wrong flags. The flags --disable-shared --enable-static do not specify how the current build should link to the libraries, it rather specifies how the code that gets compiled with this binary should link to other libraries.

So, in order to make the gdb binary statically link with libexpat or any other library one should use configure like so

/binutils/gdb/path/configure --target=${TARGET} --prefix=${PREFIX} LDFLAGS="-static"

notice the LDFLAGS="-static" flag. It forces the final binary link statically to all libraries and it won't be looking for dlls when you run it.

Ali
  • 1,001
  • 2
  • 14
  • 32