I want to debug a program I wrote. Therefor I'd like to link it using "-g -O0". When I compile (using autotools Makefile) using
make CXXFLAGS='-g -O0'
I get some errors:
libtool: link: g++ -O2 -g -O0 -I/opt/adolc-2.2.1/include -o oc_poly oc_poly-oc_poly.o oc_poly-oc_p2p.o -L/opt/ipopt-3.9.3/lib/coin -L/opt/ipopt-3.9.3/lib/coin/ThirdParty -L/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2 -L/usr/lib/i386-linux-gnu/gcc/i686- linux-gnu/4.5.2/../../.. -L/usr/lib/i386-linux-gnu /opt/ipopt-3.9.3/lib/coin/libipopt.so -llapack -ldl /opt/ipopt-3.9.3/lib/coin/ThirdParty/libcoinhsl.so /opt/ipopt-3.9.3/lib /coin/ThirdParty/libcoinblas.so /opt/ipopt-3.9.3/lib/coin/ThirdParty/libcoinlapack.so /opt/ipopt-3.9.3/lib/coin/ThirdParty/libcoinmumps.so -lpthread -lblas -lgfortran -lm -lgcc_s /opt/ipopt-3.9.3/lib/coin/ThirdParty/libcoinmetis.so -L/opt/adolc-2.2.1/lib /opt/adolc-2.2.1/lib/libadolc.so -Wl,-rpath -Wl,/opt/ipopt-3.9.3/lib/coin -Wl,-rpath -Wl,/opt/ipopt-3.9.3/lib/coin/ThirdParty -Wl,-rpath -Wl,/opt/adolc-2.2.1/lib -Wl,-rpath -Wl,/opt/ipopt-3.9.3/lib/coin -Wl,-rpath -Wl,/opt/ipopt-3.9.3/lib/coin/ThirdParty -Wl,-rpath -Wl,/opt/adolc-2.2.1/lib oc_poly-oc_p2p.o: In function
OCP_P2P::get_bounds_info(int, double*, double*, int, double*, double*)': /home/christian/Dokumente/Uni/SA/ist/Berechnungen/Optimale Steuernug/IpOpt /oc_p2p.cpp:162: undefined reference to
OCP_P2P::INF'
The mentioned symbol INF is a static class member defined in the class definition OCP_P2P.
If I omit the CXXFLAGS or set them to any optimization value of O1, O2, O3 or Os the linking works pretty well. I am using g++ 4.5.2.
Can anybody give me a hint, what's going wrong here? How can I debug my program?
Thanks
Christian
A static class member variable needs a definition; even if it is initialised in the class definition that is only a declaration. In other words, you need to put
somewhere in a cpp file. Presumably when optimisation was turned on the use of the variable was optimised out.
The official rule is that a definition is needed if the variable is used, according to the standard's definition of used, which is basically if a pointer to the variable is taken, or if the variable is bound to a reference.