1

Installed gsl 2.5 on ubuntu 18.04.

Trying to compile and run a sample_matrix.c script using

$ gcc -Wall -I/usr/local/include -c sample_matrix.c

runs successfully; further to display the output,

$ ./a.out

gives an error :

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

I am currently in the folder named 'gsl' where the sample_matrix.c file is saved and this folder is also where I have installed the gsl pkg

screenshot the lists in gsl folder

4
  • The -c switch tells gcc to compile source code to binary object code, but not link it to create an executable program. You will need to remove that and also likely need to specify the gsl (and any other required) libraries (for example pkg-config --libs gsl) Jul 2, 2019 at 15:01
  • @steeldriver removing -c switch produces errors : undefined reference to ' < > ' . Also please let me know how to specify the gsl. Thank you Sincerely
    – kedarb
    Jul 2, 2019 at 15:18
  • 1
    for next time instead of showing a screenshot its better to just paste into a question text from the terminal by doing ... highlight all the lines ... ctrl + shift + c ... to copy then paste into an editor where you can shift all text to right by 4 spaces then paste result into your question ... above comment is saying you should use ... gcc -Wall -I/usr/local/include $( pkg-config --libs gsl ) sample_matrix.c Jul 2, 2019 at 15:31
  • 1
    @ScottStensland Got it, I realise I must always ask a clear question. I will follow this from now onwards. Thank you Sincerely
    – kedarb
    Jul 2, 2019 at 18:43

1 Answer 1

1

The -c switch tells gcc to compile source code to binary object code, but not link it to create an executable program: you will first need to remove that:

gcc -Wall -I/usr/local/include sample_matrix.c

You will then likely find there are lots of undefined reference to ... errors, because you haven't specified the relevant libraries to link on the command line. (Header files only declare things; libraries define them). If you have installed gsl in a standard location like /usr/local, then it should have placed a .pc file in /usr/local/lib/pkgconfig/ that will allow you to automate the specification of libraries using pkg-config ex.

gcc -Wall -I/usr/local/include sample_matrix.c `pkg-config --libs gsl`

(note the order of arguments: references are resolved from left to right). You can probably use pkg-config to locate the header files as well i.e.

gcc -Wall sample_matrix.c `pkg-config --cflags --libs gsl`
1
  • appreciated for explaining the logic behind these commands. Thank you for providing support here, Sincerely
    – kedarb
    Jul 3, 2019 at 6:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .