0

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.

ChaoticWeg
  • 291
  • 2
  • 15
  • 1
    Generally you don't want to include a cpp file, just add it to your project and it will be compiled and linked. If you do include it then you have to exclude the actual file from being compiled. – Retired Ninja Nov 16 '13 at 21:59
  • *"functions that are defined in the resource file"* - Functions are never defined in resource files. What is this supposed to mean? – IInspectable Nov 16 '13 at 21:59
  • Calling .cpp files "resource files" and using #include on them certainly does get you into this kind of trouble. Review your favorite C++ language book about the difference between header files and source code files. – Hans Passant Nov 16 '13 at 21:59

1 Answers1

0

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.

john
  • 85,011
  • 4
  • 57
  • 81