[問題] compiler head file與多個檔在linuxm卮cc
:開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
請問一下, 我想用G++ 在linux 下compiler head file 和 cpp file (如g++ -g main.cpp -o main) 當我compiler hellowWorld.h 沒有問題. 如果我在compiler hellowWorld.cpp 錯誤為In function `_start':(.text+0x20): undefined reference to `main' collect2: ld returned 1 exit status. 如果compiler main.cpp 錯誤為 undefined reference to `HelloWorld::printGreeting()'collect2: ld returned 1 exit status
請問我要如何compiler才能把他們連起來?
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
1 helloWorld.h:
2 #ifndef HELLOWORLD
3 #define HELLOWORLD
4
5 void helloWorld();
6
7 #endif
8
9
10 helloWorld.cpp
11 #include "helloWorld.h"
12 #include <iostream>
13
14 void helloWorld()
15 {
16 std::cout << "Hello World!" << std::endl;
17 }
18
19
20 main.cpp:
21 #include "helloWorld.h"
22
23 int main()
24 {
25 helloWorld();
26 return 0;
27 }
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 71.190.195.62
推
10/06 18:05, , 1F
10/06 18:05, 1F
→
10/06 18:05, , 2F
10/06 18:05, 2F
→
10/06 18:06, , 3F
10/06 18:06, 3F
→
10/06 18:07, , 4F
10/06 18:07, 4F
→
10/06 18:08, , 5F
10/06 18:08, 5F
→
10/06 18:11, , 6F
10/06 18:11, 6F
→
10/06 18:24, , 7F
10/06 18:24, 7F
→
10/06 18:40, , 8F
10/06 18:40, 8F
→
10/06 18:59, , 9F
10/06 18:59, 9F
→
10/06 23:09, , 10F
10/06 23:09, 10F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 3 篇):