2012-11-30 16 views
11

को लिंक करते समय एक और "अपरिभाषित संदर्भ" त्रुटि मैंने कई अन्य पोस्ट देखी हैं जो इस सटीक समस्या से निपटती हैं। हालांकि, उनके समाधान में से कोई भी मेरे लिए काम नहीं कर रहा है। मैं निम्नलिखित कोड संकलित कर रहा हूं: बूस्ट लाइब्रेरी

#include <boost/numeric/ublas/matrix.hpp> 
#include <boost/numeric/ublas/io.hpp> 
#include <boost/timer/timer.hpp> 

using namespace boost::numeric::ublas; 

int main(){  
    matrix<double> mat1 (3,3); 
    matrix<double> mat2 (3,3); 
    matrix<double> mat3 (3,3); 

    unsigned k=0; 

    for(unsigned i = 0; i < mat1.size1(); ++i){ 
     for(unsigned j = 0; j < mat1.size2(); ++j){ 
     mat1(i,j) = k; 
     mat2(i,j) = 2*k++; 
     } 
    } 

    k=0; 
    if(1){ 
     boost::timer::auto_cpu_timer t; 
     while(k<1000){ 
     mat3 = prod(mat1,mat2); 
     k++; 
     } 
    } 
    return 0; 
} 

I am compiling from the command line using:

$ g++ matrix_test.cpp -o matrix_test -lboost_system -lboost_timer

and receiving the following error:

usr/lib/gcc/i686-redhat-linux/4.7.0/../../../libboost_timer.so: undefined reference to `boost::chrono::steady_clock::now()'
collect2: error: ld returned 1 exit status

If I add -lboost_chrono when I compile, I get this error:

/usr/lib/gcc/i686-redhat-linux/4.7.0/../../../libboost_chrono.so: undefined reference to `clock_gettime'
collect2: error: ld returned 1 exit status

I can trace clock_gettime to sys/time.h. Unfortunately, I cannot find a corresponding .so file to link to. What am I missing here?

उत्तर

18

आप अपने लिंक पुस्तकालयों के लिए -lrt जोड़ना होगा

g++ matrix_test.cpp -o matrix_test -lboost_system -lboost_timer -lboost_chrono -lrt 

अद्यतन (2016-08-31)

यह अभी भी एक मुद्दा हो रहा है। आप man clock_gettime देखने हैं, तो यह समाधान (-lrt) की ओर जाता है, लेकिन यह भी कहते हैं -lrt (केवल 2.17 से पहले glibc संस्करणों के लिए) के साथ

लिंक।

तो जब आपका ग्लिब नया हो, तो आपकी समस्या कुछ और हो सकती है।

+0

वाह। मैं ऐसा करने के लिए कभी भी कैसे जाना होगा? दोस्तों, बहुत बहुत धन्यवाद! –

8

Add -lrt आपके जी ++ आमंत्रण में - clock_gettimelibrt.so में है।

संबंधित मुद्दे