Library problem - not compiling in c


 
Thread Tools Search this Thread
Top Forums Programming Library problem - not compiling in c
# 1  
Old 06-16-2012
Library problem - not compiling in c

Ok I was trying to test if I installed correctly gsl, I followed the INSTALL file and still I don't know what is wrong. Here is a sample code to test gel,I got it from Random Number Generator Examples - GNU Scientific Library -- Reference Manual
(note: made a few changes in the code)


Code:
#include <stdlib.h>
#include <stdio.h>
#include <complex.h>
#include <math.h>
#include <stdio.h>
#include <gsl/gsl_rng.h>

int main (void)
{
  const gsl_rng_type * T;
  gsl_rng * r;
     
  int i, n = 10;
     
  gsl_rng_env_setup();
     
  T = gsl_rng_default;
  r = gsl_rng_alloc (T);
     
  for (i = 0; i < n; i++) 
    {
      double u = gsl_rng_uniform (r);
      printf ("%.5f\n", u);
    }
     
  gsl_rng_free (r);
     
  return 0;
}

This is how I compile:
Code:
gcc -O3 random.c -lm -I/sw/include -L/sw/lib -lgsl -lgslcblas -o random.exe

This is the message I get after:
Code:
ld: warning: directory not found for option '-L/sw/lib'
Undefined symbols for architecture x86_64:
  "_gsl_rng_env_setup", referenced from:
      _main in cc2FDGJF.o
  "_gsl_rng_default", referenced from:
      _main in cc2FDGJF.o
  "_gsl_rng_alloc", referenced from:
      _main in cc2FDGJF.o
  "_gsl_rng_uniform", referenced from:
      _main in cc2FDGJF.o
  "_gsl_rng_free", referenced from:
      _main in cc2FDGJF.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

any ideas?

Thank you.

Last edited by joseamck; 06-16-2012 at 08:47 PM..
# 2  
Old 06-17-2012
Do the /sw/lib and /sw/include dirs exist on the system and post the output of the following...
Code:
ls -latr /sw/lib /sw/include

This User Gave Thanks to shamrock For This Post:
# 3  
Old 06-17-2012
This is the output

Code:
ls: /sw/include: No such file or directory
ls: /sw/lib: No such file or directory

Then I didn't install gsl correctly?

I think this is not the right place where gsl is. mmmm I don't understand how to compile and use the correct folder where gsl is at.

this is where my gsl is
Code:
/opt/local/include/gsl



Now I tried this
Code:
gcc -O3 random.c -lm -I/opt/local/include -L/opt/local/lib -lgsl -lgslcblas -o random.exe

and this worked, just needed to verify the location of gsl an include it on the compilation line. Thank you.

Last edited by joseamck; 06-17-2012 at 12:26 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compiling GCC 6.3.0 - Error with Library

First of all -- thanks for being patient with me. I hope I'm submitting this correctly. Also I haven't done UNIX Admin since the early 1990's. I'm actually a DBA. But, since I'm the one in the office with the UNIX experience, I'm the SA. I haven't been able to compile GCC 6.3.0 which I need... (9 Replies)
Discussion started by: PJ_Namias
9 Replies

2. Programming

Trouble compiling program using the readline library.

Hi: in the info page for readline library I read -- Function: void rl_variable_dumper (int readable) Print the readline variable names and their current values to `rl_outstream'. If READABLE is non-zero, the list is formatted in such a way that it can be made part of an... (1 Reply)
Discussion started by: stf92
1 Replies

3. Linux

./configure problem for libsf library due to apparently missing libdb library.

Hello, ./configure script fails to configure libsf. Please check the following last few lines of configure script error. checking for db1/db.h... no checking for db.h... yes checking for dbopen in -ldb1... no configure: error: No libdb? No libsf. But find command shows the following; ... (4 Replies)
Discussion started by: vectrum
4 Replies

4. UNIX for Dummies Questions & Answers

Compiling samba problem

People i download the lastest version of samba i`am tryng to compile it in a solaris 9 i'm reading the how to of samba, i am in the first step making the autogen.sh but show me this when i do ./autogen.sh ./autogen.sh: running script/mkversion.sh ./script/mkversion.sh: 'include/version.h'... (0 Replies)
Discussion started by: enkei17
0 Replies

5. Linux

Compiling with multiple versions of a library

Hello! I have a set of headers and libraries I want to use but they are mixed with ones I do not want to use. They are part of some official stuff, so I cannot modify them while begging and pleading for weeks. These headers and libraries are located here /long/official/path/to/include... (0 Replies)
Discussion started by: gobi
0 Replies

6. HP-UX

Problem in HP-UX compiling

Hi When im trying to do make --version and make --help in HP-UX it throws error Make: Unknown flag argument -. Stop. a soft link is present in this directory /usr/bin/make and hard link is in /usr/ccs/bin/make what could be the reason can any1 ..please tell me how to solve this... (1 Reply)
Discussion started by: vasanthan
1 Replies

7. Programming

Problem compiling program

hi i am having a problem that when ever i use cc program_name.c to compile a program. an error occurs, showing cc not found. please help. (28 Replies)
Discussion started by: rochitsharma
28 Replies

8. Solaris

Compiling problem

I'm trying to install the jed text editor on a SunOS 5.10 box. It depends on the s-lang library, which I installed to ~/lib. I'm trying to install jed to ~/jed (it's a box @ my university, so I don't have rights to install globally), but when I run make I get this error: It looks like it... (1 Reply)
Discussion started by: iandunn
1 Replies

9. Programming

Problem compiling metamail

Hi Guys. I have downloaded metamail from internet e Iīm trying to compile it at a SCO 5.0.5. In this server itīs working fine (letīs name it as mission1) iīm using the developer package in this server (mission1) and when I use mailto, i got the e-mail fine. Itīs forwarding to a exchange server... (2 Replies)
Discussion started by: ahnishimi
2 Replies
Login or Register to Ask a Question