0

I try to compile JDK source code on Ubuntu 20.04. However, the configure script of JDK failed with some errors:

// conftest.cpp

#include <ft2build.h>
#include FT_FREETYPE_H

int main()
{
    FT_Library library;
    FT_Error error = FT_Init_FreeType(&library);
    if (error) {
        printf("Error occurred during init.\n");
    }
    else {
        printf("Initialised OK!\n");
    }

    return 0;
}

In Terminal, this can link OK:

$ g++ -o conftest  -I/usr/include/freetype2   -L/usr/lib/x86_64-linux-gnu   conftest.cpp   -lfreetype

but this not work:

$ g++ -o conftest  -I/usr/include/freetype2   -L/usr/lib/x86_64-linux-gnu -lfreetype conftest.cpp 
/usr/bin/ld: /tmp/ccpFC5Ih.o: in function `main':
conftest.cpp:(.text+0x23): undefined reference to `FT_Init_FreeType'
collect2: error: ld returned 1 exit status

Only difference is the order of the parameters and, from this freetype question1, it seems that it's a upgrade problem. I am pretty sure that already the current latest 20.04,

$ g++ --version
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0)
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
chenzero
  • 57
  • 1
  • 8
  • 2
    g++ library order matters (and with cycle dependencies, you might even need to place some lib twice). – Jarod42 Nov 24 '21 at 09:18
  • @Jarod42 Thanks! the conftest.cpp, is only dependent on freetype lib, seems without any cycle. I even tried strace with those two g++ commands, however, I can not see any big differences between them. and in Terminal, "$ readelf -s /usr/lib/x86_64-linux-gnu/libfreetype.so|grep FT_Init" shows that the function export symbol OK. It's really some strange... – chenzero Nov 24 '21 at 09:43
  • 1
    Related to [gcc-g++-parameter-order](https://stackoverflow.com/questions/14623415/gcc-g-parameter-order) – Jarod42 Nov 24 '21 at 10:12

0 Answers0