2015-08-19 32 views
-2

其實我試圖用mingw編譯c/C++項目。同樣的項目實際上是用visual studio編譯器編譯的。爲此,我已經寫了一個makefile,並且一切工作到目前爲止。當使用gcc編譯器時,'memcpy'未在此範圍內聲明

在編譯期間我得到關於該聲明withing 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告訴編譯器使用「 string.h「和」stdio.h「函數。我試圖把包含路徑放在makefile中,例如:

INCLUDE_DIRS =\ 
C:\MinGW\include 

但它沒有效果。 而且,visual studio的string.h和stdio.h和gcc使用的string.h和stdio.h是有區別的。這可能是一個問題嗎?

+0

你在源文件中有#include 嗎? –

+2

['memcpy'可能重複未在此範圍內聲明](http://stackoverflow.com/questions/24850479/memcpy-was-not-declared-in-this-scope) –

+0

不,它不包含在源文件。所以,這是一個問題,可以通過makefile強制它? – JohnDoe

回答

0

正確的方法是將這些包含的內容添加到使用其中定義的方法的源文件中。 但是如果你堅持要通過makefile包含它,你可以使用強制包含

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.

或使用-include path_to_the_headergcc

只需將此選項添加到編譯命令行。祝你好運。