GNU compiler: do i need include the header file on compiler commands?

i have created my own header file...
using command line\console, i can compile using the GNU compile parameters. but do i need include my header file on parameters?
No, but you might have to specify the directory where the header file is located if cannot be found by default.
Last edited on
see these standard code:
1
2
3
4
5
6
7
include <iostream>
int main()
{
   std::cout << "hello world!!!\n";
   std::cin.get();//press enter to exit
   return 0;
}

these cpp file is saved on test.cpp.
now see how i call the compiler:
1
2
3
4
5
cout << "\ncreating an exe....\n";
    string FileName1="C:\\Program Files\\mingw-w64\\x86_64-7.2.0-win32-seh-rt_v5-rev1\\mingw64\\bin\\x86_64-w64-mingw32-g++.exe";
    run(FileName1,"-Wall -g -std=c++14  -c \"C:\\Users\\Cambalinho\\Documents\\CB\\testfolder\\bin\\Debug\\test.cpp\" -o \"C:\\Users\\Cambalinho\\Documents\\CB\\testfolder\\bin\\Debug\\test2.o\"");
//    Sleep(20000);
    run(FileName1,"-o errorlog C:\\Users\\Cambalinho\\Documents\\CB\\testfolder\\bin\\Debug\\test2.exe C:\\Users\\Cambalinho\\Documents\\CB\\testfolder\\bin\\Debug\\test2.o -static-libstdc++ -static-libgcc -fpermissive \"C:\\Program Files\\mingw-w64\\x86_64-7.2.0-win32-seh-rt_v5-rev1\\mingw64\\x86_64-w64-mingw32\\lib\\libgdi32.a\"");

the exe is created normaly and i can execute it like it must do...
but if i change the test.cpp to:
1
2
3
4
5
6
7
8
9
#include "Untitled1.h"
void Main (vector < string > argumentlist , boolean IsOpened ) 
{
	integer a =  20;

	a = a + 30 ;
	write ( a ) ;
	write ( "hello world" ) ;
}

the header file is close to cpp file... the object file is created, but not the exe... i can't see the message printed, because it's too fast
Last edited on
Why don't you just run the command from the command prompt and see what error message you get?
because i never thot that. thank you:
C:\Program Files\mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin>x86_64-w64-mingw32-g++.exe
-o "C:\Users\Cambalinho\Documents\CB\testfolder\bin\Debug\test2.exe" "C:\Users\Cambalinho\Documents\
CB\testfolder\bin\Debug\test2.o" -static-libstdc++ -static-libgcc -fpermissive "C:\Program Files\min
gw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\x86_64-w64-mingw32\lib\libgdi32.a"

C:\Users\Cambalinho\Documents\CB\testfolder\bin\Debug\test2.o: In function `main':
C:/Users/Cambalinho/Documents/CB/testfolder/bin/Debug/Untitled1.h:335: undefined reference to `Main(
std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::al
locator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool)'
C:/Users/Cambalinho/Documents/CB/testfolder/bin/Debug/Untitled1.h:339: undefined reference to `Main(
std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::al
locator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool)'
collect2.exe: error: ld returned 1 exit status

i compile the code on Code Blocks... but i can't here :(
i can share the code, but it's almost 400 lines of code
but i belive the errors have to do with these code on header file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
typedef int integer;
typedef bool Boolean;
typedef void procedure;
using namespace std;

HANDLE mutex;
void Main(vector<string> argumentlist, bool IsOpened);

int main (int argc, char **argv)
{
    //Arguments list:
    vector<string> test;
    for (int i=0; i<argc;i++)
    {
        test.push_back(argv[i]);
    }

    //Testing if the application is executing:
    mutex = CreateMutex( NULL, TRUE, "MyApp" );

    if ( mutex!=NULL)
    {
        Main(test,true);
    }
    else
    {
        Main(test, false);
    }
    if(mutex)
        CloseHandle(mutex);
    return 0;
}

and the code on cpp:
1
2
3
4
5
6
7
8
9
#include "Untitled1.h"
void Main (vector < string > argumentlist , boolean IsOpened ) 
{
	integer a =  20;

	a = a + 30 ;
	write ( a ) ;
	write ( "hello world" ) ;
}

like i said, these code compiles on Code Blocks
Last edited on
It's quite difficult when you don't show real code.

All I can say is that you must not forget to compile (and link) the file that contains the definition of Main.
Last edited on
"It's quite difficult when you don't show real code."
i'm sorry, but what you mean? that code it's on header file.
i avoid 1 class and some functions that aren't used on cpp file, because have very code lines and these edit will give error, when i 'submit'.
"All I can say is that you must not forget to compile (and link) the file that contains the definition of Main."
the header file have it. because i create the Main() function and define it on cpp file.
the Code Blocks can do the right commands... maybe i forget some options, that i don't know them.
main() shouldn't be defined in a header file. It usually doesn't cause any problems if it's only included in one source file but would certainly lead to multiple definition errors if it was included in more than one source file.

"It's quite difficult when you don't show real code."
i'm sorry, but what you mean?

I mean that the code you have posted is obviously not the real code that produces the error that you posted.

- The error messages refer to line 335 and 339 in Untitled1.h but the header file that you have posted only contains 32 lines.

- Your typedef is named Boolean but in the source file you use boolean. I just assumed both of these were aliases for the bool type but if that is not the case then that could be the problem.

When people post simplified examples of their code the real problem is often hidden somewhere in the code that has been stripped away. It is nothing wrong to post simplified code, it is actually a very good thing to do, but then the code must still reproduces the same problem.
"When people post simplified examples of their code the real problem is often hidden somewhere in the code that has been stripped away. It is nothing wrong to post simplified code, it is actually a very good thing to do, but then the code must still reproduces the same problem."
that's why i only showed that code. it's too big for show it here.. and the problem was on showed code.

"- Your typedef is named Boolean but in the source file you use boolean. I just assumed both of these were aliases for the bool type but if that is not the case then that could be the problem."
that was my error without notice... thank you so much for all.. thank you
and i fixed 1 problem with new line that i need save it on file: i must do a double slash:
"write(\"hello world\\n\")"
if we use '\n', the new line will happen on file and not on print... that's why we must use the double slash ;)

thank you so much for all... thank you
Last edited on
Topic archived. No new replies allowed.