Visual Studio认为功能已经定义

Visual Studio thinking that functions are already defined?

本文关键字:定义 功能 Studio Visual      更新时间:2023-10-16

我正在从事的一个项目有两个文件,一个是我自己写的,一个是同学写的,作为一种API。我的问题是,资源文件中定义的函数导致VS2012中的链接器错误。

我收到错误LNK2005,Microsoft将其定义为:

已在对象中定义的符号

给定的符号,以其装饰形式显示,被乘以定义。


资源文件中定义的三个函数 ArgvFunctions.cpp 是:

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 */

以及我的实现文件中的#includes

#include <ios>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "bmpfileheaders.h"  // no problems with this one
#include "ArgvFunctions.cpp"

如果有帮助:在遇到此问题之前,我必须抑制ArgvFunctions.cpp引发的错误,这些错误是由于其中的函数使用由于安全问题而Microsoft弃用的strtok()strncpy()版本(我确保传递给函数的任何内容都不会使它们绊倒, 据我所知,这些问题无论如何都不是问题;另外,我没有时间或知识用strtok_s()等替换strtok())。


编辑:

哎呀,原来我对C++一无所知。谢谢大家。

这是

错误

#include "ArgvFunctions.cpp"

删除该行。如果仍然有错误,请再次询问。将一个 cpp 文件包含在另一个 cpp 文件中是绝对不正确的。