Catch unit test library linking error

Sungmin

I am trying to use CATCH unit test suite linked below. https://github.com/philsquared/Catch

However, I cannot succeed to make it right. The main.cpp and test.cpp are as follows.

//main.cpp
#define CATCH_CONFIG_MAIN 
#include "catch.hpp"

//test.cpp
#include "catch.hpp"

TEST_CASE("TESTTest", "") {
    CHECK(1 != 2 );
}

When this two files are located in the same folder, I could get a desired result. However, I moved the test.cpp to the subdirectory named test. It does not work anymore as expected but generates linking errors.

My cmake setting is described below.

project(catchTest)
cmake_minimum_required(VERSION 2.8)

file(GLOB_RECURSE INCS "./*.cpp")
add_executable(${PROJECT_NAME} main.cpp ${INCS})

include_directories(.)

file(GLOB_RECURSE INCS "./*.cpp") was added to include every cpp source files located in the subdirectories. and include_directories(.) was included to let them know the definition of catch.hpp.

I am pretty shure I've done something wrong but I don't know how to fix it. Please advise me to solve this problem.

It was run on Windows, compiled using mingw gcc-4.9.1 and generated by cmake ninja generator.

EDIT : I added the first few lines of error messages.

FAILED: cmd.exe /c cd . && C:\MinGW\bin\g++.exe CMakeFiles/catchTest.dir/main.cpp.obj CMakeFiles/catchTest.dir/main.cpp.obj CMakeFiles/catchTest.dir/test/testTest.cpp.obj -o catchTest.exe -Wl,--out-implib,libcatchTest.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd . CMakeFiles/catchTest.dir/main.cpp.obj:main.cpp:(.text+0x0): multiple definition of `Catch::getResultCapture()'

CMakeFiles/catchTest.dir/main.cpp.obj:main.cpp:(.text+0x0): first defined here

KimKulling

Your CMakeLists.txt is wrong, it includes main twice. If you change the add_executable-statement like this it works for me:

add_executable(${PROJECT_NAME} main.cpp test.cpp )

Hope that helps.

Kim

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Linking error in unit test using URLRequestConvertible

From Dev

Error linking test-suite to library

From Dev

Mocha Unit Test Error Handling from Library

From Dev

cimg library - linking error

From Dev

error linking GMP library

From Dev

error linking GMP library

From Dev

Boost unit test dynamic linking on Ubuntu

From Dev

Error linking discount library with Qt

From Dev

ImageMagic library with Cmake: linking error

From Dev

Boost Unit Test: Catch an unsuccessful Test

From Dev

OCMock unit test error

From Dev

How to unit test try-catch block?

From Dev

How to unit test the catch body of my Observable

From Dev

Promise.catch() does not catch exception in AngularJS unit test

From Dev

Promise.catch() does not catch exception in AngularJS unit test

From Dev

Library linking error: undefined reference to _imp__

From Dev

Solving undefined reference library linking error in gcc

From Dev

osx - Linking error, when building POCO library

From Dev

How to test the catch block code in Spock unit test Grails

From Dev

How to unit test a library that uses JNI?

From Dev

Class Library (UWP) unit test not being run

From Dev

AngularJS Unit Test Error dependence

From Dev

VSTS Unit test error message

From Dev

Error in test method in mvc for routing unit test

From Dev

Moq / Unit Test Unable to Catch Exception unless stepping through code

From Dev

How do I fail a Node unit test on the catch of a Promise?

From Dev

Catch.hpp unit testing: How to dynamically create test cases?

From Dev

Force error on unresolved symbols while linking static library

From Dev

Linking error "undefined reference" about boost static library during compiling

Related Related

HotTag

Archive