0

I am trying to compile the following test application using CodeBlocks and CppUTest, however no matter what I do I always get the undefined reference error. I compiled CppUTest with cygwin, in codeblocks I use MinGW.

The project directory just has two files, main.cpp and tests.cpp, I am trying to get this to compile.

This is the main.cpp file:

#include "CppUTest/CommandLineTestRunner.h"
int main(int ac, char** av)
{
   return CommandLineTestRunner::RunAllTests(ac, av);
}

This is the tests.cpp file:

#include "CppUTest/TestHarness.h"
TEST_GROUP(FirstTestGroup)
{
};

TEST(FirstTestGroup, FirstTest)
{
   FAIL("Fail me!");
}
TEST(FirstTestGroup, SecondTest)
{
   STRCMP_EQUAL("hello", "world");
   LONGS_EQUAL(1, 2);
   CHECK(false);
}

I already have the libraries libCppUTest.a and libCppUTestExt.a, now I have to link them to the project. For this I've attempted the following:

  • In build options, add <CppUTest>\include\ to search directories for the compiler.
  • In build options, add <CppUTest>\lib\ to search directories for the linker.
  • In link settings, add libCppUTest.a and libCppUTestExt.a to link libraries. Also tried with the full path to these libraries.

I think the problem is not Codeblocks, because I've tried with every guide I've found to link the libraries and I always get undefined reference. I've also tried to add these as global settings but I get the same error, undefined reference.

Any ideas?

Mite
  • 57
  • 1
  • 9

1 Answers1

0

As pointed out by @Sreekar, the problem is that I was using MinGW in codeblocks and the libraries were compiled with cygwin. Changing the compiler to cygwin in Codeblocks fixed the issue for me.

This describes the process to change the compiler to cygwin in codeblocks if needed:

https://www.youtube.com/watch?v=oVmd0P85D8o

Mite
  • 57
  • 1
  • 9