为Gtk制作文件 [英] make file for Gtk

查看:49
本文介绍了为Gtk制作文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个make文件,该文件先为所有源文件创建obj文件,然后为这些obj文件创建可执行文件(基本上是编译每个单独的文件,然后将它们链接在一起).

I have a make file, which creates obj files for all source files and then the executable using those obj files (basically compiling each individual file and then linking all of them together).

CC = gcc
SRC_DIR = src
INC_DIR = inc
OBJ_DIR = obj
CFLAGS = -c -Wall -I$(INC_DIR)
EXE = project

SRCS = $(SRC_DIR)/main.c $(SRC_DIR)/file1.c            # and so on...
OBJS = $(OBJ_DIR)/main.o $(OBJ_DIR)/file1.o            # and so on...

main : clean build

build:  $(OBJS)
    $(CC)   $(OBJS) -o $(EXE)

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
        $(CC) $(CFLAGS) -c $< -o $@

我尝试对gtk + 3.0执行相同的操作,但未成功,因为网络上的示例始终与示例文件有关,而不是整个项目(由多个源文件组成).例如:

I tried to do the same for gtk+3.0 but haven't been successful as the examples on the web always have been with respect to the example file and not the project as a whole (consisting multiple source files). one such eg:

$ cc `pkg-config --cflags --libs gtk+-3.0` hello.c -o hello

为gtk +制作文件是:

Make file for gtk+ is:

CC = gcc
SRC_DIR = .
INC_DIR = .
OBJ_DIR = Obj
CFLAGS = -Wall -g -o
PACKAGE = `pkg-config --cflags --libs gtk+-3.0`
LIBS = `pkg-config --libs gtk+-3.0`
EXE = Gui

SRCS = $(SRC_DIR)/main.c 
OBJS = $(OBJ_DIR)/main.o 

main : clean build       

build: $(OBJS)
    $(CC) $(OBJS) -o $(EXE)

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
        $(CC) $(PACKAGE) $(CFLAGS) $< -o $@ 

但这不起作用.它给出错误(对"gtk_init"和其他gtk函数的未定义引用)我该怎么做?

But this doesn't work. It gives errors (undefined reference to 'gtk_init' and other gtk functions) What modifications should i do?

推荐答案

CFLAGS 必须具有 -c ,或者编译.另外,在链接期间必须包含pkg-config.

The CFLAGS must have -c or that must be included while compiling. Also, the pkg-config must be included during linking.

更改后,make文件将变为:

After the changes, the make file becomes:

build: $(OBJS)
    $(CC) $(CFLAGS) $(OBJS) -o $(EXE) $(LIBS)

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
    $(CC) $(CFLAGS) ***-c*** -I$(INC_DIR) $< -o $@ $(PACKAGE)

更改成功运行.

这篇关于为Gtk制作文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆