1

I'm trying to compile a simple program in c++ with gsl. On our university server we have installed GSL. The main problem is, that I'm compilling:

g++ atest.cpp -c -lgsl -lgslcblas -c lm

And after that, I'm typing:

./a.out

And I get :

-bash: ./a.out : No such file or directory

What's the problem? Thanks.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
GoldenEgg25
  • 69
  • 1
  • 6

2 Answers2

7

You're only compiling, not linking. From man gcc:

       -c  Compile or assemble the source files, but do not link.  The linking
           stage simply is not done.  The ultimate output is in the form of an
           object file for each source file.

           By default, the object file name for a source file is made by
           replacing the suffix .c, .i, .s, etc., with .o.

           Unrecognized input files, not requiring compilation or assembly,
           are ignored.
Stephen Newell
  • 7,330
  • 1
  • 24
  • 28
  • 2
    Useful supplemental reading: [How does the compilation/linking process work?](https://stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work) – user4581301 Mar 05 '18 at 18:47
2

So -c option (command line argument) means compile

g++ atest.cpp -c -lgsl -lgslcblas -lm
g++ atest.o

this will produce a.out file, or you can use short hand

g++ atest.cpp -lgsl -lgslcblas -lm

which will compile and link code in one.

Plus, you could use ls to check your directory does it contain a.out before trying to run it.