Not sure if it's the cause of your errors, but you probably want to
name the file add.cc instead. .c is for C source files, and that
results in the definition of add() having C-linkage. add_test.cc
expects the function to have C++-linkage, so there's a mismatch.
(It's possible to link C with C++, but you need to enclose the API in
'extern "C" { ... }' when compiling in C++ mode.)
> #include "add.h"
> int add(int x, int y) {
> return x + y;
> }
>
> add_test.cc:
> #include "add.h"
> #include <gtest/gtest.h>
> TEST(Add, Default) {
> EXPECT_EQ(3,add(1,2));
> }
>
> I'm compiling the source code using the following command:
> $ g++ add.c add_test.cc -o add_test -L/usr/local/lib -lgtest_main -
> lgtest
Unrelated but you don't need -lgtest here. -lgtest_main should be enough.
Also unrelated: we don't recommend installing gtest to /usr/local/lib
as it often leads to subtle problems. Instead, just compile it as
part of your build. We tried to explain this in README. Thanks,
>
> Then when I try to run add_test.exe it fails with the exception being
> thrown.
>
> Any idea what the issues could be?
>
> Regards,
> Tom
>
>
--
Zhanyong