【问题标题】:Compiling Objective-C in terminal on Mac OS在 Mac OS 的终端中编译 Objective-C
【发布时间】:2015-11-18 21:01:31
【问题描述】:

我对编写 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 中的错误之处?为什么会出现此警告?

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

【问题讨论】:

    标签: objective-c c macos makefile


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-12
      • 1970-01-01
      • 2017-06-09
      • 2014-12-16
      • 2011-05-19
      • 1970-01-01
      相关资源
      最近更新 更多