Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[gtest] Problem z kompilacją przykładowych testów

Ostatnio zmodyfikowano 2013-06-28 20:12
Autor Wiadomość
johny
Temat założony przez niniejszego użytkownika
[gtest] Problem z kompilacją przykładowych testów
» 2013-06-28 20:12:50
Witam. Od jakiegoś czasu tworzę swoje wypociny na Linuxie. Moje IDE to Code::Blocks 12.11.
Postanowiłem zabrać się za testy jednostkowe i jako framework wybrałem google test. No więc w celu uruchomienia tego całego ustrojstwa wziąłem się za czytanie tutorialu/dokumentacji dostarczonej przez twórców, o tutaj: http://code.google.com/p/googletest/source/browse/trunk/README

Pracuję pod Ubuntu 13.04. Pobrałem pakiety źródłowe, tak jak w instrukcji (### Source Package ###), a następnie wziąłem się za kompilację biblioteki i archiwizację (ar). Wszystko wg instrukcji z przewodnika:
g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
-pthread -c ${GTEST_DIR}/src/gtest-all.cc
ar -rv libgtest.a gtest-all.o
Dalej, umieściłem zarchiwizowane pliki w katalogu /usr/local/lib. Są to libgtest.a i libgtest_main.a. Pliki nagłówkowe, te od google (które były po rozpakowaniu w katalogu gtest-1.6.0/include) skopiowałem do usr/local/include.

W następnym kroku postanowiłem wypróbować gotowce dostarczane przez producenta. Dostępne są one o tu: http://code.google.com/p/googletest/source/browse/trunk/#trunk%2Fsamples%253Fstate%253Dclosed
Na mój projekt składają się 4 pliki. Pierwszy to testowany sample1.cc, drugi to jego plik nagłówkowy, trzeci to plik zawierający testy, a czwarty to main, w którym jedynie wywołuje testy.
C/C++
//plik sample1.cc
#include "sample1.h"

// Returns n! (the factorial of n).  For negative n, n! is defined to be 1.
int Factorial( int n ) {
    int result = 1;
    for( int i = 1; i <= n; i++ ) {
        result *= i;
    }
   
    return result;
}

// Returns true iff n is a prime number.
bool IsPrime( int n ) {
    // Trivial case 1: small numbers
    if( n <= 1 ) return false;
   
    // Trivial case 2: even numbers
    if( n % 2 == 0 ) return n == 2;
   
    // Now, we have that n is odd and n >= 3.
   
    // Try to divide n by every odd number i, starting from 3
    for( int i = 3;; i += 2 ) {
        // We only have to try i up to the squre root of n
        if( i > n / i ) break;
       
        // Now, we have i <= n/i < n.
        // If n is divisible by i, n is not prime.
        if( n % i == 0 ) return false;
       
    }
   
    // n has no integer factor in the range (1, n), and thus is prime.
    return true;
}

C/C++
//plik sample1.h
#ifndef GTEST_SAMPLES_SAMPLE1_H_
#define GTEST_SAMPLES_SAMPLE1_H_

// Returns n! (the factorial of n).  For negative n, n! is defined to be 1.
int Factorial( int n );

// Returns true iff n is a prime number.
bool IsPrime( int n );

#endif  // GTEST_SAMPLES_SAMPLE1_H_

C/C++
//plik zawierajacy testy
//sample1_unittest.cc
// This sample shows how to write a simple unit test for a function,
// using Google C++ testing framework.
//
// Writing a unit test using Google C++ testing framework is easy as 1-2-3:


// Step 1. Include necessary header files such that the stuff your
// test logic needs is declared.
//
// Don't forget gtest.h, which declares the testing framework.

#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"


// Step 2. Use the TEST macro to define your tests.
//
// TEST has two parameters: the test case name and the test name.
// After using the macro, you should define your test logic between a
// pair of braces.  You can use a bunch of macros to indicate the
// success or failure of a test.  EXPECT_TRUE and EXPECT_EQ are
// examples of such macros.  For a complete list, see gtest.h.
//
// <TechnicalDetails>
//
// In Google Test, tests are grouped into test cases.  This is how we
// keep test code organized.  You should put logically related tests
// into the same test case.
//
// The test case name and the test name should both be valid C++
// identifiers.  And you should not use underscore (_) in the names.
//
// Google Test guarantees that each test you define is run exactly
// once, but it makes no guarantee on the order the tests are
// executed.  Therefore, you should write your tests in such a way
// that their results don't depend on their order.
//
// </TechnicalDetails>


// Tests Factorial().

// Tests factorial of negative numbers.
TEST( FactorialTest, Negative ) {
    // This test is named "Negative", and belongs to the "FactorialTest"
    // test case.
    EXPECT_EQ( 1, Factorial( - 5 ) );
    EXPECT_EQ( 1, Factorial( - 1 ) );
    EXPECT_TRUE( Factorial( - 10 ) > 0 );
   
    // <TechnicalDetails>
    //
    // EXPECT_EQ(expected, actual) is the same as
    //
    //   EXPECT_TRUE((expected) == (actual))
    //
    // except that it will print both the expected value and the actual
    // value when the assertion fails.  This is very helpful for
    // debugging.  Therefore in this case EXPECT_EQ is preferred.
    //
    // On the other hand, EXPECT_TRUE accepts any Boolean expression,
    // and is thus more general.
    //
    // </TechnicalDetails>
}

// Tests factorial of 0.
TEST( FactorialTest, Zero ) {
    EXPECT_EQ( 1, Factorial( 0 ) );
}

// Tests factorial of positive numbers.
TEST( FactorialTest, Positive ) {
    EXPECT_EQ( 1, Factorial( 1 ) );
    EXPECT_EQ( 2, Factorial( 2 ) );
    EXPECT_EQ( 6, Factorial( 3 ) );
    EXPECT_EQ( 40320, Factorial( 8 ) );
}


// Tests IsPrime()

// Tests negative input.
TEST( IsPrimeTest, Negative ) {
    // This test belongs to the IsPrimeTest test case.
   
    EXPECT_FALSE( IsPrime( - 1 ) );
    EXPECT_FALSE( IsPrime( - 2 ) );
    EXPECT_FALSE( IsPrime( INT_MIN ) );
}

// Tests some trivial cases.
TEST( IsPrimeTest, Trivial ) {
    EXPECT_FALSE( IsPrime( 0 ) );
    EXPECT_FALSE( IsPrime( 1 ) );
    EXPECT_TRUE( IsPrime( 2 ) );
    EXPECT_TRUE( IsPrime( 3 ) );
}

// Tests positive input.
TEST( IsPrimeTest, Positive ) {
    EXPECT_FALSE( IsPrime( 4 ) );
    EXPECT_TRUE( IsPrime( 5 ) );
    EXPECT_FALSE( IsPrime( 6 ) );
    EXPECT_TRUE( IsPrime( 23 ) );
}

// Step 3. Call RUN_ALL_TESTS() in main().
//
// We do this by linking in src/gtest_main.cc file, which consists of
// a main() function which calls RUN_ALL_TESTS() for us.
//
// This runs all the tests you've defined, prints the result, and
// returns 0 if successful, or 1 otherwise.
//
// Did you notice that we didn't register the tests?  The
// RUN_ALL_TESTS() macro magically knows about all the tests we
// defined.  Isn't this convenient?

C/C++
//plik main
#include "sample1.h"
#include <gtest/gtest.h>
int main( int argc, char ** argv ) {
    testing::InitGoogleTest( & argc, argv );
    return RUN_ALL_TESTS();
}

Zarówno próba kompilacji pod IDE jak i przy użyciu gcc wysypuje lawinę błędów. Brakuje mu plików nagłówkowych, chyba. Od 2 dni nie mogę tego ogarnąć. Wie ktoś co mam zrobić, aby ruszyć z tym dalej?:P


Log kompilacji wypluwany przez Code::Blocks:
||=== P1, Debug ===|
obj/Debug/Pobrane/gtest-1.6.0/samples/sample1_unittest.o||In function `FactorialTest_Negative_Test::TestBody()':|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|82|undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|82|undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|82|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|83|undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|83|undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|83|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|84|undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|84|undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|84|undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|84|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|82|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|83|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|84|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
obj/Debug/Pobrane/gtest-1.6.0/samples/sample1_unittest.o||In function `FactorialTest_Zero_Test::TestBody()':|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|104|undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|104|undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|104|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|104|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
obj/Debug/Pobrane/gtest-1.6.0/samples/sample1_unittest.o||In function `FactorialTest_Positive_Test::TestBody()':|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|109|undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|109|undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|109|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|110|undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|110|undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|110|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|111|undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|111|undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|111|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|112|undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|112|undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|112|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|109|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|110|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|111|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|112|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
obj/Debug/Pobrane/gtest-1.6.0/samples/sample1_unittest.o||In function `IsPrimeTest_Negative_Test::TestBody()':|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|122|undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|122|undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|122|undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|122|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|123|undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|123|undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|123|undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|123|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|124|undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|124|undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|124|undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|124|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|122|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|123|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|124|undefined reference to `testing::internal::AssertHelper::~AssertHelper()'|
obj/Debug/Pobrane/gtest-1.6.0/samples/sample1_unittest.o||In function `IsPrimeTest_Trivial_Test::TestBody()':|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|129|undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'|
/home/mateusz/Pobrane/gtest-1.6.0/samples/sample1_unittest.cc|129|undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings (0 minutes, 2 seconds) ===|

A tutaj od gcc, przy "ręcznej" kompilacji:
mateusz@mateusz-P35-S3G:~/CodeBlocks/samples$ g++ -Wall sample1.cc sample1_unittest.cc main.cc -o main
/tmp/ccznp48T.o: In function `FactorialTest_Negative_Test::TestBody()':
sample1_unittest.cc:(.text+0x91): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0xa3): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0xae): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x152): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x164): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x16f): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x1f0): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
sample1_unittest.cc:(.text+0x225): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x237): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x242): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x277): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x2b0): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x2e7): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/tmp/ccznp48T.o: In function `FactorialTest_Zero_Test::TestBody()':
sample1_unittest.cc:(.text+0x3bb): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x3cd): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x3d8): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x3ff): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/tmp/ccznp48T.o: In function `FactorialTest_Positive_Test::TestBody()':
sample1_unittest.cc:(.text+0x4c3): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x4d5): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x4e0): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x584): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x596): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x5a1): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x645): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x657): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x662): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x706): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x718): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x723): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x74d): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x786): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x7bf): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x7f8): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/tmp/ccznp48T.o: In function `IsPrimeTest_Negative_Test::TestBody()':
sample1_unittest.cc:(.text+0x898): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
sample1_unittest.cc:(.text+0x8cd): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x8df): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x8ea): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x974): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
sample1_unittest.cc:(.text+0x9a9): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x9bb): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x9c6): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0xa50): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
sample1_unittest.cc:(.text+0xa85): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0xa97): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0xaa2): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0xad5): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0xb1b): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0xb61): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/tmp/ccznp48T.o: In function `IsPrimeTest_Trivial_Test::TestBody()':
sample1_unittest.cc:(.text+0xc10): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
sample1_unittest.cc:(.text+0xc45): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0xc57): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0xc62): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0xcec): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
sample1_unittest.cc:(.text+0xd21): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0xd33): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0xd3e): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0xdc5): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
sample1_unittest.cc:(.text+0xdfa): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0xe0c): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0xe17): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0xe9e): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
sample1_unittest.cc:(.text+0xed3): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0xee5): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0xef0): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0xf23): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0xf69): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0xfaf): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0xff5): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/tmp/ccznp48T.o: In function `IsPrimeTest_Positive_Test::TestBody()':
sample1_unittest.cc:(.text+0x10a4): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
sample1_unittest.cc:(.text+0x10d9): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x10eb): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x10f6): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x117d): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
sample1_unittest.cc:(.text+0x11b2): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x11c4): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x11cf): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x1259): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
sample1_unittest.cc:(.text+0x128e): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x12a0): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x12ab): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x1332): undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
sample1_unittest.cc:(.text+0x1367): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
sample1_unittest.cc:(.text+0x1379): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
sample1_unittest.cc:(.text+0x1384): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x13b7): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x13fd): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x1443): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
sample1_unittest.cc:(.text+0x1489): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/tmp/ccznp48T.o: In function `__static_initialization_and_destruction_0(int, int)':
sample1_unittest.cc:(.text+0x1528): undefined reference to `testing::internal::GetTestTypeId()'
sample1_unittest.cc:(.text+0x1564): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
sample1_unittest.cc:(.text+0x1584): undefined reference to `testing::internal::GetTestTypeId()'
sample1_unittest.cc:(.text+0x15c0): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
sample1_unittest.cc:(.text+0x15e0): undefined reference to `testing::internal::GetTestTypeId()'
sample1_unittest.cc:(.text+0x161c): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
sample1_unittest.cc:(.text+0x163c): undefined reference to `testing::internal::GetTestTypeId()'
sample1_unittest.cc:(.text+0x1678): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
sample1_unittest.cc:(.text+0x1698): undefined reference to `testing::internal::GetTestTypeId()'
sample1_unittest.cc:(.text+0x16d4): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
sample1_unittest.cc:(.text+0x16f4): undefined reference to `testing::internal::GetTestTypeId()'
sample1_unittest.cc:(.text+0x1730): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
/tmp/ccznp48T.o: In function `FactorialTest_Negative_Test::FactorialTest_Negative_Test()':
sample1_unittest.cc:(.text._ZN27FactorialTest_Negative_TestC2Ev[_ZN27FactorialTest_Negative_TestC5Ev]+0xd): undefined reference to `testing::Test::Test()'
/tmp/ccznp48T.o: In function `FactorialTest_Zero_Test::FactorialTest_Zero_Test()':
sample1_unittest.cc:(.text._ZN23FactorialTest_Zero_TestC2Ev[_ZN23FactorialTest_Zero_TestC5Ev]+0xd): undefined reference to `testing::Test::Test()'
/tmp/ccznp48T.o: In function `FactorialTest_Positive_Test::FactorialTest_Positive_Test()':
sample1_unittest.cc:(.text._ZN27FactorialTest_Positive_TestC2Ev[_ZN27FactorialTest_Positive_TestC5Ev]+0xd): undefined reference to `testing::Test::Test()'
/tmp/ccznp48T.o: In function `IsPrimeTest_Negative_Test::IsPrimeTest_Negative_Test()':
sample1_unittest.cc:(.text._ZN25IsPrimeTest_Negative_TestC2Ev[_ZN25IsPrimeTest_Negative_TestC5Ev]+0xd): undefined reference to `testing::Test::Test()'
/tmp/ccznp48T.o: In function `IsPrimeTest_Trivial_Test::IsPrimeTest_Trivial_Test()':
sample1_unittest.cc:(.text._ZN24IsPrimeTest_Trivial_TestC2Ev[_ZN24IsPrimeTest_Trivial_TestC5Ev]+0xd): undefined reference to `testing::Test::Test()'
/tmp/ccznp48T.o:sample1_unittest.cc:(.text._ZN25IsPrimeTest_Positive_TestC2Ev[_ZN25IsPrimeTest_Positive_TestC5Ev]+0xd): more undefined references to `testing::Test::Test()' follow
/tmp/ccznp48T.o: In function `testing::internal::scoped_ptr<std::string>::reset(std::string*)':
sample1_unittest.cc:(.text._ZN7testing8internal10scoped_ptrISsE5resetEPSs[_ZN7testing8internal10scoped_ptrISsE5resetEPSs]+0x19): undefined reference to `testing::internal::IsTrue(bool)'
/tmp/ccznp48T.o: In function `testing::internal::scoped_ptr<std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> > >::reset(std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >*)':
sample1_unittest.cc:(.text._ZN7testing8internal10scoped_ptrISt18basic_stringstreamIcSt11char_traitsIcESaIcEEE5resetEPS6_[_ZN7testing8internal10scoped_ptrISt18basic_stringstreamIcSt11char_traitsIcESaIcEEE5resetEPS6_]+0x18): undefined reference to `testing::internal::IsTrue(bool)'
/tmp/ccznp48T.o: In function `testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&)':
sample1_unittest.cc:(.text._ZN7testing8internal11CmpHelperEQIiiEENS_15AssertionResultEPKcS4_RKT_RKT0_[_ZN7testing8internal11CmpHelperEQIiiEENS_15AssertionResultEPKcS4_RKT_RKT0_]+0x1c): undefined reference to `testing::AssertionSuccess()'
sample1_unittest.cc:(.text._ZN7testing8internal11CmpHelperEQIiiEENS_15AssertionResultEPKcS4_RKT_RKT0_[_ZN7testing8internal11CmpHelperEQIiiEENS_15AssertionResultEPKcS4_RKT_RKT0_]+0x8b): undefined reference to `testing::internal::EqFailure(char const*, char const*, testing::internal::String const&, testing::internal::String const&, bool)'
/tmp/ccznp48T.o:(.rodata._ZTV25IsPrimeTest_Positive_Test[_ZTV25IsPrimeTest_Positive_Test]+0x10): undefined reference to `testing::Test::SetUp()'
/tmp/ccznp48T.o:(.rodata._ZTV25IsPrimeTest_Positive_Test[_ZTV25IsPrimeTest_Positive_Test]+0x14): undefined reference to `testing::Test::TearDown()'
/tmp/ccznp48T.o: In function `IsPrimeTest_Positive_Test::~IsPrimeTest_Positive_Test()':
sample1_unittest.cc:(.text._ZN25IsPrimeTest_Positive_TestD2Ev[_ZN25IsPrimeTest_Positive_TestD5Ev]+0x16): undefined reference to `testing::Test::~Test()'
/tmp/ccznp48T.o:(.rodata._ZTV24IsPrimeTest_Trivial_Test[_ZTV24IsPrimeTest_Trivial_Test]+0x10): undefined reference to `testing::Test::SetUp()'
/tmp/ccznp48T.o:(.rodata._ZTV24IsPrimeTest_Trivial_Test[_ZTV24IsPrimeTest_Trivial_Test]+0x14): undefined reference to `testing::Test::TearDown()'
/tmp/ccznp48T.o: In function `IsPrimeTest_Trivial_Test::~IsPrimeTest_Trivial_Test()':
sample1_unittest.cc:(.text._ZN24IsPrimeTest_Trivial_TestD2Ev[_ZN24IsPrimeTest_Trivial_TestD5Ev]+0x16): undefined reference to `testing::Test::~Test()'
/tmp/ccznp48T.o:(.rodata._ZTV25IsPrimeTest_Negative_Test[_ZTV25IsPrimeTest_Negative_Test]+0x10): undefined reference to `testing::Test::SetUp()'
/tmp/ccznp48T.o:(.rodata._ZTV25IsPrimeTest_Negative_Test[_ZTV25IsPrimeTest_Negative_Test]+0x14): undefined reference to `testing::Test::TearDown()'
/tmp/ccznp48T.o: In function `IsPrimeTest_Negative_Test::~IsPrimeTest_Negative_Test()':
sample1_unittest.cc:(.text._ZN25IsPrimeTest_Negative_TestD2Ev[_ZN25IsPrimeTest_Negative_TestD5Ev]+0x16): undefined reference to `testing::Test::~Test()'
/tmp/ccznp48T.o:(.rodata._ZTV27FactorialTest_Positive_Test[_ZTV27FactorialTest_Positive_Test]+0x10): undefined reference to `testing::Test::SetUp()'
/tmp/ccznp48T.o:(.rodata._ZTV27FactorialTest_Positive_Test[_ZTV27FactorialTest_Positive_Test]+0x14): undefined reference to `testing::Test::TearDown()'
/tmp/ccznp48T.o: In function `FactorialTest_Positive_Test::~FactorialTest_Positive_Test()':
sample1_unittest.cc:(.text._ZN27FactorialTest_Positive_TestD2Ev[_ZN27FactorialTest_Positive_TestD5Ev]+0x16): undefined reference to `testing::Test::~Test()'
/tmp/ccznp48T.o:(.rodata._ZTV23FactorialTest_Zero_Test[_ZTV23FactorialTest_Zero_Test]+0x10): undefined reference to `testing::Test::SetUp()'
/tmp/ccznp48T.o:(.rodata._ZTV23FactorialTest_Zero_Test[_ZTV23FactorialTest_Zero_Test]+0x14): undefined reference to `testing::Test::TearDown()'
/tmp/ccznp48T.o: In function `FactorialTest_Zero_Test::~FactorialTest_Zero_Test()':
sample1_unittest.cc:(.text._ZN23FactorialTest_Zero_TestD2Ev[_ZN23FactorialTest_Zero_TestD5Ev]+0x16): undefined reference to `testing::Test::~Test()'
/tmp/ccznp48T.o:(.rodata._ZTV27FactorialTest_Negative_Test[_ZTV27FactorialTest_Negative_Test]+0x10): undefined reference to `testing::Test::SetUp()'
/tmp/ccznp48T.o:(.rodata._ZTV27FactorialTest_Negative_Test[_ZTV27FactorialTest_Negative_Test]+0x14): undefined reference to `testing::Test::TearDown()'
/tmp/ccznp48T.o: In function `FactorialTest_Negative_Test::~FactorialTest_Negative_Test()':
sample1_unittest.cc:(.text._ZN27FactorialTest_Negative_TestD2Ev[_ZN27FactorialTest_Negative_TestD5Ev]+0x16): undefined reference to `testing::Test::~Test()'
/tmp/ccznp48T.o:(.rodata._ZTI25IsPrimeTest_Positive_Test[_ZTI25IsPrimeTest_Positive_Test]+0x8): undefined reference to `typeinfo for testing::Test'
/tmp/ccznp48T.o:(.rodata._ZTI24IsPrimeTest_Trivial_Test[_ZTI24IsPrimeTest_Trivial_Test]+0x8): undefined reference to `typeinfo for testing::Test'
/tmp/ccznp48T.o:(.rodata._ZTI25IsPrimeTest_Negative_Test[_ZTI25IsPrimeTest_Negative_Test]+0x8): undefined reference to `typeinfo for testing::Test'
/tmp/ccznp48T.o:(.rodata._ZTI27FactorialTest_Positive_Test[_ZTI27FactorialTest_Positive_Test]+0x8): undefined reference to `typeinfo for testing::Test'
/tmp/ccznp48T.o:(.rodata._ZTI23FactorialTest_Zero_Test[_ZTI23FactorialTest_Zero_Test]+0x8): undefined reference to `typeinfo for testing::Test'
/tmp/ccznp48T.o:(.rodata._ZTI27FactorialTest_Negative_Test[_ZTI27FactorialTest_Negative_Test]+0x8): more undefined references to `typeinfo for testing::Test' follow
/tmp/ccrtkmvf.o: In function `main':
main.cc:(.text+0x17): undefined reference to `testing::InitGoogleTest(int*, char**)'
main.cc:(.text+0x1c): undefined reference to `testing::UnitTest::GetInstance()'
main.cc:(.text+0x24): undefined reference to `testing::UnitTest::Run()'
collect2: error: ld returned 1 exit status

Edit:
Ok, wrzuciłem zawartość maina do testu i udało się skompilować takim oto zaklęciem:
g++ -isystem /home/mateusz/Pobrane/gtest-1.6.0/include/ main.cc sample1.cc sample1_unittest.cc -lgtest -o tescik -pthread
Czas cofnąć się do podstawy podstaw, bo widać wychodzą braki, jeśli chodzi o kompilowanie w terminalu.

To teraz mój problem sprowadza się do tego, w jaki sposób podać mam ścieżki w Code::Blocks IDE, żeby efekt był taki sam. :D

Edit2:
W Code::Blocks Settings->Compiler->Linker Settings. W polu "Link libraries" ścieżki do bibliotek, a w "Other linker options" dodać trzeba -pthread. Do tej pory miałem tylko podane ścieżki w "search directiories" :<
Można zamknąć. Sorki za zaśmiecanie :P
P-86515
« 1 »
  Strona 1 z 1