I have a very simple piece of C++ code justread.cc reading numbers from a file. After the command
ludi@ludi-M17xR4:~/Desktop/tests$ g++ -Wall -pedantic -o justread.x justread.cc && ./justread.x
it compiles without any errors or warnings. This is the code:
#include <fstream>
#include <vector>
int read_covariance ()
{
std::vector<double> data;
double tmp;
std::ifstream fin("peano_covariance.data");
while(fin >> tmp)
{
data.push_back(tmp);
}
return 0;
}
int main()
{
read_covariance();
return 0;
}
I wish to use this within an other working code called sylapack.cc. I can not post sylapack.cc due to copyright reasons, but it is taken from the documentation here
without any modifications except removing the spurious lines
< Table Of Contents Intel® Math Kernel Library LAPACK Examples
at the top of the webpage.
I can compile sylapack.cc as C code without errors or warnings:
ludi@ludi-M17xR4:~/Desktop/tests$ gcc -Ddsyev=dsyev_ -o sylapack sylapack.c -L/usr/local/lib -llapack -lblas && ./sylapack
DSYEV Example Program Results
Eigenvalues
-11.07 -6.23 0.86 8.87 16.09
Eigenvectors (stored columnwise)
-0.30 -0.61 0.40 -0.37 0.49
-0.51 -0.29 -0.41 -0.36 -0.61
-0.08 -0.38 -0.66 0.50 0.40
-0.00 -0.45 0.46 0.62 -0.46
-0.80 0.45 0.17 0.31 0.16
ludi@ludi-M17xR4:~/Desktop/tests$
I wish to integrate the C++ function read_covariance into sylapack.cc. To that end I have to compile sylapack.cc with g++. This gives me errors.
ludi@ludi-M17xR4:~/Desktop/tests$ g++ -Ddsyev=dsyev_ -o sylapack sylapack.c -L/usr/local/lib -llapack -lblas && ./sylapack
sylapack.c: In function ‘int main()’:
sylapack.c:89:74: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
dsyev( "Vectors", "Upper", &n, a, &lda, w, &wkopt, &lwork, &info );
^
sylapack.c:89:74: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
sylapack.c:93:72: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
dsyev( "Vectors", "Upper", &n, a, &lda, w, work, &lwork, &info );
^
sylapack.c:93:72: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
sylapack.c:100:49: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
print_matrix( "Eigenvalues", 1, n, w, 1 );
^
sylapack.c:102:72: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
print_matrix( "Eigenvectors (stored columnwise)", n, n, a, lda );
^
/tmp/ccz2hTYK.o: In function `main':
sylapack.c:(.text+0xa3): undefined reference to `dsyev_(char*, char*, int*, double*, int*, double*, double*, int*, int*)'
sylapack.c:(.text+0x12a): undefined reference to `dsyev_(char*, char*, int*, double*, int*, double*, double*, int*, int*)'
collect2: error: ld returned 1 exit status
ludi@ludi-M17xR4:~/Desktop/tests$