2016-11-07 41 views
0

Lynda.com
課程編譯:C的基本訓練
çLynda.com教程文件不是在終端或者Eclipse

問題1:項目文件 - 00_04.c
- 終端:編譯和運行正常。
- Eclipse Neon:在控制檯中生成但不顯示輸出。 02_01.c
- 項目:

00_04.c

#include <stdio.h> 
#include <stdlib.h> 

int main(void) { 
    puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ 
    return EXIT_SUCCESS; 
} 

Eclipse控制檯輸出

15:49:04 **** Incremental Build of configuration Debug for project NewProject **** 
make all 
make: Nothing to be done for `all'. 

15:49:04 Build Finished (took 99ms) 


問題2:(MacOS X的GCC與工具鏈創建) - 終端:不識別包含的文件

02_01.c

#include <stdio.h>   // Notice the library included in the header of this file 
#include <stdlib.h> 

#include "myLibrary.h"  // Notice that myLibrary.h uses different include syntax 

myLibrary.h

#ifndef MYLIBRARY_H_ 
#define MYLIBRARY_H_ 

void function1(void); 
void function2(void); 

#endif /* MYLIBRARY_H_ */ 

myLibrary.c

void function1(void){ 
    puts("It works :)"); 
} 

void function2(void){ 
    //This function does nothing as well 
} 

端子輸出

Undefined symbols for architecture x86_64: 
    "_function1", referenced from: 
     _main in 02_01-7f91e4.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
+0

什麼是第一個例子使用的makefile?並在第二個你有一個鏈接器錯誤(也是'function1'在那裏定義?) – UnholySheep

+0

@UnholySheep抱歉。複製爲myLibrary的錯誤代碼。在OP中修復。這就是function1()所在的位置。 – dbconfession

+2

這只是函數的聲明。它的定義/實現在哪裏? – UnholySheep

回答

1

如果你正在運行cc 02_01.c的命令。然後編譯器試圖在文件(02_01.c)或包含的文件(myLibrary.h)中尋找main()函數。

在02_01.c和myLibrary.h中沒有main()函數,所以你得到那個編譯器錯誤。

要修復,讓你的02_01.c看起來像這樣。

#include <stdio.h>   // Notice the library included in the header of this file 
#include <stdlib.h> 

#include "myLibrary.c"  // Notice that myLibrary.h uses different include syntax 
int main(void) 
{ 
    function1(); 
    return 0; 
} 
相關問題