Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Objective-C in terminal on Mac OS

I am quite new to both writing a makefiles and Objective-C language. I am trying to compile a small test application with this 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

The code I am trying to compile is:

#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;
}

The warning compiler is throwing me everytime:

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

Could you, please, point me, where I did mistake in a Makefile? And why this warning appears?

I was looking through the similar questions, but nothing worked.

like image 492
user1415536 Avatar asked Jan 22 '26 08:01

user1415536


1 Answers

The warning indicates the Foundation framework statement isn't used, and can be removed:

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

Removing it from the CFLAGS line should resolve things.

Warnings are just that — to warn you about behavior that might not necessarily be a problem, but something to be aware of. Despite this the program might compile anyway, although it's good that you have the mindset to fix it.

like image 180
l'L'l Avatar answered Jan 24 '26 10:01

l'L'l