You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Linux下的GCC编写适配mycode项目的简单Makefile?

Simple Makefile for Your libstrophe Project

Got it, let's turn that manual gcc command into a reusable Makefile that's easy to maintain. Here's a straightforward implementation that matches your compilation setup:

# Define the compiler to use
CC = gcc

# Compiler flags: include libstrophe's compile flags via pkg-config
CFLAGS = `pkg-config --cflags libstrophe`

# Linker flags: include libstrophe's libraries + pthread
LIBS = `pkg-config --libs libstrophe` -lpthread

# The target executable
TARGET = mycode

# Build the target when running `make`
$(TARGET): mycode.c mycode.h
	$(CC) $(CFLAGS) -o $@ $< $(LIBS)

# Clean up the executable when running `make clean`
.PHONY: clean
clean:
	rm -f $(TARGET)

How it works:

  • CC: Sets the compiler to gcc, which matches your original command.
  • CFLAGS: Captures libstrophe's required compile flags using pkg-config --cflags libstrophe, just like your manual command.
  • LIBS: Combines libstrophe's libraries (pkg-config --libs libstrophe) with the pthread library you need.
  • $(TARGET): The main rule tells Make to build mycode from your source and header files. $@ refers to the target (mycode), and $< refers to the first dependency (mycode.c).
  • clean: A helper rule to delete the compiled executable, useful for cleaning up your project directory. The .PHONY line ensures Make doesn't confuse a file named clean with the rule.

Usage:

  • Run make in your project directory to compile your code into the mycode executable.
  • Run make clean to remove the mycode executable.

This Makefile keeps things simple while staying true to your original compilation command, and it's easy to tweak later if you add more source files or need to adjust flags.

内容的提问来源于stack exchange,提问作者Abdeslam ben issa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:34:29