Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22097

Using gtest with gcc cpp, got error - collect2: error: ld returned 1 exit status

$
0
0

Source code:

#include <stdio.h>
#include <gtest/gtest.h>
int main() {
    return 0;
}

Error message:

happyjoo@D:~$ gcc test.cpp
/tmp/cctruZ9h.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x30): undefined reference to `std::ios_base::Init::Init()'
test.cpp:(.text+0x45): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
happyjoo@D:~$ gcc -lpthread -lgtest test.cpp
/tmp/ccmuAM5q.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x30): undefined reference to `std::ios_base::Init::Init()'
test.cpp:(.text+0x45): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status

The code is very simple, so I don't know what is wrong. If I comment the #include <gtest/gtest.h>, my code can be complied normally. I guess it is the problem of the gtest?

I follow the link How to set up googletest as a shared library on linux. But instead of copy, I used make install. Got something after using sudo ldconfig -v | grep gtest. Don't know whether they are related or not.

$ sudo ldconfig -v | grep gtest
[sudo] password for happyjoo: 
/sbin/ldconfig.real: Can't stat /usr/local/lib/x86_64-linux-gnu: No such file or directory
/sbin/ldconfig.real: Path `/lib/x86_64-linux-gnu' given more than once
/sbin/ldconfig.real: Path `/usr/lib/x86_64-linux-gnu' given more than once
/sbin/ldconfig.real: /lib/x86_64-linux-gnu/ld-2.27.so is the dynamic linker, ignoring

        libgtest_main.so -> libgtest_main.so
        libgtest.so -> libgtest.so

Before I commented other code, I got a lot of error messages using RUN_ALL_TESTS() and EXPECT_EQ. I'll test it again after fixing this problem. I guess it is the same issue.

I'll be very appreciated if someone can help. Thanks for every one!!!


Viewing all articles
Browse latest Browse all 22097

Trending Articles