Ive searched documentation all over the net and yet I cannot seem to find how to link code/object using Bloodshed DevC++ IDE.
A simple example just to demonstrate what I need:
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
usingnamespace std;
int main(){
int a;
cout<<"enter a number to find its double value: ";
cin>>a;
cout<<"The numbers double is: "<<doublevalue(a);
return (0);
}
That above code compiled alone will give an error saying the function doublevalue() is not defined, but I want to LINK the above function "doublevalue()" to another code that defines it:
1 2 3 4 5
int doublevalue(int a){ //This is a function to be linked to the main code
b=2*a;
return (b);
}
What I do know is that I must somehow first seperately compile them and save the code to be linked as an object file or something?
If you're using Dev-C++ (which we disrecommend due to the last release's age), then all you should have to do is write the file and include it in your project along with a header file that contains the function's prototype. Remember to include the header file in both files.
Small print: Actually, you can include C++ files using #include which renders the header file irrelevant but... don't... don't do that. It's quite dangerous.
If you're using Dev-C++ (which we disrecommend due to the last release's age), then all you should have to do is write the file and include it in your project along with a header file that contains the function's prototype. Remember to include the header file in both files.
Small print: Actually, you can include C++ files using #include which renders the header file irrelevant but... don't... don't do that. It's quite dangerous.
Um, you mean make a single project and include two source files in it (one the body (first code) and the other the object to be linked to(second code))? Then I also include header files containing the function name? I did those two simple things and compiled to get an error saying:
"doublevalue: No such file or directory"
I included the header:
#include <doublevalue>
...in both the main code and the object code (the code to be linked to).
Maybe the header I provided above is incorrect but I tried all variations of it including adding (int a) etc etc...
Its not picking up the function to be linked to. I know you dont use Dev, so you wont know the exact step by step, but someone out there, can they be very specific on how to actually do this?
I really need a step by step process to simply link the above code I provided. I know it takes roughly 30 seconds to do and takes roughly two steps but nowhere on the entire internet can I find how to do this. Ive looked for 2 months on the net just how to do this trivial task. Im really surprised no one has asked this.
Athar wrote:
You cannot use double as an identifier anyway, since it is a reserved keyword.
AngelHoof, Athar was referring to my pre-edited post where I had used "double" in the original post and then I edited my post to have "doublevalue", so Athar was actually right according to the pre-edited post. But you are also right that now doublevalue wouldnt matter. Mis-understanding thats all :)
Is it okay if an administrator or forum manager move this thread in the "General C++ Programming" forum instead of this beginners forum?
I just feel I may get more answers there.
Neither do I want to re post this there because ill come across as an annoying spammer and its sort of against the rules to flood this forum with repeated questions.
This is definitely a basic question, so this forum is the right one.
Don't write <doublevalue>, but "doublevalue". If you enclose the file name in <>, the compiler will search the standard include paths for the file, instead of the project's directory. Give your header an extension (.h or .hpp), or else Dev-C++ might be confused.