Hallo Tweakers,
Sindskort ben ik overgestapt van VisualStudio naar notepad++ en MinGW. Echter wanneer ik probeer te compilen word de test.cpp niet gevonden, en krijg ik dus een aantal fouten in mn compiler. Naar mijn weten hoefde je in de include's alleen de headers toe te voegen, de CPP files worden automatisch toegevoegd. (Correct me if i wrong).
Ik heb even een kleine voorbeeld code gemaakt. Omdat het totaal nutteloos is om mijn gehele source hier te plaatsen.
main.cpp
main.h
test.cpp
test.h
De compiler uitput
Wanneer in in de main.cpp #include "test.cpp" bovenaanzet compiled de applicatie wel. Maar je hoort niet de .cpp files te includen naar mijn weten.
Sindskort ben ik overgestapt van VisualStudio naar notepad++ en MinGW. Echter wanneer ik probeer te compilen word de test.cpp niet gevonden, en krijg ik dus een aantal fouten in mn compiler. Naar mijn weten hoefde je in de include's alleen de headers toe te voegen, de CPP files worden automatisch toegevoegd. (Correct me if i wrong).
Ik heb even een kleine voorbeeld code gemaakt. Omdat het totaal nutteloos is om mijn gehele source hier te plaatsen.
main.cpp
C++:
1
2
3
4
5
6
7
8
9
| #include "main.h" int main(int argc, char *argv[]) { TestCls test; test.printTekst(); getchar(); return 0; } |
main.h
C++:
1
2
3
4
5
6
7
8
9
| #ifndef __H_MAIN #define __H_MAIN #include <stdio.h> #include <iostream> #include "test.h" #endif |
test.cpp
C++:
1
2
3
4
5
| #include "test.h" void TestCls::printTekst(){ std::cout << "Tekst..."; } |
test.h
C++:
1
2
3
4
5
6
7
8
9
10
11
12
| #ifndef __H_TEST #define __H_TEST #include <stdio.h> #include <iostream> class TestCls { public: void printTekst(); }; #endif |
De compiler uitput
Kevin van der Burgt@LT_KEVIN /d/test/cpp $ g++ main.cpp -o application.exe main.cpp: In function 'int main(int, char**)': main.cpp:4:2: error: 'TestCls' was not declared in this scope main.cpp:4:10: error: expected ';' before 'test' main.cpp:5:2: error: 'test' was not declared in this scope
Wanneer in in de main.cpp #include "test.cpp" bovenaanzet compiled de applicatie wel. Maar je hoort niet de .cpp files te includen naar mijn weten.