2012-07-18 48 views
0

我想編譯一個非常簡單的程序,我不明白它爲什麼不編譯。這裏是我的程序:C30 PIC編譯器無法編譯(MPLAB-X IDE)

/* General includes */ 
#include <stdio.h> 
#include <stdlib.h> 
#include <libpic30.h> 
#include <p33FJ128GP804.h> 

#include "RunLengthAlgorithm.h" 
//#include "RunLengthAlgorithm.c" 

int main(void) { 

    int n; 
    char source[10001]; 
    char target[100]; 

    for(n = 0; n < 1000; ++n){ 
     source[n] = "A"; 
    } 
    for(n = 1000; n < 2000; ++n){ 
     source[n] = "B"; 
    } 
    for(n = 2000; n < 3000; ++n){ 
     source[n] = "C"; 
    } 
    for(n = 3000; n < 4000; ++n){ 
     source[n] = "D"; 
    } 
    for(n = 4000; n < 5000; ++n){ 
     source[n] = "E"; 
    } 
    for(n = 5000; n < 6000; ++n){ 
     source[n] = "F"; 
    } 
    for(n = 6000; n < 7000; ++n){ 
     source[n] = "G"; 
    } 
    for(n = 7000; n < 8000; ++n){ 
     source[n] = "H"; 
    } 
    for(n = 8000; n < 9000; ++n){ 
     source[n] = "I"; 
    } 
    for(n = 9000; n < 10000; ++n){ 
     source[n] = "J"; 
    } 
    source[10001] = '\0'; 

    RLEncode(&source, &target); 

    while(1); 
    return (EXIT_SUCCESS); 

} 

.h和.c文件被添加到項目中。

#ifndef RUNLENGTHALGORITHM_H 
#define RUNLENGTHALGORITHM_H 

void RLEncode (char *source, char *target); 

#endif 

而.c文件:

#ifndef RUNLENGTHALGORITHM_C 
#define RUNLENGTHALGORITHM_C 
void RLEncode (char *source, char *target){ 
    int n, k = 0; 
    for(n = 0; source[n] != '\0'; ++n){ 
     int length = 1; 
     while(source[n+1] != '\0' && source[n] == source[n+1]){ 
      ++length; ++n; 
     } 
     target[k++] = length; 
     target[k++] = source[n]; 
    } 
    source[n] = '\0'; 
} 

#endif 

我使用的MPLAB-X IDE蒙山C30編譯器,它給我這個錯誤:

CLEAN SUCCESSFUL (total time: 1s) 
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf 
make[1]: Entering directory `D:/Datos (Disco)/Electronica/Multi portatil/Run-Length Algorithm.X' 
make -f nbproject/Makefile-default.mk dist/default/production/Run-Length_Algorithm.X.production.hex 
make[2]: Entering directory `D:/Datos (Disco)/Electronica/Multi portatil/Run-Length Algorithm.X' 
Main.c: In function 'main': 
Main.c:24: warning: assignment makes integer from pointer without a cast 
Main.c:27: warning: assignment makes integer from pointer without a cast 
Main.c:30: warning: assignment makes integer from pointer without a cast 
Main.c:33: warning: assignment makes integer from pointer without a cast 
Main.c:36: warning: assignment makes integer from pointer without a cast 
Main.c:39: warning: assignment makes integer from pointer without a cast 
Main.c:42: warning: assignment makes integer from pointer without a cast 
Main.c:45: warning: assignment makes integer from pointer without a cast 
Main.c:48: warning: assignment makes integer from pointer without a cast 
Main.c:51: warning: assignment makes integer from pointer without a cast 
Main.c:55: warning: passing argument 1 of 'RLEncode' from incompatible pointer type 
Main.c:55: warning: passing argument 2 of 'RLEncode' from incompatible pointer type 
"C:\Program Files (x86)\Microchip\MPLAB C30\bin\pic30-gcc.exe" -g -omf=elf -x c -c -mcpu=33FJ128GP804 -MMD -MF build/default/production/Main.o.d -o **build/default/production/Main.o Main.c 
"C:\Program Files (x86)\Microchip\MPLAB C30\bin\pic30-gcc.exe" -g -omf=elf -x c -c -mcpu=33FJ128GP804 -MMD -MF build/default/production/RunLengthAlgorithm.o.d -o build/default/production/RunLengthAlgorithm.o RunLengthAlgorithm.c 
"C:\Program Files (x86)\Microchip\MPLAB C30\bin\pic30-gcc.exe" -omf=elf -mcpu=33FJ128GP804 -o dist/default/production/Run-Length_Algorithm.X.production.elf build/default/production/Main.o build/default/production/RunLengthAlgorithm.o build/default/production/RunLengthAlgorithm.o  -Wl,--defsym=__MPLAB_BUILD=1,-Tp33FJ128GP804.gld 
build/default/production/RunLengthAlgorithm.o(.text+0x0): In function `_RLEncode': 
: multiple definition of `_RLEncode' 
build/default/production/RunLengthAlgorithm.o(.text+0x0): first defined here 
c:\program files (x86)\microchip\mplab c30\bin\bin\..\bin/pic30-elf-ld.exe: Link terminated due to previous error(s).** 
make[2]: Leaving directory `D:/Datos (Disco)/Electronica/Multi portatil/Run-Length Algorithm.X' 
make[1]: Leaving directory `D:/Datos (Disco)/Electronica/Multi portatil/Run-Length Algorithm.X' 
**make[2]: *** [dist/default/production/Run-Length_Algorithm.X.production.hex] Error 255 
make[1]: *** [.build-conf] Error 2 
make: *** [.build-impl] Error 2 

BUILD FAILED (exit value 2, total time: 8s)** 

我不明白爲什麼,如果我把我的函數放在Main.c中,並且不包含#include「RunLengthAlgorithm.h」,它可以工作,但是我無法使它運行,包括一個文件。

回答

0

我認爲這個問題與內存映射有關。根據所使用的處理器系列,您應該重新定義.gld或.lkr文件中堆棧的大小。當你聲明具有非常大的內存位置的變量源時,堆棧正在溢出。

0

當你「#include _your_func.h」你的函數,然後使用IDE> Projects> sourcefiles> Add existing item手動包含包含函數的文件時,會發生這種情況。其足以做任何一個這些。