Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 99023

Getting 'multiple definition' error and I have no clue why [duplicate]

$
0
0

I know this is a common and frequent question. I'm working on visual-studio-code and using code-runner extension for convenience. My project working tree is the following:

enter image description here

I'm trying to compile serial.cc (the main) using the following code-runner setting taking a cue from what is stated here:

"cpp": "cd $dir && g++ -Wall -fopenmp $fileName utilities/*.cc -o $fileNameWithoutExt.o && $dir$fileNameWithoutExt.o"

Here's the following files includes:

  • serial.cc #include "utilities/CSVIterator.h"
  • CSVIterator.h #include "CSVRow.h"
  • CSVRow.h #include "utility.h"

What I get is a 'multiple definition' error triggered by CSVRow.cc and utility.cc listing a series of functions (namely every function defined inline -not actually using inline keyword- inside utility.h) that the compiler sees already defined into serial.cc . E.g. inside utility.h I have:

double cpuSecond()
{
    struct timeval tp;
    gettimeofday(&tp, NULL);
    return ((double)tp.tv_sec + (double)tp.tv_usec * 1.e-6);
}

Problem is fixed if:

  1. I define EVERY function inside the corresponding .cc file.
  2. I move EVERY function inside the corresponding .h file and so removing every source file apart from the main one (serial.cc).

I understand this is too little to understand so here's the full GitHub Repo. Thanks in advance.


Viewing all articles
Browse latest Browse all 99023

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>