Fun Stuff > CLIKC

A programming thread!

<< < (18/37) > >>

cesium133:
I'm using Fortran, and the syntax I always end up typing in is:

gfortran -lblas -llapack arss.f

when it should be

gfortran arss.f -lblas -llapack

I suppose I should get unlazy and make a proper makefile for the program (I was given just the Fortran source for it).

Schwungrad:

--- Quote from: snalin on 18 May 2014, 13:47 ---In C++ (gcc), on the other hand, options are after the sources. I think. So then it's the other way around. So the answer to your question is language-dependent.

--- End quote ---
http://linux.die.net/man/1/gcc says the options come before the input file(s). Same should go for gfortran. :?

However, dynamic linking works just the other way round: The compiler makes your source file into an object file that just contains the instruction "put args on the stack and call libraryfunction(args)". Then, in a second step, the linker makes the object file (or several object files) into an executable by adding the information that libraryfunction(args) is found in the file library.so (on Linux) or library.dll (on Windows) at address 0x00abcdef. At least that's how I think it works. So when you do linking and compiling in two different steps, you have to specify the libraries in the second step.

cesium133:
My problem was I was doing the compiling and linking as one command (rather than doing one command to build the object file then another to link it), and when doing it as one command gfortran expects the libraries to be after the source file that requires them.

Schwungrad:
That's odd. Judging from the manpage and from my own experience with gcc, putting the -llib options before the input file should also be the syntax for one-step compilation/linking. Not because the libraries are a prerequisite to linking, but because the invocation syntax demands all options being put before the input files.

Just out of curiosity, though it shouldn't make a difference: are you doing this on Windows?

cesium133:
Yes, and I'm using Cygwin.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version