Visual Studio认为功能已经定义
Visual Studio thinking that functions are already defined?
我正在从事的一个项目有两个文件,一个是我自己写的,一个是同学写的,作为一种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 文件中是绝对不正确的。
相关文章:
- 类模板的成员功能的定义在单独的TU中完全专业化
- C++ - 没有自定义交换功能的移动分配运算符?
- 如何定义可变参数类模板的成员模板功能
- '_HAS_CXX17'宏是否可用于自定义项目标头以启用C++17 语言集功能?
- C++模板功能并定义特定情况
- 这种错误的原因是什么:将"功能"重新定义为不同类型的符号
- 功能原型,没有定义
- 如何在cmake工具链文件中设置编译功能,以便已知的自定义编译器使用target_compile_features
- 如何在C 17中定义功能组成
- 如何自定义功能行为
- 在多态性中重新定义功能(虚拟),具有不同数量的参数
- 定义功能,以便它可以接受列表或向量
- 如何在自定义功能中使用C 构建器OpenArray
- 用户定义功能的返回值的分配:性能
- 使用自己的结构在标题类中定义功能
- 自定义功能不返回正确的值
- 全部使用用户自定义功能和MPI_BOTTOM
- 如何正确定义功能并实现它们
- 重新定义功能
- c++共享库定义和取消定义功能