2017-04-23 13 views
-1

UNIX 환경에서 컴파일을 시도하고이 오류가 계속 발생합니다. 그러나, 내가 가진 모든 것은 파일의 주요 기능입니까? 어떤 아이디어? 이것은 내가 다른 파일에서 오류가 발생했을 때부터 가지고있는 유일한 코드이며 헤더 파일이 포함되어있을 경우 주요 기능으로 컴파일을 테스트하기로 결정했습니다. 난 헤더 파일에 대한 include 문을 제거하고 잘 컴파일됩니다. gcc filename headfilename을 시도해 보았습니다.하지만 차이가 나는지 알아보기 위해서입니다. 헤더 파일은 같은 폴더에 있습니다.'main'에 대한 정의되지 않은 참조 - collect2 : 오류 : ld가 1 종료 상태를 반환했습니다.

아이디어가 있으십니까?

In function `_start': 
(.text+0x18): undefined reference to `main' 
collect2: error: ld returned 1 exit status 

다음 줄에 컴파일 : gcc가 TriePrediction.c

나는 또한 시도

#include "TriePrediction.h" 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <ctype.h> 


int main(int argc, char **argv) 
{ 
    return 0; 
} 

이것은 내가 무엇입니까 정확한 오류는 다음과 같습니다

코드입니다 :

gcc TriePrediction.c TriePrediction.h 

주요 기능은 TriePrediction.c

이 헤더 파일입니다

에 있습니다

참고 : 나는 파일의 컴파일 이유로 기능을 설정 한 장소를 제거 그래서 그 그러나, 잘못 알고, 정의되지 않은 참조 오류로 인해 컴파일 작업이 엉망이되는지 확인하기 위해 작업을 수행했습니다.

#ifndef __TRIE_PREDICTION_H 
#define __TRIE_PREDICTION_H 

#define MAX_WORDS_PER_LINE 30 
#define MAX_CHARACTERS_PER_WORD 1023 

// This directive renames your main() function, which then gives my test cases 
// a choice: they can either call your main() function (using this new function 
// name), or they can call individual functions from your code and bypass your 
// main() function altogether. THIS IS FANCY. 
#define main demoted_main 

typedef struct TrieNode 
{ 
    // number of times this string occurs in the corpus 
    int count; 

    // 26 TrieNode pointers, one for each letter of the alphabet 
    struct TrieNode *children[26]; 

    // the co-occurrence subtrie for this string 
    struct TrieNode *subtrie; 
} TrieNode; 


// Functional Prototypes 

TrieNode *buildTrie(char *filename); 

TrieNode *destroyTrie(TrieNode *root); 

TrieNode *getNode(TrieNode *root, char *str); 

void getMostFrequentWord(TrieNode *root, char *str); 

int containsWord(TrieNode *root, char *str); 

int prefixCount(TrieNode *root, char *str); 

double difficultyRating(void); 

double hoursSpent(void); 

#endif 
+0

정확한 빌드 명령을 표시하십시오. – kaylum

+0

문제가있는 헤더 파일에서'main'을 재정의하는 매크로가 있습니까? – InternetAussie

+0

@kaylum 업데이트 됨 – starlight

답변

1

헤더 기능은이 프로그램이 주 기능이없는 및 GCC와 연결되지 않을 수 있다는 것을 의미한다 demoted_mainmain을 정의한다. 프로그램을 올바르게 링크하려면 해당 행을 제거해야합니다. 링커 옵션을 사용하여 demoted_main을 엔트리 포인트로 사용할 수도 있습니다. gcc -o TriePrediction.c TriePrediction.h -Wl,-edemoted_main -nostartfiles으로 가능하지만 권장하지 않습니다.

+0

감사합니다. 이것은 많은 의미를 갖습니다! – starlight