在Windows 7中使用MinGW-w64编译C代码时出错

时间:2015-02-23 17:21:49

标签: c makefile mingw mingw-w64

我试图从为MinGW编写的回溯项目https://code.google.com/p/backtrace-mingw/编译代码,但是使用MinGW-w64。

我的旧安装和全新安装的MinGW-w64会产生同样的问题。 Path在路径变量中设置,也在命令提示符中设置:

C:\ mingw-w64 \ i686-4.9.2-win32-sjlj-rt_v3-rev1 \ mingw32 \ bin

C:\ mingw-w64 \ i686-4.9.2-win32-sjlj-rt_v3-rev1 \ mingw32 虽然不需要这个。

这是该项目的makefile:

.PHONY: all clean

all : backtrace.dll test.exe

backtrace.dll : backtrace.c
    gcc -O2 -shared -Wall -o $@ $^ -lbfd -lintl -liberty -limagehlp

test.exe : test.c
    gcc -g -Wall -o $@ $^

clean :
    -del -f backtrace.dll test.exe

编译时我收到警告:

backtrace.c:23:17:致命错误:bfd.h:没有这样的文件或目录#include< bfd.h>`

这很奇怪,因为该文件存在于 ../ mingw32 / include 文件夹中。

如果我在compilind dll时添加这个: -IC:\ mingw-w64 \ i686-4.9.2-win32-sjlj-rt_v3-rev1 \ mingw32 \ include 它会继续但​​是停在指令: #error config.h必须包含在此标题之前且MinGW-w64中缺少config.h

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

ming包含路径中的路径是明确缺少的。我不知道为什么。您必须以自己喜欢的方式自行添加:cmake recipe,autoconf recipe,CFLAGSCPATHgcc specs

而且,据我记忆,它仅使用HAVE_STRINGIZE中的config.h宏,并且仅用于定义CONCAT4宏,bfd.h宏未用于#define PACKAGE package {1}}。所以,欺骗一点安全

是安全的

bfd.h

包括package com.oplo.user.demo2; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.StrictMode; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; /** * Created by user on 6/2/2015. */ @SuppressWarnings("deprecation") public class addRecord extends Activity { @SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add); if(android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } final EditText txtA = (EditText) findViewById(R.id.txtA); final EditText txtB = (EditText) findViewById(R.id.txtB); final EditText txtC = (EditText) findViewById(R.id.txtC); final Button getData = (Button) findViewById(R.id.btnSave); final Button btnBack = (Button) findViewById(R.id.btnBack); btnBack.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent i = new Intent(getApplicationContext(), MainActivity.class); startActivity(i); } }); getData.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if(txtA.getText().length()<2){ Toast.makeText(getApplicationContext(), "Input Name", Toast.LENGTH_LONG).show(); }if(txtB.getText().length()<2){ Toast.makeText(getApplicationContext(), "Input Price", Toast.LENGTH_LONG).show(); }if(txtC.getText().length()<2){ Toast.makeText(getApplicationContext(), "Input Description", Toast.LENGTH_LONG).show(); }else{ String url = "http://www.xyz.in/demo.php"; List params = new ArrayList(); //noinspection deprecation params.add(new BasicNameValuePair("strA", txtA.getText().toString())); params.add(new BasicNameValuePair("strB", txtB.getText().toString())); params.add(new BasicNameValuePair("strC", txtC.getText().toString())); @SuppressWarnings("unused") String resultServer = getHttpPost(url,params); //result.setText(resultServer); Toast.makeText(addRecord.this, "1 Record inserted...", Toast.LENGTH_LONG).show(); emtyText(); txtA.requestFocus(); } } public void emtyText(){ txtA.setText(""); txtB.setText(""); txtC.setText(""); } }); } public String getHttpPost(String url,List params) { StringBuilder str = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); try { httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpResponse response = client.execute(httpPost); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { // Status OK HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { str.append(line); } } else { Log.e("Log", "Failed to download result.."); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return str.toString(); } }

之前

答案 1 :(得分:-1)

将它添加到compile语句的末尾:

-I./mingw32/include

所以整个编译语句将是:

gcc -g -Wall -o $@ $^ -I./mingw32/include

所以编译器知道在哪里找到包含文件