Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link error (multiple definition...) in simple project #470

Closed
sktpin opened this issue Feb 12, 2021 · 2 comments
Closed

Link error (multiple definition...) in simple project #470

sktpin opened this issue Feb 12, 2021 · 2 comments

Comments

@sktpin
Copy link

sktpin commented Feb 12, 2021

Description

I used Eclipse 2020 CDT on a Windows host, using the cross tool chain "gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf" to compile for RaspberryPi as a target.
Set up a managed build project with above mentioned compiler set up as cross compiler.
This generally works for other projects.

So now I added the doctest folder to the project (by copy) and added it to the known include paths.
I made 2 source files: main.cpp, which contains nothing but #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN and including doctest.h, and, in subfolder "tests", a file Test01.cpp, which contains only the include to doctest, not the macro, as described in the tutorial.
I then added one testcase, which prints one std::cout line,
with one subcase, which does the same, while doing one REQUIRES on a constant, and one CHECK, checking one local static function call for a result.

I then built the project, generating a bunch of linker errors, e.g. for "multiple definition" of:

  • doctest::is_running_in_test';: in function doctest::detail::my_memcpy
  • doctest::detail::g_oss[abi:cxx11]'; in function __tls_init'
  • doctest::detail::rawMemoryToString

... and a couple pages more of that

Steps to reproduce

main.cpp:

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"

Test01.cpp:

#include "doctest.h"

#include <iostream>
using namespace std;

static const int xyz = 123;

static int func(int i)
{	return xyz * i;
}

TEST_CASE("testcase01")
{
	cout << "testcase" << endl;

	SUBCASE("subcaseA")
	{
		cout << "subcase" << endl;

		REQUIRE( xyz == 123 );
		CHECK( func(2) == 2*123 );
	}
}

Extra information

I searched the net and found some people with that problem.
It seems to be very dependent on the exact compiler tool chain being used, incl. specific target, and how the linking works exactly.

  • doctest version: v2.4.5
  • Operating System: Windows 10 (cross compile host), Linux for ARMv7, hardfloat (target)
  • Compiler+version: gcc-arm-9.2-2019.12-mingw-w64-i686-arm-none-linux-gnueabihf
    this toolchain
@onqtam
Copy link
Member

onqtam commented Feb 18, 2021

Strange... I'm not sure how to help you with this. Make sure that you aren't compiling main.cpp more than once (or that you aren't linking the object file from it more than once) - perhaps you should inspect the verbose output of the build and see which object files are being compiled and what is being linked - with the full commands.

@sktpin
Copy link
Author

sktpin commented Mar 10, 2021

D'OH! I had just thrown that into a folder of some little test project with Eclipse managed build.
And forgot about this otherwise time-saving default behavior of Eclipse of adding everthing to the list of compiled things that it finds in the tree, unless you explicitly state e.g. a folder should be "exclude from build" ;)

@sktpin sktpin closed this as completed Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants