objective-c - 在 Mac OS 的终端中编译 Objective-C

标签 objective-c c macos makefile

我对编写 makefile 和 Objective-C 语言都很陌生。我正在尝试使用此 Makefile 编译一个小型测试应用程序:

Q = @
INCLUDE_PREF = -I

CC := gcc 

#Here the source files are specified

list_src_files = $(shell find . -type f -name "*.m")
SRCS := $(subst ./,,$(call list_src_files))

#Here is our include files

list_include_dirs = $(shell find . -type d -name "include")
INCLUDE_LS := $(call list_include_dirs)
INCLUDE_DIRS := $(INCLUDE_PREF).
INCLUDE_DIRS += $(addprefix $(INCLUDE_PREF), $(subst ./,,$(INCLUDE_LS)))

#Flags used with gcc

CFLAGS = -Wall -fobjc-arc -framework Foundation -g -O0 $(INCLUDE_DIRS)

#Here all object files are specified

OBJS := $(SRCS:%.m=%.o)

#Here is the name of target specified

TARGET := Convertor

#Here is our target

$(TARGET): $(OBJS)
           @echo "Building target"
           $(Q)$(CC) $(CFLAGS) $^ -o $@

%.o: %.m 
     @echo "Building objects"
     $(Q)$(CC) $(CFLAGS) -c $< -o $@

.PHONY: clean

clean:
      $(Q)-rm $(OBJS) $(TARGET) 2>/dev/null || true

我要编译的代码是:

#import <Foundation/Foundation.h>


#define DEBUG
#define VALID_PARMS_NBR   3   

#ifdef DEBUG
# define dbg(fmt, ...) NSLog((@"%s " fmt), __PRETTY_FUNCTION__,  ##__VA_ARGS__)
#else
# define dbg(...)
#endif



int main (int argc, char *argv[])
{
  if (argc < VALID_PARMS_NBR) {
    NSLog(@"Usage of this program is: prog_name arg1 arg2");
  } else {
    dbg(@"Parameters: %s, %s, %s\n", argv[0], argv[1], argv[2]);
  }


  return 0;
}

警告编译器每次都向我抛出:

clang: warning: -framework Foundation: 'linker' input unused

能否请您指出我在 Makefile 中哪里出错了?为什么会出现这个警告?

我正在浏览类似的问题,但没有任何效果。

最佳答案

警告表明未使用 Foundation 框架语句,可以将其删除:

CFLAGS = -Wall -fobjc-arc -g -O0 $(INCLUDE_DIRS)

CFLAGS 行中删除它应该可以解决问题。

警告就是这样——警告您可能不一定是问题,但需要注意的行为。尽管如此,该程序仍然可以编译,尽管您有修复它的心态是件好事。

关于objective-c - 在 Mac OS 的终端中编译 Objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32199232/

相关文章:

objective-c - 异步请求示例

objective-c - 如何将 Facebook 粉丝页面集成到 iPhone 应用程序中?

objective-c - iOS iPad UIActionSheet问题

c - 使用 RegGetValue 显示值的数据

c - 为什么 OSX 命令行中使用 Bash

android - 在 Mac OS 上的 eclipse 3.4.1 中运行 Junit 测试的问题

android - 尝试使用 adb 推送/安装 .apk 时出错

ios - CBCentralManagerDelegate 没有在 NSObject 中被调用

c++ - 代码风格 : Reuse of a control expression or control variable in the branch of a switch/if statement

彩色 readline 提示符会中断 control-a