# Need help using GNU scientific library

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:

SixNein
Gold Member
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).

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: 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.

I like Serena
Homework Helper
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:
$gcc -Wall -I/usr/local/include GLS-mc-demo.c -L/usr/local/lib -lgsl$ ./a.out

AlephZero
Homework Helper
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. Try it without the -c flag. That flag means "compile-only", but your program also needs to be "linked". 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! SixNein Gold Member 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.

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:
I like Serena
Homework Helper
you have a permission issue with your file system.

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.

SixNein
Gold Member
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.

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.

I like Serena
Homework Helper
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.

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

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

[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: #include <stdio.h> int main() { printf("Watch me run\n"); return 0; } This was compiled an ran in my home directory. I like Serena Homework Helper 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.) SixNein Gold Member may want to check permissions on the a.out ls -al 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: chmod 755 a.out 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. I like Serena Homework Helper you can set permissions with:$ chmod 755 a.out

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

SixNein
Gold Member
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.)

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

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

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.

I like Serena
Homework Helper
Ahhh he didn't copy and paste the line I wrote.

No he didn't.