I've spent 5 hours trying to understand the reason for an undefined reference, so I'm asking for some help. The code -------------------- #include <cstdlib> #include <gmp.h> #include <cln/cln.h> using namespace std; using namespace cln; const cl_univpoly_complex_ring CZ = find_univpoly_ring(cl_C_ring); struct parameter { cl_N z0; cl_UP_N p(); }; int main(void) { cl_UP_N q=CZ->create(1); q.set_coeff(1, 1); q.set_coeff(0, -1); q.finalize(); parameter param; param.z0=1; param.p()=q; } -------------------- produces the error message -------------------- /tmp/ccZPl6fM.o: In function `main': test.cpp:(.text+0xc6): undefined reference to `parameter::p()' collect2: error: ld returned 1 exit status -------------------- What am I doing wrong? Note: replacing p() with p, which would make more sense to me, generates compiler errors. Thanks, Mike
Michael, On 03/26/2014 06:35 PM, Michael Miller wrote:
I've spent 5 hours trying to understand the reason for an undefined reference, so I'm asking for some help.
The code
-------------------- #include <cstdlib> #include <gmp.h> #include <cln/cln.h>
using namespace std; using namespace cln;
const cl_univpoly_complex_ring CZ = find_univpoly_ring(cl_C_ring);
struct parameter { cl_N z0; cl_UP_N p(); };
int main(void) { cl_UP_N q=CZ->create(1); q.set_coeff(1, 1); q.set_coeff(0, -1); q.finalize();
parameter param; param.z0=1; param.p()=q;
} --------------------
produces the error message
-------------------- /tmp/ccZPl6fM.o: In function `main': test.cpp:(.text+0xc6): undefined reference to `parameter::p()' collect2: error: ld returned 1 exit status --------------------
What am I doing wrong?
Note: replacing p() with p, which would make more sense to me, generates compiler errors.
The linker is telling you that you are call an undefined member function p of struct parameter. You declared that member function in line 10 of your program, call it in line 20, but never defined it. My bet is that you wanted to declare p as a member variable, not as a member function, in line 10. hope this helps -richard. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
On 03/26/2014 04:50 PM, Richard B. Kreckel wrote:
Michael,
On 03/26/2014 06:35 PM, Michael Miller wrote:
I've spent 5 hours trying to understand the reason for an undefined reference, so I'm asking for some help.
The code
-------------------- #include <cstdlib> #include <gmp.h> #include <cln/cln.h>
using namespace std; using namespace cln;
const cl_univpoly_complex_ring CZ = find_univpoly_ring(cl_C_ring);
struct parameter { cl_N z0; cl_UP_N p(); };
int main(void) { cl_UP_N q=CZ->create(1); q.set_coeff(1, 1); q.set_coeff(0, -1); q.finalize();
parameter param; param.z0=1; param.p()=q;
} --------------------
produces the error message
-------------------- /tmp/ccZPl6fM.o: In function `main': test.cpp:(.text+0xc6): undefined reference to `parameter::p()' collect2: error: ld returned 1 exit status --------------------
What am I doing wrong?
Note: replacing p() with p, which would make more sense to me, generates compiler errors.
The linker is telling you that you are call an undefined member function p of struct parameter. You declared that member function in line 10 of your program, call it in line 20, but never defined it.
My bet is that you wanted to declare p as a member variable, not as a member function, in line 10.
hope this helps -richard.
Thanks for your quick response! Your bet is correct - I do want to declare p as a member variable. However, when I try to do this, the code ================== #include <cstdlib> #include <gmp.h> #include <cln/cln.h> using namespace std; using namespace cln; struct parameter { cl_N z0; cl_UP_N p; }; int main(void) { parameter param; } ================== produces the error messages: ================== In file included from /usr/include/cln/cln.h:126:0, from test3.cpp:6: /usr/include/cln/univpoly.h: In constructor ‘cln::cl_UP_N::cl_UP_N()’: /usr/include/cln/univpoly.h:473:8: error: ‘cln::cl_UP::cl_UP()’ is private inline cl_UP::cl_UP () ^ In file included from /usr/include/cln/cln.h:127:0, from test3.cpp:6: /usr/include/cln/univpoly_complex.h:44:7: error: within this context class cl_UP_N : public cl_UP { ^ test3.cpp: In constructor ‘parameter::parameter()’: test3.cpp:11:8: note: synthesized method ‘cln::cl_UP_N::cl_UP_N()’ first required here struct parameter { cl_N z0; cl_UP_N p; }; ^ test3.cpp: In function ‘int main()’: test3.cpp:14:14: note: synthesized method ‘parameter::parameter()’ first required here parameter param; ====================== What is the compiler trying to tell me? Thanks, Michael
On 03/27/2014 09:26 PM, Michael Miller wrote: [...]
test3.cpp: In function ‘int main()’: test3.cpp:14:14: note: synthesized method ‘parameter::parameter()’ first required here parameter param; ======================
What is the compiler trying to tell me?
The compiler is complaining about a missing constructor. (This is on purpose: rings and polynomials are reference counted and centrally managed in order to avoid two mathematically equal objects within one program.) Use references to polynomials rings if you want to pass them around. For instance, you could declare your structure like this: struct parameter { cl_N z0; cl_UP& p; } and, once you have created and finalized your cl_UP_N object q, create a parameter object like this: parameter param = {1, q}; hope this helps -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
participants (2)
-
Michael Miller
-
Richard B. Kreckel