943,083 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1498
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 3rd, 2010
0

Sparselib++ library in C++ - compile error

Expand Post »
Hi,

I am using Sparselib++ in this C++ program.

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include "comprow_double.h"
  4. using namespace std;
  5.  
  6. int main() {
  7. cout << "Sparse example" << endl; // prints Sparse example
  8.  
  9. double val[12]={1,2,3,4,5,6,7,8,9,10,11,12};
  10. int colind[12]={0,1,4,0,1,2,1,2,4,3,0,4};
  11. int rowptr[6]={0,3,6,9,10,12};
  12.  
  13. CompRow_Mat_double R (5,5,12,val,rowptr,colind);
  14. return 0;
  15. }

Since I use Eclipse, I have added the -D preprocessor statement in the Project->Properties->C/C=++ Build->Settings->Preprocessor. The -D statement added here is
C++ Syntax (Toggle Plain Text)
  1. COMPLEX=std::complex<double>
which was given in the Sparselib++ makefile.def as
C++ Syntax (Toggle Plain Text)
  1. # g++ v. 2.7.0
  2. #
  3. CCC = g++
  4. CC = gcc
  5. CCCFLAGS = -DMV_VECTOR_BOUNDS_CHECK -g -Wall -pedantic\
  6. '-DCOMPLEX=std::complex<double>'
  7. CCCFLAGS = -g -Wall -pedantic -O3 '-DCOMPLEX=std::complex<double>'
  8. LDFLAGS = $(SPARSELIB_DIR)/lib/libsparse.a $(SPARSELIB_DIR)/lib/libspblas.a \
  9. $(SPARSELIB_DIR)/lib/libmv.a -lm

Now the build error I get is as follows saying " /bin/sh: double: No such file or directory'"

C++ Syntax (Toggle Plain Text)
  1. make -k all
  2. Building file: ../src/sparseCpp.cpp
  3. /bin/sh: double: No such file or directory
  4. Invoking: GCC C++ Compiler
  5. g++ -DCOMPLEX=std::complex<double> -I/home/s/Download/SparseLib++/1.7/include -I/home/s/Download/SparseLib++/1.7/src -I/home/s/Download/SparseLib++/1.7/mv/include -I/home/s/Download/SparseLib++/1.7/mv/src -O0 -g3 -p -Wall -c -fmessage-length=0 -v -MMD -MP -MF"src/sparseCpp.d" -MT"src/sparseCpp.d" -o"src/sparseCpp.o" "../src/sparseCpp.cpp"
  6. make: *** [src/sparseCpp.o] Error 1
  7. make: Target `all' not remade because of errors.
  8.  
There could be something I need to set up in Eclipse before compiling. I also checked using the 'which sh' command in Linux and get '/bin/sh' although I am not quite sure what is missing. Please help.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
Sandhya212 is offline Offline
27 posts
since Jul 2009
Jun 3rd, 2010
0
Re: Sparselib++ library in C++ - compile error
I am using KDevelop and I got the same error (/bin/sh: double: No such file or directory). I added this to the top of your code instead:

C++ Syntax (Toggle Plain Text)
  1. #define COMPLEX std::complex<double>

And it compiled and ran fine. It must be something wrong that we are doing with the -D syntax.

Good luck,

Dave
Featured Poster
Reputation Points: 437
Solved Threads: 204
Posting Virtuoso
daviddoria is offline Offline
1,968 posts
since Feb 2008
Jun 3rd, 2010
2
Re: Sparselib++ library in C++ - compile error
As always with programs when you have a problem with your command line arguments put them in quotes

-D"COMPLEX=std::complex<double>"

I imagine that the command line interpreter is < as the input piping operator.
Last edited by Banfa; Jun 3rd, 2010 at 4:20 pm.
Reputation Points: 445
Solved Threads: 72
Posting Pro
Banfa is offline Offline
506 posts
since Mar 2010
Jun 4th, 2010
0
Re: Sparselib++ library in C++ - compile error
Hi,

I have done as per your suggestions.
In both cases, I get the following error.
C++ Syntax (Toggle Plain Text)
  1. **** Build of configuration Debug for project sparseCpp ****
  2.  
  3. make -k all
  4. Building file: ../src/sparseCpp.cpp
  5. Invoking: GCC C++ Compiler
  6. g++ -D'COMPLEX std::complex<double>' -I/home/s/Download/SparseLib++/1.7/include -I/home/s/Download/SparseLib++/1.7/src -I/home/s/Download/SparseLib++/1.7/mv/include -I/home/s/Download/SparseLib++/1.7/mv/src -O0 -g3 -p -Wall -c -fmessage-length=0 -MMD -MP -MF"src/sparseCpp.d" -MT"src/sparseCpp.d" -o"src/sparseCpp.o" "../src/sparseCpp.cpp"
  7. In file included from /home/s/Download/SparseLib++/1.7/mv/include/mvv.h:45,
  8. from /home/s/Download/SparseLib++/1.7/include/icpre_double.h:36,
  9. from ../src/sparseCpp.cpp:16:
  10. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:56: error: expected unqualified-id before numeric constant
  11. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:68: error: expected ',' or '...' before numeric constant
  12. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:71: error: expected ',' or '...' before numeric constant
  13. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:72: error: expected ',' or '...' before numeric constant
  14. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:72: error: 'MV_Vector_COMPLEX::MV_Vector_COMPLEX(std::complex<double>)' cannot be overloaded
  15. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:71: error: with 'MV_Vector_COMPLEX::MV_Vector_COMPLEX(std::complex<double>)'
  16. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:82: error: expected ',' or '...' before numeric constant
  17. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:82: error: 'MV_Vector_COMPLEX::MV_Vector_COMPLEX(std::complex<double>)' cannot be overloaded
  18. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:71: error: with 'MV_Vector_COMPLEX::MV_Vector_COMPLEX(std::complex<double>)'
  19. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:95: error: expected unqualified-id before numeric constant
  20. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:102: error: expected unqualified-id before numeric constant
  21. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:110: error: expected unqualified-id before numeric constant
  22. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:117: error: expected unqualified-id before numeric constant
  23. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:144: error: expected ',' or '...' before numeric constant
  24. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h: In constructor 'MV_Vector_COMPLEX::MV_Vector_COMPLEX(std::complex<double>)':
  25. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:83: error: class 'MV_Vector_COMPLEX' does not have any field named 'p_'
  26. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:83: error: 'd' was not declared in this scope
  27. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:83: error: 'N' was not declared in this scope
  28. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:83: error: 'i' was not declared in this scope
  29. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h: In constructor 'MV_Vector_COMPLEX::MV_Vector_COMPLEX(const MV_Vector_COMPLEX&, MV_Vector_::ref_type)':
  30. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:86: error: class 'MV_Vector_COMPLEX' does not have any field named 'p_'
  31. /home/s/Download/SparseLib++/1.7/mv/include/mvvc.h:86: error: 'const class MV_Vector_COMPLEX' has no member named 'p_'
  32. In file included from /home/s/Download/SparseLib++/1.7/mv/include/mvv.h:46,
  33. from /home/s/Download/SparseLib++/1.7/include/icpre_double.h:36,
  34. from ../src/sparseCpp.cpp:16:
  35. /home/s/Download/SparseLib++/1.7/mv/include/mvblasc.h: At global scope:
  36. /home/s/Download/SparseLib++/1.7/mv/include/mvblasc.h:29: error: expected ',' or '...' before numeric constant
  37. /home/s/Download/SparseLib++/1.7/mv/include/mvblasc.h:30: error: expected ',' or '...' before numeric constant
  38. /home/s/Download/SparseLib++/1.7/mv/include/mvblasc.h:31: error: expected ',' or '...' before numeric constant
  39. /home/s/Download/SparseLib++/1.7/mv/include/mvblasc.h:39: error: expected unqualified-id before numeric constant
  40. /home/s/Download/SparseLib++/1.7/mv/include/mvblasc.h:40: error: expected unqualified-id before numeric constant
  41. make: *** [src/sparseCpp.o] Error 1
  42. make: Target `all' not remade because of errors.
  43.  

Both mvvc.h and mvblasc.h are meant for the COMPLEX data type. I do not understand why these errors are thrown. Please help.
Reputation Points: 10
Solved Threads: 1
Light Poster
Sandhya212 is offline Offline
27 posts
since Jul 2009
Jun 4th, 2010
0
Re: Sparselib++ library in C++ - compile error
I just placed
C++ Syntax (Toggle Plain Text)
  1. #define COMPLEX std::complex<double>
as the very first line in the code and now I get these errors.
C++ Syntax (Toggle Plain Text)
  1. make -k all
  2. Building file: ../src/sparseCpp.cpp
  3. Invoking: GCC C++ Compiler
  4. g++ -I/home/s/Download/SparseLib++/1.7/include -I/home/s/Download/SparseLib++/1.7/src -I/home/s/Download/SparseLib++/1.7/mv/include -I/home/s/Download/SparseLib++/1.7/mv/src -O0 -g3 -p -Wall -c -fmessage-length=0 -MMD -MP -MF"src/sparseCpp.d" -MT"src/sparseCpp.d" -o"src/sparseCpp.o" "../src/sparseCpp.cpp"
  5. Finished building: ../src/sparseCpp.cpp
  6.  
  7. Building target: sparseCpp
  8. Invoking: GCC C++ Linker
  9. g++ -o"sparseCpp" ./src/sparseCpp.o
  10. ./src/sparseCpp.o: In function `main':
  11. /home/s/workspace/sparseCpp/Debug/../src/sparseCpp.cpp:46: undefined reference to `Coord_Mat_double::Coord_Mat_double(int, int, int, double*, int*, int*, int)'
  12. ./src/sparseCpp.o: In function `~Coord_Mat_double':
  13. /home/s/Download/SparseLib++/1.7/include/coord_double.h:66: undefined reference to `MV_Vector_int::~MV_Vector_int()'
  14. /home/s/Download/SparseLib++/1.7/include/coord_double.h:66: undefined reference to `MV_Vector_int::~MV_Vector_int()'
  15. /home/s/Download/SparseLib++/1.7/include/coord_double.h:66: undefined reference to `MV_Vector_int::~MV_Vector_int()'
  16. /home/s/Download/SparseLib++/1.7/include/coord_double.h:66: undefined reference to `MV_Vector_double::~MV_Vector_double()'
  17. /home/s/Download/SparseLib++/1.7/include/coord_double.h:66: undefined reference to `MV_Vector_double::~MV_Vector_double()'
  18. collect2: ld returned 1 exit status
  19. make: *** [sparseCpp] Error 1

What is the difference in the placement of this COMPLEX preprocessor directive between this
C++ Syntax (Toggle Plain Text)
  1. #define COMPLEX std::complex<double>
  2.  
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include "icpre_double.h"
  6. #include "coord_double.h"
  7. #include "comprow_double.h"
  8.  
  9. using namespace std;
and this ?
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include "icpre_double.h"
  4. #include "coord_double.h"
  5. #include "comprow_double.h"
  6.  
  7. #define COMPLEX std::complex<double>
  8.  
  9. using namespace std;
. The latter was the one that gave me all the errors in my previous post.
Reputation Points: 10
Solved Threads: 1
Light Poster
Sandhya212 is offline Offline
27 posts
since Jul 2009
Jun 4th, 2010
0
Re: Sparselib++ library in C++ - compile error
If those headers contain a definition or use of the symbol COMPLEX by placing it before you include the headers you change the headers and by placing it after them you don't.

BTW compiler/linker errors without the lines of code the correspond to are nearly (not quite but nearly) useless.

In the last listing it looks like you are missing a library or object file when you are linking.
Reputation Points: 445
Solved Threads: 72
Posting Pro
Banfa is offline Offline
506 posts
since Mar 2010
Jun 4th, 2010
0
Re: Sparselib++ library in C++ - compile error
Yes you are right. I get that explanation now.

I have not changed the code since the initial post here but will repeat it once again for clarity.
C++ Syntax (Toggle Plain Text)
  1. #define COMPLEX std::complex<double>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include "comprow_double.h"
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. cout << "Sparse example" << endl; // prints Sparse example
  10.  
  11. double val[12]={1,2,3,4,5,6,7,8,9,10,11,12};
  12. int colind[12]={0,1,4,0,1,2,1,2,4,3,0,4};
  13. int rowptr[6]={0,3,6,9,10,12};
  14.  
  15. Coord_Mat_double R(5,5,12,val,rowptr,colind); //----> here is where the error is signalled
  16.  
  17. return 0;
  18. }
I have checked line 66 in coord_double.h. It is the destructor. I am pasting those lines too here.
C++ Syntax (Toggle Plain Text)
  1. #ifndef Coord_Mat_double_H
  2. #define Coord_Mat_double_H
  3.  
  4. #include "vecdefs.h"
  5. #include VECTOR_H
  6.  
  7. class CompCol_Mat_double;
  8. class CompRow_Mat_double;
  9.  
  10. class Coord_Mat_double {
  11.  
  12. private:
  13. VECTOR_double val_; // data values (nz_ elements)
  14. VECTOR_int rowind_; // row_ind (nz_ elements)
  15. VECTOR_int colind_; // col_ind (nz_ elements)
  16.  
  17. int base_; // index base: not used....
  18. int nz_; // number of nonzeros
  19. int dim_[2]; // number of rows, cols
  20.  
  21. public:
  22. Coord_Mat_double(void);
  23. Coord_Mat_double(const Coord_Mat_double &S);
  24. Coord_Mat_double(int M, int N, int nz, double *val, int *r,
  25. int *c, int base=0);
  26. Coord_Mat_double(const CompCol_Mat_double &C);
  27. Coord_Mat_double(const CompRow_Mat_double &R);
  28. ~Coord_Mat_double() {};
  29.  
  30. /*******************************/
  31. /* Access and info functions */
  32. /*******************************/
  33. ...........
  34. ............

I also searched the header files for where MV_Vector_double is defined. It is present in mvv.h. Must I look if the other headers also make use of this one? This is a widely-used library so I am doubtful if there is any mistake in the library but with what or how I am using it.
Reputation Points: 10
Solved Threads: 1
Light Poster
Sandhya212 is offline Offline
27 posts
since Jul 2009
Jun 4th, 2010
0
Re: Sparselib++ library in C++ - compile error
Sorry I was getting a little confused.

So you have the undefined reference errors?

I downloaded SparseLib and examined a couple of them

coord_double.h:66: undefined reference to `MV_Vector_int::~MV_Vector_int()'
coord_double.h:66: undefined reference to `MV_Vector_double::~MV_Vector_double()'

Those functions, the destructors on those classes, do not exist. They are defined in the right place but while all the other methods of those classes are also declared in the headers those ones aren't.

I think you are probably going to have to go through and edit the files to implement the missing functions to get this to link.

Either that or find a place that provides specific help on this library.
Reputation Points: 445
Solved Threads: 72
Posting Pro
Banfa is offline Offline
506 posts
since Mar 2010
Jun 4th, 2010
0
Re: Sparselib++ library in C++ - compile error
Is your project set up to link to all 3 libraries that build with sparselib?
Featured Poster
Reputation Points: 437
Solved Threads: 204
Posting Virtuoso
daviddoria is offline Offline
1,968 posts
since Feb 2008
Jun 4th, 2010
0
Re: Sparselib++ library in C++ - compile error
Thank you so much for downloading Sparselib and having a look. I did not understand what you meant by
Quote ...
'Those functions, the destructors on those classes, do not exist. They are defined in the right place but while all the other methods of those classes are also declared in the headers those ones aren't.'
. Are not these mentioned in mvvd.h and mvvi.h? I see the destructor there or what is it that is wrong? I added
C++ Syntax (Toggle Plain Text)
  1. #include "mvv.h"
in the program but I still get the same error.

To daviddoria's question - Please let me know what the 3 libraries are you were mentioning? I have downloaded Sparselib++ from here http://math.nist.gov/sparselib/. Apart from this I did not downloaded anything else. They also mention that MV++ is shipped along with this so I did not download that. All the code for MV++ is present in Sparselib++.

Thank you indeed for looking into this problem. I am quite new to C++ and Eclipse and therefore when an error occurs I do not know if it is due to Eclipse or C++. Any and every help is valid.
Reputation Points: 10
Solved Threads: 1
Light Poster
Sandhya212 is offline Offline
27 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How to generate an 'Out of Memory' exception
Next Thread in C++ Forum Timeline: Borland's function StrToDateTime fails





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC