【发布时间】:2015-08-19 08:12:52
【问题描述】:
实际上我正在尝试使用 mingw 编译一个 c/c++ 项目。同一个项目实际上是用 Visual Studio 编译器编译的。为此,我编写了一个 makefile,到目前为止一切正常。
在编译过程中,我收到关于使用 string.h 和 stdio.h 声明的函数的错误,例如 memcpy() 、 printf()...,并出现以下错误:
error: 'memcpy' was not declared in this scope
那是因为编译器没有找到函数。在 Visual Studio 中编译时,逻辑上没有出现此错误,因为编译器包含如下路径:
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\
我现在的问题是: 我应该在我的 makefile 中做什么来告诉编译器使用 mingw 中的“string.h”和“stdio.h”函数。我尝试将包含路径放在makefile中,例如:
INCLUDE_DIRS =\
C:\MinGW\include
但它没有效果。 此外,Visual Studio 中的 string.h 和 stdio.h 与 gcc 使用的 string.h 和 stdio.h 之间存在差异。这会是个问题吗?
【问题讨论】:
-
你的源文件中有
#include <string.h>吗? -
不,它不包含在源文件中。那么,这就是问题所在,是否可以通过 makefile 强制执行?
-
你通常应该只#include所有必需的头文件,但是一些编译器(例如Visual Studio)你需要采取一种懒惰的方法(stdafx.h) - 可能有一种方法可以使用gcc( ?) 但这确实是错误的解决方案 - 只需添加所需的#includes。