Right now I am just fiddling around with c++ but am having a problem.
To make a long story short am trying to make my program get its functions from another file. I have a main, header , and a function cpp file (these are all in separate files, source files.)
I understand that there is a easy way of doing this -- File -> New -> Project-> etc etc.
I am aware of this method. but i dont want to do it this way.
Like i said as of now i created three differnet source files and save two as .cpp, and one as .h. Also i looked in the FAQ/READ THIS first and tired to follow those direction but it wasn't clear enough for me to get it to work. as you can see in my log i added the -I"C:\dev-cpp\" and -L"C:\dev-cpp\" to linker command but still nothing
Here is my code:
// menu.cpp file
include <iostream>
include <cstdlib>
include "menu_options.h"
using namespace std;
int main()
{
echo();
cout << " This is the menu test"<<endl;
echo();
system("pause");
echo();
system("pause");
}
//menu_options.h
if !defined menu_options_h
define menu_options_h
void echo();
endif
//menu_options.cpp file
include <iostream>
include <cstdlib>
include "menu_options.h"
using namespace std;
void echo();
void echo()
{
cout <<"this is a lib."<< endl;
}
My error:
C:\Dev-Cpp\menu.cpp In function int main()':
C:\Dev-Cpp\menu.cppecho' undeclared (first use this function)
This is my log:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Dev-Cpp\menu_options.cpp" -o "C:\Dev-Cpp\menu_options.exe" -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -L"C:\Dev-Cpp", -L"C:\Dev-Cpp" -g3
C:\Dev-Cpp\lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
Execution terminated
Dev C++ 4.9.9.2
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Right now I am just fiddling around with c++ but am having a problem.
To make a long story short am trying to make my program get its functions from another file. I have a main, header , and a function cpp file (these are all in separate files, source files.)
I understand that there is a easy way of doing this -- File -> New -> Project-> etc etc.
I am aware of this method. but i dont want to do it this way.
Like i said as of now i created three differnet source files and save two as .cpp, and one as .h. Also i looked in the FAQ/READ THIS first and tired to follow those direction but it wasn't clear enough for me to get it to work. as you can see in my log i added the -I"C:\dev-cpp\" and -L"C:\dev-cpp\" to linker command but still nothing
Here is my code:
// menu.cpp file
include <iostream>
include <cstdlib>
include "menu_options.h"
using namespace std;
int main()
{
echo();
cout << " This is the menu test"<<endl;
echo();
system("pause");
echo();
system("pause");
}
//menu_options.h
if !defined menu_options_h
define menu_options_h
void echo();
endif
//menu_options.cpp file
include <iostream>
include <cstdlib>
include "menu_options.h"
using namespace std;
void echo();
void echo()
{
cout <<"this is a lib."<< endl;
}
My error:
C:\Dev-Cpp\menu.cpp In function
int main()': C:\Dev-Cpp\menu.cppecho' undeclared (first use this function)This is my log:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Dev-Cpp\menu_options.cpp" -o "C:\Dev-Cpp\menu_options.exe" -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -L"C:\Dev-Cpp", -L"C:\Dev-Cpp" -g3
C:\Dev-Cpp\lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
Execution terminated
Dev C++ 4.9.9.2
btw am using winxp-