2011-12-23 2 views
0

내 'Makefile'을 내 프로그램에 포함하려고 했으므로 어떻게 해결할 수 있었는지 조금 문제가 있습니다. 내 코드는 xcode에서 명령 줄 도구로 프로그램하면 작동하지만 SDL 라이브러리를 사용하여 응용 프로그램으로 프로그램하도록 선택하면 컴파일러 dosent가 생성 또는 내보내기 (.o) 파일을 ... 링커가 찾지 못합니다.C - C++ 프로그램 안에 메이크 파일 포함

내가지고있어 오류가 없습니다 : 메이크업 : AVR-GCC는 : 그런 파일이나 디렉토리 메이크업 : [main.o를] ​​오류 1 .APP을 마우스 오른쪽 버튼으로 클릭하여 *

및 패키지 내용보기 (View Package Contents)를 선택하면, 내부에있는 실행 파일은 .app dosent가됩니다.

내 코드는 다음과 같습니다

char cmd[1040]; 
char cwd[1024]; 
char path[1024]; 
char path2[1024]; 
int status; 
FILE *fp; 

char *path = NULL; 
    size_t sizes; 
    path = getcwd(path, sizes); 
    cout << path << endl; 



    if (getcwd(cwd, sizeof(cwd)) != NULL) 
    { 
     snprintf(cmd, sizeof(cmd), "make -C \"%s\" flash", path); 

     // i = system(cmd); 


     /* Open the command for reading. */ 

     fp = popen(cmd, "r"); 

     if (fp == NULL) { 

      cout << ("Failed to run command\n"); 


     } 


     /* Read the output a line at a time - output it. */ // So we can use it later 

     while (fgets(path2, sizeof(path2)-1, fp) != NULL) { 

      printf("Info: %s\n", path2); 
     } 

     /* close */ 

     status = pclose(fp); 


    } 
  • 컴파일러 Mac 용

http://www.obdev.at/products/crosspack/index.html

The makefile is :

######### AVR Project Makefile Template ######### 
######          ###### 
###### Copyright (C) 2003-2005,Pat Deegan, ###### 
######   Psychogenic Inc    ###### 
######   All Rights Reserved   ###### 
######          ###### 
###### You are free to use this code as part ###### 
###### of your own applications provided  ###### 
###### you keep this copyright notice intact ###### 
###### and acknowledge its authorship with ###### 
###### the words:        ###### 
######          ###### 
###### "Contains software by Pat Deegan of ###### 
###### Psychogenic Inc (www.psychogenic.com)" ###### 
######          ###### 
###### If you use it as part of a web site ###### 
###### please include a link to our site,  ###### 
###### http://electrons.psychogenic.com or ###### 
###### http://www.psychogenic.com    ###### 
######          ###### 
#################################################### 


##### This Makefile will make compiling Atmel AVR 
##### micro controller projects simple with Linux 
##### or other Unix workstations and the AVR-GCC 
##### tools. 
##### 
##### It supports C, C++ and Assembly source files. 
##### 
##### Customize the values as indicated below and : 
##### make 
##### make disasm 
##### make stats 
##### make hex 
##### make writeflash 
##### make gdbinit 
##### or make clean 
##### 
##### See the http://electrons.psychogenic.com/ 
##### website for detailed instructions 


#################################################### 
#####           ##### 
#####    Configuration    ##### 
#####           ##### 
##### Customize the values in this section for ##### 
##### your project. MCU, PROJECTNAME and  ##### 
##### PRJSRC must be setup for all projects, ##### 
##### the remaining variables are only   ##### 
##### relevant to those needing additional  ##### 
##### include dirs or libraries and those  ##### 
##### who wish to use the avrdude programmer ##### 
#####           ##### 
##### See http://electrons.psychogenic.com/ ##### 
##### for further details.      ##### 
#####           ##### 
#################################################### 


#####   Target Specific Details   ##### 
#####  Customize these for your project  ##### 

# Name of target controller 
# (e.g. 'at90s8515', see the available avr-gcc mmcu 
# options for possible values) 
MCU=atmega8 

# id to use with programmer 
# default: PROGRAMMER_MCU=$(MCU) 
# In case the programer used, e.g avrdude, doesn't 
# accept the same MCU name as avr-gcc (for example 
# for ATmega8s, avr-gcc expects 'atmega8' and 
# avrdude requires 'm8') 
PROGRAMMER_MCU=m8 

# Name of our project 
# (use a single word, e.g. 'myproject') 
PROJECTNAME=myproject 

# Source files 
# List C/C++/Assembly source files: 
# (list all files to compile, e.g. 'a.c b.cpp as.S'): 
# Use .cc, .cpp or .C suffix for C++ files, use .S 
# (NOT .s !!!) for assembly source code files. 
PRJSRC=main.c myclass.cpp lowlevelstuff.S 

# additional includes (e.g. -I/path/to/mydir) 
INC=-I/path/to/include 

# libraries to link in (e.g. -lmylib) 
LIBS= 

# Optimization level, 
# use s (size opt), 1, 2, 3 or 0 (off) 
OPTLEVEL=s 


#####  AVR Dude 'writeflash' options  ##### 
##### If you are using the avrdude program 
##### (http://www.bsdhome.com/avrdude/) to write 
##### to the MCU, you can set the following config 
##### options and use 'make writeflash' to program 
##### the device. 


# programmer id--check the avrdude for complete list 
# of available opts. These should include stk500, 
# avr910, avrisp, bsd, pony and more. Set this to 
# one of the valid "-c PROGRAMMER-ID" values 
# described in the avrdude info page. 
# 
AVRDUDE_PROGRAMMERID=stk500 

# port--serial or parallel port to which your 
# hardware programmer is attached 
# 
AVRDUDE_PORT=/dev/ttyS1 


#################################################### 
#####    Config Done    ##### 
#####           ##### 
##### You shouldn't need to edit anything  ##### 
##### below to use the makefile but may wish ##### 
##### to override a few of the flags   ##### 
##### nonetheless        ##### 
#####           ##### 
#################################################### 


##### Flags #### 

# HEXFORMAT -- format for .hex file output 
HEXFORMAT=ihex 

# compiler 
CFLAGS=-I. $(INC) -g -mmcu=$(MCU) -O$(OPTLEVEL) \ 
    -fpack-struct -fshort-enums    \ 
    -funsigned-bitfields -funsigned-char \ 
    -Wall -Wstrict-prototypes    \ 
    -Wa,-ahlms=$(firstword     \ 
    $(filter %.lst, $(<:.c=.lst))) 

# c++ specific flags 
CPPFLAGS=-fno-exceptions    \ 
    -Wa,-ahlms=$(firstword   \ 
    $(filter %.lst, $(<:.cpp=.lst))\ 
    $(filter %.lst, $(<:.cc=.lst)) \ 
    $(filter %.lst, $(<:.C=.lst))) 

# assembler 
ASMFLAGS =-I. $(INC) -mmcu=$(MCU)  \ 
    -x assembler-with-cpp   \ 
    -Wa,-gstabs,-ahlms=$(firstword \ 
     $(<:.S=.lst) $(<.s=.lst)) 


# linker 
LDFLAGS=-Wl,-Map,$(TRG).map -mmcu=$(MCU) \ 
    -lm $(LIBS) 

##### executables #### 
CC=avr-gcc 
OBJCOPY=avr-objcopy 
OBJDUMP=avr-objdump 
SIZE=avr-size 
AVRDUDE=avrdude 
REMOVE=rm -f 

##### automatic target names #### 
TRG=$(PROJECTNAME).out 
DUMPTRG=$(PROJECTNAME).s 

HEXROMTRG=$(PROJECTNAME).hex 
HEXTRG=$(HEXROMTRG) $(PROJECTNAME).ee.hex 
GDBINITFILE=gdbinit-$(PROJECTNAME) 

# Define all object files. 

# Start by splitting source files by type 
# C++ 
CPPFILES=$(filter %.cpp, $(PRJSRC)) 
CCFILES=$(filter %.cc, $(PRJSRC)) 
BIGCFILES=$(filter %.C, $(PRJSRC)) 
# C 
CFILES=$(filter %.c, $(PRJSRC)) 
# Assembly 
ASMFILES=$(filter %.S, $(PRJSRC)) 


# List all object files we need to create 
OBJDEPS=$(CFILES:.c=.o) \ 
    $(CPPFILES:.cpp=.o)\ 
    $(BIGCFILES:.C=.o) \ 
    $(CCFILES:.cc=.o) \ 
    $(ASMFILES:.S=.o) 

# Define all lst files. 
LST=$(filter %.lst, $(OBJDEPS:.o=.lst)) 

# All the possible generated assembly 
# files (.s files) 
GENASMFILES=$(filter %.s, $(OBJDEPS:.o=.s)) 


.SUFFIXES : .c .cc .cpp .C .o .out .s .S \ 
    .hex .ee.hex .h .hh .hpp 


.PHONY: writeflash clean stats gdbinit stats 

# Make targets: 
# all, disasm, stats, hex, writeflash/install, clean 
all: $(TRG) 

disasm: $(DUMPTRG) stats 

stats: $(TRG) 
    $(OBJDUMP) -h $(TRG) 
    $(SIZE) $(TRG) 

hex: $(HEXTRG) 


writeflash: hex 
    $(AVRDUDE) -c $(AVRDUDE_PROGRAMMERID) \ 
    -p $(PROGRAMMER_MCU) -P $(AVRDUDE_PORT) -e  \ 
    -U flash:w:$(HEXROMTRG) 

install: writeflash 

$(DUMPTRG): $(TRG) 
    $(OBJDUMP) -S $< > [email protected] 


$(TRG): $(OBJDEPS) 
    $(CC) $(LDFLAGS) -o $(TRG) $(OBJDEPS) 


#### Generating assembly #### 
# asm from C 
%.s: %.c 
    $(CC) -S $(CFLAGS) $< -o [email protected] 

# asm from (hand coded) asm 
%.s: %.S 
    $(CC) -S $(ASMFLAGS) $< > [email protected] 


# asm from C++ 
.cpp.s .cc.s .C.s : 
    $(CC) -S $(CFLAGS) $(CPPFLAGS) $< -o [email protected] 



#### Generating object files #### 
# object from C 
.c.o: 
    $(CC) $(CFLAGS) -c $< -o [email protected] 


# object from C++ (.cc, .cpp, .C files) 
.cc.o .cpp.o .C.o : 
    $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o [email protected] 

# object from asm 
.S.o : 
    $(CC) $(ASMFLAGS) -c $< -o [email protected] 


#### Generating hex files #### 
# hex files from elf 
##### Generating a gdb initialisation file ##### 
.out.hex: 
    $(OBJCOPY) -j .text     \ 
     -j .data      \ 
     -O $(HEXFORMAT) $< [email protected] 

.out.ee.hex: 
    $(OBJCOPY) -j .eeprom     \ 
     --change-section-lma .eeprom=0 \ 
     -O $(HEXFORMAT) $< [email protected] 


##### Generating a gdb initialisation file ##### 
##### Use by launching simulavr and avr-gdb: ##### 
##### avr-gdb -x gdbinit-myproject   ##### 
gdbinit: $(GDBINITFILE) 

$(GDBINITFILE): $(TRG) 
    @echo "file $(TRG)" > $(GDBINITFILE) 

    @echo "target remote localhost:1212" \ 
         >> $(GDBINITFILE) 

    @echo "load"  >> $(GDBINITFILE) 
    @echo "break main" >> $(GDBINITFILE) 
    @echo "continue" >> $(GDBINITFILE) 
    @echo 
    @echo "Use 'avr-gdb -x $(GDBINITFILE)'" 


#### Cleanup #### 
clean: 
    $(REMOVE) $(TRG) $(TRG).map $(DUMPTRG) 
    $(REMOVE) $(OBJDEPS) 
    $(REMOVE) $(LST) $(GDBINITFILE) 
    $(REMOVE) $(GENASMFILES) 
    $(REMOVE) $(HEXTRG) 



#####     EOF     ##### 
+0

여기서이 코드는 C++입니다. 태그 지정에서 약속 한대로? –

+1

makefile은 C, C++을 지원하지만 C 또는 C++을 사용하는 모든 솔루션을 언급했습니다. – John

+0

C 및 C++은 다른 언어입니다. 적절한 C 코드는 적절한 C++ 코드와 완전히 다릅니다 (RAII 및 일반 코드 만 참조). C++ 컴파일러를 구입할 여력이 있다면 C를 완전히 없애는 것이 어떻습니까? –

답변

0

그러한 종류의 버그를 디버그 할 수있는 방법은 예를 들어 make에 몇 가지 추가 플래그를 전달하는 것입니다. 그런 다음

const char *makeflags = getenv("MYMAKEFLAGS"); 
    if (makeflags) 
     snprintf(cmd, sizeof(cmd), "make -C \"%s\" %s flash", path, makeflags); 
    else 
     snprintf(cmd, sizeof(cmd), "make -C \"%s\" flash", path); 

당신 (가정 당신의 make은 GNU make가있다) 환경 변수

export MYMAKEFLAGS=--debug=b 

을 설정하여 일을 디버깅 할 수 그리고 난 당신의 OBJDEPS을하는해야 정말 계산할 수 있도록 기능을 patsubst GNU 사용합니다 OBJFILES, 예.

OBJFILES= \ 
     $(patsubst %.cc, %.o, $(CCFILES)) \ 
     $(patsubst %c, %.o, $(CFILES)) 
#etc 
+0

하지만 선생님, 어떻게 임플란트합니까? export MYMAKEFLAGS = - debug = b "?? 내 근원 안에 있니? – John

+0

소스 코드에 넣지 마십시오. 'make '를 수행하는 실행 파일을 실행하기 전에 터미널에 입력하기 만하면됩니다. –

+0

하지만 선생님, 저는 수동으로하지 않고 자동으로 처리하려고합니다. – John