error: conflicts with new declaration with =?UTF-8?B?4oCYQ+KAmSBs?==?UTF-8?B?aW5rYWdl?=

H

H.S.

Hello,

This is a bit weird problem and I am not expert in C++. I am trying to
make a small program to use the Taucs library (it is a C library for
solving sparse linear system, http://www.tau.ac.il/~stoledo/taucs/, tgz
with external libs), but I keep getting this compiler error. The example
program I am trying is this:
--------------------------------------------------------------
#include <taucs.h>

#ifdef __cplusplus
extern "C" {
#endif
extern taucs_ccs_matrix * taucs_ccs_create (int m, int n, int nnz,
int flags);
extern void taucs_css_free (taucs_ccs_matrix* );
#ifdef __cplusplus
}
#endif // __cplusplus

int main(){
int C,R,k;
C=20;
R=20;
k=4;
taucs_ccs_matrix *taucAsigmaIMat;
taucAsigmaIMat = taucs_ccs_create(C, R, (k+1)*C,
TAUCS_DOUBLE|TAUCS_SYMMETRIC);

//cleanup
taucs_ccs_free(taucAsigmaIMat);
return 0;
}
-----------------------------------------------------------------

I downloaded the Taucs library in ~/tmp/taucs and compiled it. I am
using the following command to compile my example program above and I get:
$> g++ -Wall -I$HOME/tmp/taucs/build/linux -I$HOME/tmp/taucs/src
-L$HOME/tmp/taucs/lib/linux -ltaucs -L$HOME/tmp/taucs/external/lib/linux
-latlas -lcblas -lf77blas -llapack -lmetis
$HOME/tmp/taucs/external/lib/linux/blas_aux.o spmat.cc -o spmat
In file included from /usr/include/c++/4.1.3/backward/complex.h:31,
from /home/hs/tmp/taucs/src/taucs.h:132,
from spmat.cc:1:
/usr/include/c++/4.1.3/backward/backward_warning.h:32:2: warning:
#warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the <X>
header for the <X.h> header for C++ includes, or <iostream> instead of
the deprecated header <iostream.h>. To disable this warning use
-Wno-deprecated.
/home/hs/tmp/taucs/src/taucs_private.h:45: error: previous declaration
of ‘taucs_ccs_matrix* taucs_ccs_create(int, int, int, int)’ with ‘C++’
linkage
spmat.cc:6: error: conflicts with new declaration with ‘C’ linkage


The lines near taucs_private.h line 45 are (output from `less -N`):
-----------------------------------------------
36 taucs_datatype taucs_dtl(div_fn)(taucs_datatype a,
taucs_datatype b);
37 taucs_datatype taucs_dtl(neg_fn)(taucs_datatype a);
38 taucs_datatype taucs_dtl(sqrt_fn)(taucs_datatype a);
39 taucs_datatype taucs_dtl(conj_fn)(taucs_datatype a);
40 double taucs_dtl(abs_fn)(taucs_datatype a);
41
42 /*** taucs_ccs_base.c ***/
43
44 taucs_ccs_matrix* taucs_dtl(ccs_create) (int m, int n,
int nnz);
45 taucs_ccs_matrix* taucs_ccs_create (int m, int n,
int nnz, int flags);
46 void taucs_dtl(ccs_free)
(taucs_ccs_matrix* matrix);
47 void taucs_ccs_free
(taucs_ccs_matrix* matrix);
48
49 /*** taucs_ccs_ops.c ***/
50
51 void taucs_dtl(ccs_split)
(taucs_ccs_matrix* A,
52
taucs_ccs_matrix** L,
53
taucs_ccs_matrix** R,
54 int p);
----------------------------------------------------

Given the above compiler output, could somebody suggest what I am doing
wrong? Or point me in the direction to get this working.

thanks,
->HS
 
V

Victor Bazarov

H.S. said:
This is a bit weird problem and I am not expert in C++. I am trying to
make a small program to use the Taucs library (it is a C library for
solving sparse linear system, http://www.tau.ac.il/~stoledo/taucs/,
tgz with external libs), but I keep getting this compiler error. The
example program I am trying is this:
--------------------------------------------------------------
#include <taucs.h>

#ifdef __cplusplus
extern "C" {
#endif
extern taucs_ccs_matrix * taucs_ccs_create (int m, int n, int nnz,
int flags);
extern void taucs_css_free (taucs_ccs_matrix* );
#ifdef __cplusplus
}
#endif // __cplusplus

Try removing everything between this place and the #include (leave the
#include in).
int main(){
int C,R,k;
C=20;
R=20;
k=4;
taucs_ccs_matrix *taucAsigmaIMat;
taucAsigmaIMat = taucs_ccs_create(C, R, (k+1)*C,
TAUCS_DOUBLE|TAUCS_SYMMETRIC);

//cleanup
taucs_ccs_free(taucAsigmaIMat);
return 0;
}

V
 
H

H.S.

Victor said:
Try removing everything between this place and the #include (leave the
#include in).

Here is what my source now looks like:
#include <taucs.h>

int main(){
int C,R,k;
C=20;
R=20;
k=4;
taucs_ccs_matrix *taucAsigmaIMat;
taucAsigmaIMat = taucs_ccs_create(C, R, (k+1)*C,
TAUCS_DOUBLE|TAUCS_SYMMETRIC);

//cleanup
taucs_ccs_free(taucAsigmaIMat);
return 0;
}


When I compile this, I get the following "undefined reference to" error:

$> g++ -Wall -I$HOME/tmp/taucs/build/linux -I$HOME/tmp/taucs/src
-L$HOME/tmp/taucs/lib/linux -ltaucs -L$HOME/tmp/taucs/external/lib/linux
-latlas -lcblas -lf77blas -llapack -lmetis
$HOME/tmp/taucs/external/lib/linux/blas_aux.o spmat.cc -o spmat
In file included from /usr/include/c++/4.1.3/backward/complex.h:31,
from /home/hs/tmp/taucs/src/taucs.h:132,
from spmat.cc:1:
/usr/include/c++/4.1.3/backward/backward_warning.h:32:2: warning:
#warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the <X>
header for the <X.h> header for C++ includes, or <iostream> instead of
the deprecated header <iostream.h>. To disable this warning use
-Wno-deprecated.
/tmp/cct4bmtf.o: In function `main':
spmat.cc:(.text+0x4a): undefined reference to `taucs_ccs_create(int,
int, int, int)'
spmat.cc:(.text+0x58): undefined reference to
`taucs_ccs_free(taucs_ccs_matrix*)'
collect2: ld returned 1 exit status


thanks,
->HS
 
V

Victor Bazarov

H.S. said:
Here is what my source now looks like:
#include <taucs.h>

int main(){
int C,R,k;
C=20;
R=20;
k=4;
taucs_ccs_matrix *taucAsigmaIMat;
taucAsigmaIMat = taucs_ccs_create(C, R, (k+1)*C,
TAUCS_DOUBLE|TAUCS_SYMMETRIC);

//cleanup
taucs_ccs_free(taucAsigmaIMat);
return 0;
}


When I compile this, I get the following "undefined reference to"
error:

$> g++ -Wall -I$HOME/tmp/taucs/build/linux -I$HOME/tmp/taucs/src
-L$HOME/tmp/taucs/lib/linux -ltaucs
-L$HOME/tmp/taucs/external/lib/linux
-latlas -lcblas -lf77blas -llapack -lmetis
$HOME/tmp/taucs/external/lib/linux/blas_aux.o spmat.cc -o spmat
In file included from /usr/include/c++/4.1.3/backward/complex.h:31,
from /home/hs/tmp/taucs/src/taucs.h:132,
from spmat.cc:1:
/usr/include/c++/4.1.3/backward/backward_warning.h:32:2: warning:
#warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the <X>
header for the <X.h> header for C++ includes, or <iostream> instead of
the deprecated header <iostream.h>. To disable this warning use
-Wno-deprecated.
/tmp/cct4bmtf.o: In function `main':
spmat.cc:(.text+0x4a): undefined reference to `taucs_ccs_create(int,
int, int, int)'
spmat.cc:(.text+0x58): undefined reference to
`taucs_ccs_free(taucs_ccs_matrix*)'
collect2: ld returned 1 exit status

Linker errors indicate that the required library is either not in
the list or the order of libraries is incorrect. This is beyond the
scope of this _language_ newsgroup. Please consult your library
documentation.

Another guess: your header file is not designed to work with C++ code,
you might want to put exter "C" around it:

extern "C" {
#include <taucs.h>
}

....

V
 
H

H.S.

Victor said:
Linker errors indicate that the required library is either not in
the list or the order of libraries is incorrect. This is beyond the
scope of this _language_ newsgroup. Please consult your library
documentation.

Okay. I will look into this. Meanwhile ....
Another guess: your header file is not designed to work with C++ code,
you might want to put exter "C" around it:

extern "C" {
#include <taucs.h>
}

...

.... I already this yesterday. Here is a sample of huge number of errors
that I get:
..
..
..
/usr/include/c++/4.1.3/bits/stl_algobase.h:892: error: declaration of C
function ‘bool std::lexicographical_compare(const char*, const char*,
const char*, const char*)’ conflicts with
/usr/include/c++/4.1.3/bits/stl_algobase.h:878: error: previous
declaration ‘bool std::lexicographical_compare(const unsigned char*,
const unsigned char*, const unsigned char*, const unsigned char*)’ here
/usr/include/c++/4.1.3/bits/char_traits.h: At global scope:
/usr/include/c++/4.1.3/bits/char_traits.h:61: error: template with C linkage
/usr/include/c++/4.1.3/bits/char_traits.h:86: error: template with C linkage
..
..
..



Thanks,
->HS
 
V

Victor Bazarov

H.S. said:
Victor said:
Linker errors indicate that the required library is either not in
the list or the order of libraries is incorrect. This is beyond the
scope of this _language_ newsgroup. Please consult your library
documentation.

Okay. I will look into this. Meanwhile ....
[..]

You might want to start with it next time...
 
H

H.S.

Victor said:
H.S. said:
Victor said:
Linker errors indicate that the required library is either not in
the list or the order of libraries is incorrect. This is beyond the
scope of this _language_ newsgroup. Please consult your library
documentation.
Okay. I will look into this. Meanwhile ....
[..]

You might want to start with it next time...

I did. Gave you the benefit of doubt, assumed you knew better and looked
at it again. Didn't help much. The symbols exist in the library, the
library is in the path specified by -L. So, looks like this by itself is
not the problem.

Looks like the problem is not *strictly* related to the standard. So
before hyperactive "standard nazis" here pick up their handy ever
burning torches and regularly used pitchforks, I better go look for help
from some other beings with kinder souls (or any souls, for that matter)
;-) .... already tried s.m.num-analysis, without luck.

thanks for your previous insights though,
cheers,
->HS
 
I

Ian Collins

H.S. said:
#ifdef __cplusplus
extern "C" {
#endif
extern taucs_ccs_matrix * taucs_ccs_create (int m, int n, int nnz,
int flags);
extern void taucs_css_free (taucs_ccs_matrix* );
#ifdef __cplusplus
}
/home/hs/tmp/taucs/src/taucs_private.h:45: error: previous declaration
of ‘taucs_ccs_matrix* taucs_ccs_create(int, int, int, int)’ with ‘C++’
linkage
spmat.cc:6: error: conflicts with new declaration with ‘C’ linkage
You can't declare a function with C++ linkage and then redeclare it with
C linkage. What you have is the same as

void f();

extern "C" void f();
 
A

Alf P. Steinbach

* H.S.:
Okay. I will look into this. Meanwhile ....


... I already this yesterday. Here is a sample of huge number of errors
that I get:
.
.
.
/usr/include/c++/4.1.3/bits/stl_algobase.h:892: error: declaration of C
function ‘bool std::lexicographical_compare(const char*, const char*,
const char*, const char*)’ conflicts with
/usr/include/c++/4.1.3/bits/stl_algobase.h:878: error: previous
declaration ‘bool std::lexicographical_compare(const unsigned char*,
const unsigned char*, const unsigned char*, const unsigned char*)’ here
/usr/include/c++/4.1.3/bits/char_traits.h: At global scope:
/usr/include/c++/4.1.3/bits/char_traits.h:61: error: template with C linkage
/usr/include/c++/4.1.3/bits/char_traits.h:86: error: template with C linkage
.
.
.

This looks like you have extended the 'extern "C"' declaration too far,
encompassing not just <taucs.h> include, but also includes of C++ headers.

Another possibility could be that <taucs.h> is a C++ header.
 
V

Victor Bazarov

Ian said:
You can't declare a function with C++ linkage and then redeclare it
with C linkage. What you have is the same as

void f();

extern "C" void f();

That's why I suggested removing that extraneous code from 'H.S.'s
program. The response was that it didn't help. See the original
thread.

V
 
H

H.S.

Victor said:
Linker errors indicate that the required library is either not in
the list or the order of libraries is incorrect. This is beyond the

I have consulted a few other people about the above error. Turns out,
you are wrong on both counts.

If the linker couldn't find the library, it would not have known about
the arguments signature of the calling functions. I would have got:
$> make
g++ spmat.o -o spmat
spmat.o: In function `main':
/home/sahambi/tmp/spmat/spmat.cc:24: undefined reference to
`taucs_ccs_create'
/home/sahambi/tmp/spmat/spmat.cc:27: undefined reference to `taucs_ccs_free'
collect2: ld returned 1 exit status
make: *** [spmat] Error 1


scope of this _language_ newsgroup. Please consult your library
documentation.

Another guess: your header file is not designed to work with C++ code,
you might want to put exter "C" around it:

extern "C" {
#include <taucs.h>
}

That is a terrible idea again. From my newly gained experience, this is
a bad programming practice. The problem, actually, lies in the library
itself.

I will reply to my own original post to give the solution, for closure :)

Thanks for your help and comments,
->HS
 
H

H.S.

H.S. said:
Hello,

This is a bit weird problem and I am not expert in C++. I am trying to
make a small program to use the Taucs library (it is a C library for
solving sparse linear system, http://www.tau.ac.il/~stoledo/taucs/, tgz
with external libs), but I keep getting this compiler error. The example
program I am trying is this:
--------------------------------------------------------------
#include <taucs.h>

#ifdef __cplusplus
extern "C" {
#endif
extern taucs_ccs_matrix * taucs_ccs_create (int m, int n, int nnz,
int flags);
extern void taucs_css_free (taucs_ccs_matrix* );
#ifdef __cplusplus
}
#endif // __cplusplus

int main(){
int C,R,k;
C=20;
R=20;
k=4;
taucs_ccs_matrix *taucAsigmaIMat;
taucAsigmaIMat = taucs_ccs_create(C, R, (k+1)*C,
TAUCS_DOUBLE|TAUCS_SYMMETRIC);

//cleanup
taucs_ccs_free(taucAsigmaIMat);
return 0;
}
-----------------------------------------------------------------

I downloaded the Taucs library in ~/tmp/taucs and compiled it. I am
using the following command to compile my example program above and I get:
$> g++ -Wall -I$HOME/tmp/taucs/build/linux -I$HOME/tmp/taucs/src
-L$HOME/tmp/taucs/lib/linux -ltaucs -L$HOME/tmp/taucs/external/lib/linux
-latlas -lcblas -lf77blas -llapack -lmetis
$HOME/tmp/taucs/external/lib/linux/blas_aux.o spmat.cc -o spmat
In file included from /usr/include/c++/4.1.3/backward/complex.h:31,
from /home/hs/tmp/taucs/src/taucs.h:132,
from spmat.cc:1:
/usr/include/c++/4.1.3/backward/backward_warning.h:32:2: warning:
#warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the <X>
header for the <X.h> header for C++ includes, or <iostream> instead of
the deprecated header <iostream.h>. To disable this warning use
-Wno-deprecated.
/home/hs/tmp/taucs/src/taucs_private.h:45: error: previous declaration
of ‘taucs_ccs_matrix* taucs_ccs_create(int, int, int, int)’ with ‘C++’
linkage
spmat.cc:6: error: conflicts with new declaration with ‘C’ linkage


The lines near taucs_private.h line 45 are (output from `less -N`):
-----------------------------------------------
36 taucs_datatype taucs_dtl(div_fn)(taucs_datatype a,
taucs_datatype b);
37 taucs_datatype taucs_dtl(neg_fn)(taucs_datatype a);
38 taucs_datatype taucs_dtl(sqrt_fn)(taucs_datatype a);
39 taucs_datatype taucs_dtl(conj_fn)(taucs_datatype a);
40 double taucs_dtl(abs_fn)(taucs_datatype a);
41
42 /*** taucs_ccs_base.c ***/
43
44 taucs_ccs_matrix* taucs_dtl(ccs_create) (int m, int n,
int nnz);
45 taucs_ccs_matrix* taucs_ccs_create (int m, int n,
int nnz, int flags);
46 void taucs_dtl(ccs_free)
(taucs_ccs_matrix* matrix);
47 void taucs_ccs_free
(taucs_ccs_matrix* matrix);
48
49 /*** taucs_ccs_ops.c ***/
50
51 void taucs_dtl(ccs_split)
(taucs_ccs_matrix* A,
52
taucs_ccs_matrix** L,
53
taucs_ccs_matrix** R,
54 int p);
----------------------------------------------------

Given the above compiler output, could somebody suggest what I am doing
wrong? Or point me in the direction to get this working.

thanks,
->HS

The solution is to wrap the relevant function declarations with the
usual extern "C" construct like so:
ifdef __cplusplus
extern "C" {
#endif
taucs_ccs_matrix* taucs_dtl(ccs_create)(int m, int n, int nnz);
taucs_ccs_matrix* taucs_ccs_create (int m, int n, int nnz,
int flags);
void taucs_dtl(ccs_free) (taucs_ccs_matrix* matrix);
void taucs_ccs_free (taucs_ccs_matrix* matrix);
#ifdef __cplusplus
}
#endif

Then, buy just including taucs.h in my source file, my example program
compiles. Now I just need to go through the library header files and
make similar changes at appropriate places.

So, the library header does not appear to be designed in a portable manner.

This response is just to wrap up the thread giving the solution.

Thanks to everyone who help me achieve various insights into this problem
regards,
->HS
 
V

Victor Bazarov

H.S. said:
I have consulted a few other people about the above error. Turns out,
you are wrong on both counts.

Quite possible. Not this time, though.
If the linker couldn't find the library, it would not have known about
the arguments signature of the calling functions.

The signature is embedded into the object module where the call is
made. That signature comes from the declaration and the call itself.
(if you have no declaration, you can't compile the call; if you don't
call, the declaration does not survive the compilation, it's dicarded).

The presense (or absence of the library has no effect on the result
of the compilation which is fed to the linker, which then displays
the error if it can't resolve the symbol).
I would have got:
$> make
g++ spmat.o -o spmat
spmat.o: In function `main':
/home/sahambi/tmp/spmat/spmat.cc:24: undefined reference to
`taucs_ccs_create'
/home/sahambi/tmp/spmat/spmat.cc:27: undefined reference to
`taucs_ccs_free' collect2: ld returned 1 exit status
make: *** [spmat] Error 1


scope of this _language_ newsgroup. Please consult your library
documentation.

Another guess: your header file is not designed to work with C++
code, you might want to put exter "C" around it:

extern "C" {
#include <taucs.h>
}

That is a terrible idea again. From my newly gained experience, this
is
a bad programming practice. The problem, actually, lies in the library
itself.

Again, quite possible. Some old libraries are made with wrong
headers, and placing the #include inside the 'extern "C"' is just
a quick hack to see if it is so. Should it turn up to be true,
you would have to make up a new header for the bad library, if
you can't get it from the makers of it.
I will reply to my own original post to give the solution, for
closure :)

I'll keep my eye out.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top