-2

Actually I'm trying to compile a c/c++ project with mingw. The same project is actually compiled with visual studio compiler. For this purpose, I have written a makefile and everything works so far.

During compiling I get error regarding functions which are declared withing string.h and stdio.h like memcpy() , printf()..., with following error:

error: 'memcpy' was not declared in this scope

That's because the compiler didn't find the functions. When compiling within visual studio, this error didn't appear, logically, because of compiler include paths like:

c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\

My question now is: What should I do in my makefile to tell the compiler to use the "string.h" and "stdio.h" functions from the mingw. I tried to put the include path in the makefile, like:

 INCLUDE_DIRS =\
 C:\MinGW\include

but it has no effect. And also, there is a difference between the string.h and stdio.h from visual studio and string.h and stdio.h used by gcc. Can this be a problem?

Paul R
  • 208,748
  • 37
  • 389
  • 560
JohnDoe
  • 825
  • 1
  • 13
  • 31
  • Do you have `#include ` in your source file ? – Paul R Aug 19 '15 at 08:14
  • 2
    possible duplicate of [‘memcpy’ was not declared in this scope](http://stackoverflow.com/questions/24850479/memcpy-was-not-declared-in-this-scope) – Paul R Aug 19 '15 at 08:15
  • No, it is not included in the source file. So, this is the question, it is possible to force it via makefile? – JohnDoe Aug 19 '15 at 08:31
  • 2
    you should normally just #include all required headers, but some compilers (e.g. Visual Studio) all you to take a lazy approach (stdafx.h) - there may be a way to do this with gcc (?) but it's really the wrong solution - just add the required #includes. – Paul R Aug 19 '15 at 08:34

1 Answers1

0

The correct way would be to add these includes to the source files where you use methods which are defined in them. But if you insist to include it through the makefile, you can use force include.

Visual studio link.

To set this compiler option in the Visual Studio development environment Open the project's Property Pages dialog box.

Open Project Property Pages.

Click the C/C++ folder.

Click the Advanced property page.

Modify the Force Includes property.

or use -include path_to_the_header for gcc

Just add this option to the compilation command line. Good luck.

Alex Lop.
  • 6,810
  • 1
  • 26
  • 45