c++ - Maven nar 构建中的 GoogleTest 编译错误 - 未定义对`testing::internal::MakeAndRegisterTestInfo 的引用

标签 c++ maven googletest maven-nar-plugin

我正在尝试使用 Maven 进行 Google 测试。所以,我使用这个 link 安装了它.然后我创建了用于测试的 dummyTest.cpp 并将其添加到 pom.xml 中以执行测试。当我执行 mvn clean install 时,出现以下错误 -

[INFO] 1 total files to be compiled.
[INFO] 1 total files to be compiled.
[INFO] Found 1 processors available
[INFO] Found 1 processors available
[INFO]
Starting Core 0 with 1 source files...
[INFO]
Starting Core 0 with 1 source files...
[INFO] Linking...
[INFO] Linking...
[INFO] Starting link {4.8.3 -L/usr/lib -Bdynamic -lgtest -L/usr/lib -Bdynamic -lgtest_main -Bdynamic -lpthread -fexceptions -lstdc++}
[INFO] Starting link {4.8.3 -L/usr/lib -Bdynamic -lgtest -L/usr/lib -Bdynamic -lgtest_main -Bdynamic -lpthread -fexceptions -lstdc++}
[ERROR] /usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread
[ERROR] /usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread
[ERROR] /usr/bin/ld: skipping incompatible /usr/lib/libm.so when searching for -lm
[ERROR] /usr/bin/ld: skipping incompatible /usr/lib/libm.so when searching for -lm
[ERROR] /usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc
[ERROR] /usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc
[ERROR] /home/sshakya/MavenC/Recent_Backup/COE/testlibrary/target/test-nar/obj/amd64-Linux-gpp/dummyTest.o: In function `__static_initialization_and_destruction_0(int, int)':
[ERROR] dummyTest.cpp:(.text+0x1f2): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
[ERROR] collect2: error: ld returned 1 exit status
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

我使用的dummyTest.cpppom文件工程结构如下:-

//
//      File:   dummyTest.cpp
//
#include "gtest/gtest.h"
TEST(dummyTest, AlwaysTrueTest) {
  EXPECT_EQ(1, 1);
}

//
//      File:   pom.xml
//
<project xmlns="http://maven.apache.org/POM/4.0.0"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.coe</groupId>
<artifactId>testlibrary</artifactId>
<packaging>nar</packaging>
<version>1.0-SNAPSHOT</version>

<properties>
    <skipTests>false</skipTests>
    <skipDeploy>false</skipDeploy> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>   

<build>
    <defaultGoal>install</defaultGoal>
    <plugins>          
        <plugin>
            <groupId>com.github.maven-nar</groupId>
            <artifactId>nar-maven-plugin</artifactId>
            <version>3.2.3</version>
            <extensions>true</extensions>
            <configuration>
                <layout>NarLayout20</layout>
                <libraries>
                   <library>
                        <type>executable</type>
                        <run>true</run>
                    </library>
                </libraries>
                <linker>
                    <name>g++</name>
                    <sysLibs>
                        <sysLib>
                            <name>pthread</name>
                        </sysLib>
                    </sysLibs>
                     <libs>
                          <lib>
                            <name>gtest</name>
                            <type>shared</type>
                            <directory>/usr/lib/</directory>
                          </lib>
                          <lib>
                            <name>gtest_main</name>
                            <type>shared</type>
                            <directory>/usr/lib/</directory>
                          </lib>
                    </libs>
                </linker>
                <tests>
                    <test>
                      <name>dummyTest</name>
                      <link>shared</link>
                    </test>
              </tests>
            </configuration>
        </plugin>
    </plugins>
</build>

enter image description here

从其他博客文章和 stackoverflow 问答中,我似乎是以正确的方式来做这件事,但我无法弄清楚是什么导致了这个问题。任何帮助或任何指向正确方向的提示都将不胜感激。谢谢

最佳答案

请检查搜索路径中是否存在矛盾的 gtest 版本:编译期间包含的 gtest.h 是否与您链接到的库 libgtest{,_main} 所用的相同?

关于c++ - Maven nar 构建中的 GoogleTest 编译错误 - 未定义对`testing::internal::MakeAndRegisterTestInfo 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39296811/

相关文章:

c++ - 信号处理程序与事件处理程序

java - pom.xml 中的版本未更新

eclipse - 在Eclipse控制台中为Google C++测试框架中的输出文本着色文本

c++ - GTest 和 GoogleMock EXPECT_CALL 在 Windows 中失败,在 Mac 上通过 char * param

c++ - 从 Swift 访问 C++ 枚举

c++ - 创建对象指针数组 C++

c++ - glGetError 和性能

java - Spring Bundlor 类似物

maven - 如何在maven antrun插件中执行输入任务

c++ - Gtest : capture output but print it on failure