# Need help using GNU scientific library

1. Aug 11, 2011

### quasar_4

Hi,

I'm stumped trying to learn how to use the GNU scientific library.

I installed X11, Xcode and gsl library using MacPorts on my computer which is running Mac OSX 10.6.8. I've used Xcode plenty in the past year for generic (simple) c programs and it's worked fine, so I think all the installs worked.

All I am trying to do at the moment is run the first sample in the GNU scientific library manual (also located at http://www.gnu.org/software/gsl/manual/html_node/An-Example-Program.html): [Broken]

#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>

int
main (void)
{
double x = 5.0;
double y = gsl_sf_bessel_J0 (x);
printf ("J0(%g) = %.18e\n", x, y);
return 0;
}

I saved this snippet as GSL-demo.c on my computer and in my terminal window I type:
$gcc -Wall -I/usr/local/include -c GLS-mc-demo.c which seems to compile fine. When I try to run it,$ ./a.out

I get:

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

How do I actually run the code? And what does -c mean? (I'm totally new to unix too, for the most part).

Last edited by a moderator: May 5, 2017
2. Aug 12, 2011

Try
$gcc -Wall -I/usr/local/include -o a.out GLS-mc-demo.c then try to run a.out -c means compile Last edited by a moderator: May 5, 2017 3. Aug 12, 2011 ### quasar_4 It still doesn't run. I get:$ gcc -Wall -I/usr/local/include -o a.out -c GLS-mc-demo.c
$./a.out -bash: ./a.out: Permission denied$

I tried putting -c before -o as well and got the same result.

4. Aug 12, 2011

### I like Serena

Try it without the -c flag.
That flag means "compile-only", but your program also needs to be "linked".
Btw, no doubt you will also have to link against the gsl-library.

This means you need to do something like:
Code (Text):
$gcc -Wall -I/usr/local/include GLS-mc-demo.c -L/usr/local/lib -lgsl$ ./a.out

5. Aug 12, 2011

### AlephZero

Yep, if you specify both -o and -c, you are just renaming the "object code" demo.o file as a.out.

It's hard to think of any "simple" situation where doing that would be useful. The only "complicated" situation I can think of iis if you had source files in different languages with similar names (for example demo.c and demo.f), and obviously you can't have two different files both called demo.o in the same directory. But it would be better to fix that problem by remanimg the files, or changing the directory structure for the project!

6. Aug 12, 2011

### SixNein

You have a permission issue with your file system. Check the directory to make sure you have right to execute. And don't use -c.

You could try
$gcc -Wall -I/usr/local/include -o /home/YOURUSERNAME/a.out GLS-mc-demo.c$ /home/YOURUSERNAME/a.out

May be selinux causing the issue for the permission denied by setting ownership to that of the directory. Make sure you change the YOURUSERNAME to whatever username your using.

Last edited: Aug 12, 2011
7. Aug 12, 2011

### I like Serena

Nope. That won't be it.
Obviously a.out could be written, otherwise gcc would have complained.
gcc itself sets the proper executable bits on a.out, so it will run.
However, what should be an object file, is written to the file a.out, but that cannot be executed, hence the permission error.
This was already remarked upon by AlephZero.

8. Aug 12, 2011

### SixNein

Permission denied is a result of the file system, and it has nothing to do with GCC. Most likely, SElinux is setting the group to that of the directory.

9. Aug 13, 2011

### I like Serena

Please try the command lines used yourself.
You'll see that you will get the same permission denied error.

10. Aug 13, 2011

### SixNein

[Maven@localhost ~]$gcc -Wall -I/usr/local/include -o test test.c [Maven@localhost ~]$ ./test
Watch me run
[Maven@localhost ~]$gcc -Wall -I/usr/local/include -o a.out test.c [Maven@localhost ~]$ ./a.out
Watch me run
[Maven@localhost ~]$source: This was compiled an ran in my home directory. 11. Aug 13, 2011 ### I like Serena Now try it with: [Maven@localhost ~]$ gcc -Wall -I/usr/local/include -o a.out -c test.c
[Maven@localhost ~]\$ ./a.out

Note the extra "-c".
(That is what quasar_4 did.)

12. Aug 13, 2011

### SixNein

may want to check permissions on the a.out

You should see something like this:

-rwxrwxr-x. 1 Maven Maven 4642 Aug 13 06:14 a.out

if you don't see an x, you can't execute the program.

you can set permissions with:

If you are compiling the program on removable storage, external hard drive, etc, you may need to remount the drive with the exec option included.

13. Aug 13, 2011

### I like Serena

If he does that, he'll get:
bash: ./a.out: cannot execute binary file

14. Aug 13, 2011

### SixNein

Ahhh he didn't copy and paste the line I wrote.

15. Aug 13, 2011

### SixNein

There are some issues that can come up with permissions and especially on mounted drives with exec off. I figured it was something like that. I assumed he tried the line I gave him, but I guess not.

16. Aug 13, 2011

### I like Serena

No he didn't.