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