so there is no problem I am looking to solve as the problem has already been solved but just noticed a strange occurrence with the codeblocks ide,so I have two files one .cpp and one.h file one is cordinates.cpp and cordinates.h(yes spelled wrong to avoid possible name clashes,I'm sure a class called coordinates probably exists already,probably should have made a namespace but meh)
any who I included the cordinates.h into my main cpp file where main is and I got plenty of undefined references to functions such as solve and the constructor,so I decided to also include cordinates.cpp in my main cpp file and it worked,
this is quite surprising to me as I would have been under the impression that once the header is included and the .cpp file is in local scope of the project it should find the code but looks like it didn't
Sounds like you haven't added cordinates.cpp as part of the project.
The way it works is that each source file (.cpp) is compiled independently, without the knowledge of other source files. When all the source files has been compiled everything is linked together to create the executable file.
If cordinates.cpp is not part of the project it would notice that some of the definitions are missing and give you a linker error "undefined reference".
There is no magic relationship between source files and header files. That they are named the same is only for our own sanity. You could call the header file asda.h and the source file xc76.cpp if you wanted.
Do not include the cpp-files. While it might succeed, it is not what is expected.
The "include" directive is almost like copy-pasting the content of the named file into your code. In other words, you have all your code in "one file".
What you should have done is to tell the codeblocks that your "project" contains two .cpp files. When you have done that properly, the "build" will.
1. compile the cordinates.cpp into cordinates.o
2. compile the main.cpp into main.o
3. link cordinates.o, main.o, and standard libraries into the executable file
How to use your IDE? Read its documentation. Consult its Forum.
I didn't add a class to the project instead I manually added a .cpp file and a .h file instead of choosing to add a class maybe that has something to do with it?
Sounds like you haven't added cordinates.cpp as part of the project.
The way it works is that each source file (.cpp) is compiled independently, without the knowledge of other source files. When all the source files has been compiled everything is linked together to create the executable file.
that could exactly be the problem as what I said above may be the reason for it?
by manually I meant I selected the project and instead of selecting add class I chose add file > add c/c++ header and add c/c++ source file
mingw32-g++.exe -o bin\Release\cordinateMath.exe obj\Release\main.o -s -lmingw32 -lSDL2 -lSDL2main "C:\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.dll.a" "C:\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2main.a" this is with cordinates.cpp included
At least that confirms that it's only linking main.o and nothing calling "cordinates.o" or similar.
I don't know why CB isn't trying to compile your cordinates.cpp file. Maybe, for some reason, that file isn't set to be compiled in Release mode. But that's just a guess.
Can you post the contents of your CBP ("Code Blocks Project") file?
... If you are using windows, it is common for the system to set hidden extensions by default, you can easily change that with a google, all programmers usually have this option on. (sorry if I am wrong, but you should know that the cbp file is the file that you use to open your project), otherwise if you just don't know where it is you can right click on your project in the left column and click "open project from file explorer".
The reason why it doesn't get compiled is due to codeblocks always asking you which build targets would you like the file to be included with, and you forgot to check all build targets by accident.
In the properties of the project, you can look under build targets tab, and you can check if the files are checked in.
If you have trouble with finding that, you can also just remove the cordinate.cpp file from the project and re include it, that could fix it.
I assumed that you had the file inside the project, which should be obvious if you look at the files in your project in the left side column. I thought you said in your post that you created the file from new>file>h and cpp for both the cordinates files, but you didn't. You can include files by right clicking the project and adding files. You would also do yourself a favor if you had a debug and release build, since you should be frequently going to debug mode for finding segment faults and other bugs.
Also note that you are manually pointing to libSDL2.dll.a instead of having SDL linked up with -L"C:/..." to the folders instead, which confuses me why -lSDL2 -lSDL2main works at all, since the -l options are supposed to lead to the libLIBRARYNAME.a(.dll) magically, like -lmingw32 points to libmingw32.a which is always in the scope because its inside of the compiler scope. It is possible that SDL2 could be in the scope due to putting it in the global PATH or a global IDE variables (and other scope possibilities).
I would be surprised if it is true that if you can link to the file directly while linking the same library with linker flags at the same time and not have any problems, and I just tested it and it is true you can link the same thing over and over again without warning, I hope the linker is smart enough to make it indifferent from just linking once (it should since it would have redefinition errors otherwise).... It isn't a big problem, but I like having all my things nice and strict, and having a warning would be nice. At least codeblocks is smart enough to automatically cull link flag duplicates the next time you look at them, but it wont clean up your scenario.
I have both Debug and Release configurations on mine, although you having only Release should still be fine. But for some reason, your only "Unit filename" is main.cpp. This means you aren't actually adding the other files to your project. The main.cpp, cordinate.cpp, cordinate.h, and my project are all in the same folder, and I did right-click --> Add File for each one, and added each one to Debug and Release.
My built output looks like this:
-------------- Build: Debug in cordinateMath (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -g -c C:\dev\cordinateMath\cordinate.cpp -o obj\Debug\cordinate.o
mingw32-g++.exe -Wall -fexceptions -g -c C:\dev\cordinateMath\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\cordinateMath.exe obj\Debug\cordinate.o obj\Debug\main.o
Output file is bin\Debug\cordinateMath.exe with size 1.51 MB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))