GSL Vectors

Hello-- I am trying to use the GSL library in C++, and am having an issue with GSL vectors. As header files for other things that I'm using GSL for, I'm including--

# include <C:\cygwin64\usr\include\gsl\gsl_sf_gamma.h>
# include <C:\cygwin64\usr\include\gsl\gsl_sf_expint.h>

The functions that I'm using (like gsl_sf_gamma_inc for example) are working fine, so I seem to be setting up the header files correctly and getting the paths right.

When I try to use gsl vectors, though, I am including--

# include <C:\cygwin64\usr\include\gsl\gsl_vector.h>

When I compile the program, Cygwin appears to be recognizing it as a valid header file, but when I try to start using gsl_vectors in my code, for example--

gsl_vector *v = gsl_vector_alloc(3);

Visual studio is giving me--

Error: identifier "gsl_vector" is undefined

and

Error: identifier "gsl_vector_alloc" is undefined

How can I get this to work?

Thank you!
jt9812Asked:
Who is Participating?
 
jt9812Author Commented:
OK, well I deleted Cygwin, reinstalled, took the path names out of the header files, used the "-I" to include them from the command line (didn't even know you could do that-- pretty new with this), and all of a sudden the gsl_vectors started working... in Visual Studio, though, for some reason there are red squiggly lines showing up under gsl_vector, gsl_vector_alloc, gsl_vector_set, gsl_vector_get, and gsl_vector_free (almost as if they're misspelled words in MS Word and it's telling me that they're "spelled wrong"), even though functionally they're working fine... any idea why this would be?

Also, once I took the path names out of the header files, there are red squiggly lines under the "# include"s now too for each one...
0
 
jkrCommented:
Well, where to start? Well, maybe here:

>> so I seem to be setting up the header files correctly and getting the paths right.

Sorry, but to be blunt - a line like

# include <C:\cygwin64\usr\include\gsl\gsl_vector.h>

Open in new window


is gut-wrenching at best. Not only because one of the first 'best-practices' tip that you will get is 'never use an absolute path to include header files', but mainly because it is quite likely that you will run in trouble with gcc/g++ not correctly resolving the location because of a) the drive letter and b) the backslashes. You should use

#include <gsl_vector.h>

Open in new window


and compile your code providing the include path like

g++ -o sample -I/usr/include/gsl -lgsl -L/usr/lib/gsl sample.cpp 

Open in new window


Or, even simpler

#include <gsl/gsl_vector.h>

Open in new window


if you have '/usr/include' in your INCLUDE environment variable

'/usr/lib/gsl'is the path where the libraries should reside, please check it it's the correct one for your system/setup.

BTW, just in case you need them, you'll find examples at http://www.gnu.org/software/gsl/manual/html_node/Example-programs-for-vectors.html
0
 
sarabandeCommented:
I think you were using the c++ and not the c version of gsl vectors.

then the gsl is not  a prefix but a namespace and was used like

gsl::vector * v = gsl::vector_alloc(3);


see http://gslwrap.sourceforge.net/classgsl_1_1vector.html for a complete reference of the class.

Sara
0
 
sarabandeCommented:
for some reason there are red squiggly lines showing up under gsl_vector
visual studio editor makes a syntax check while you were editing by a tool that is called 'intellisense'. while this feature is nearly as clever as a precompiler + compiler, it is sometimes not able to resolve ambiguous definitions given by header files, especially when those headers exert excessive use of conditional macros what is often the case with portable sources of third party libraries.

you may ignore the red underlines as long as the compiler is happy with the code. sometimes "intellisense" is able to "learn" from a successful compilation but not for all cases.  

Sara
0
 
jt9812Author Commented:
It worked...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.