I tried to link an object file "blas.o", compiled from a user-written C file, with some third-party libraries.
It works in this way,
$ gcc blas.o -lgsl -lgslcblas -lm
but not in this way
$ gcc -lgsl -lgslcblas -lm blas.o
blas.o: In function `main':
blas.c:(.text+0xf9): undefined reference to `gsl_matrix_view_array'
blas.c:(.text+0x116): undefined reference to `gsl_matrix_view_array'
blas.c:(.text+0x136): undefined reference to `gsl_matrix_view_array'
blas.c:(.text+0x16f): undefined reference to `gsl_blas_dgemm'
collect2: error: ld returned 1 exit status
Above, blas.o depends on the linked libraries but not inversely. Could I conclude that the linker actually takes symbols from right to left from the command line? My gcc and ld versions are listed below:
$gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
Copyright info...
$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.26.1
Copyright info...
I understand that the order of the linked libraries and objects can matter for some linkers. But, in general, is there a safe (or called universal) order to link the libraries in a GCC command line? For example, is there a kind of standard that all linkers comply with?