Question

I have two files for a project I'm working on, one of my own writing and one written by a fellow student to serve as a sort of API. My problem is, the functions that are defined in the resource file are causing linker errors in VS2012.

I'm getting error LNK2005, which Microsoft defines as:

symbol already defined in object

The given symbol, displayed in its decorated form, was multiply defined.


The three functions defined in the resource file, ArgvFunctions.cpp, are:

void convertCommandToArgv(char* commandString, char** argv[], int* argc);
void freeDynamicallyAllocatedArgv(char* argv[], int argc);

void doMain(int argc, char* argv[]);
/* renamed from "main" to avoid error. is never called: only shows implementation */

and the #includes in my implementation file:

#include <ios>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

#include "bmpfileheaders.h"  // no problems with this one
#include "ArgvFunctions.cpp"

In case it helps: before I encountered this problem, I had to suppress errors raised by ArgvFunctions.cpp that were due to the fact that the functions therein use the versions of strtok() and strncpy() that Microsoft deprecated due to security issues (I'm making sure that nothing passed to the functions could trip them up, as nearly as I can tell, so those issues wouldn't be a problem either way; also, I don't have the time or the knowledge to replace strtok() with strtok_s() and et cetera).


EDIT:

whoops, turns out I know nothing about C++. Thanks, all.

Was it helpful?

Solution

This is the mistake

#include "ArgvFunctions.cpp"

remove that line. If you still have errors then ask again. It's never correct to include one cpp file in another cpp file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top