gtest in eclipse error:ld.exe can not find -llibgtest

gtest in eclipse error:ld.exe can not find -llibgtest

本文关键字:can not find -llibgtest exe ld in eclipse error gtest      更新时间:2023-10-16

我在 eclipse 中使用 google test(gtest),这是我的代码

测试.h

#ifndef TEST_H_
#define TEST_H_
int Foo(int a, int b);
#endif

测试.cpp

#include<iostream>
#include "test.h"
int Foo(int a, int b) {
return a + b;}

主.cpp

#include "test.h"
#include "gtest/gtest.h"

TEST(FooTest, HandleNoneZeroInput)
{
    EXPECT_EQ(2, Foo(4, 10));
    EXPECT_EQ(6, Foo(30, 18));
}
int main(int argc, char* argv[])
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

这是我的 Eclipse 配置:

Library Paths    F:GTESTgoogletestgoogletestmybuildlib

Libraries        libgtest

Includes         F:GTESTgoogletestgoogletestinclude

我的文件夹中有两个文件F:GTESTgoogletestgoogletestmybuildlib分别名为libgtest.alibgtest_main.a

我构建了我的项目,日食产生了一个错误:

c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -llibgtest

注意:

我的工作环境windows7_64, mingw32, gcc 6.3.0, eclipse

谢谢你,我希望你的解决方案。

解决方案很简单。当库列在 Eclipse 配置的"库"部分中时,应省略"lib"前缀:

Libraries        gtest gtest_main