I have downloaded the google test with below command.
wget https://github.com/google/googletest/archive/release-1.8.0.zip
and I run the following command to install the libraries to my macOS 10.13.5
unzip release-1.8.0.zip
cd googletest-release-1.8.0
mkdir build
cd build
cmake ..
make
sudo make install
and i try to compile the test as below code with command g++ -c -std=c++11 -stdlib=libc++ -lgtest -lgtest_main -pthread -o cpptest test.cpp
.
#include <iostream>
#include <gtest/gtest.h>
TEST(firstTest, abs)
{
EXPECT_EQ(1, abs( -1 ));
EXPECT_EQ(1, abs( 1 ));
}
int main(int argc, char **argv) {
std::cout << "Running main() from testmain.cc\n";
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
but i get below warnings
clang: warning: -lgtest: 'linker' input unused [-Wunused-command-lin-argument]
clang: warning: -lgtest_main: 'linker' input unused [-Wunused-command-line-argument]
Does anyone can fix this problems?
g++ -c
is used to compile a source file to an object file. This stage does not link an executable, i.e. it does not use linker, thus linker flags -lgtest -lgtest_main
are not used. If you want to compile an executable the proper compand will be without -c
:
g++ -std=c++11 -lgtest -lgtest_main -pthread -o cpptest test.cpp
Note, I have removed not required use of -stdlib
.