Hi people, I am having problems linking two files together. One file contains a function the other file contains the actual main() function. I get a linking error even though I included the file in the project. I guess I don't know how to link. Could someone please explain? When i include the function after the #include<stdio.h> it works fine.
I am using the latest version of Dev-C++ (4.9.9.2)
Any help would be appreciated. Thanks in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-04-20
OK, you have posted the same question twice, both on old threads! This one is 12 months old!
I answered your question in the other thread you tagged on to, but stop doing that!
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not really enough information to go on here, but I'll give you a couple of pointers...
If you to use a function that's in one file in another, the second file has to know about the function. The way you would normally do this is make a header file with the function declaration and #include it in your other files.
So you'd end up with three files sort of like this (these are just quick, incomplete examples):
//myfunction.h
int myfunction(int x);
//myfunction.cpp
include myfunction.h
int myfunction(int x)
{return x + 1}
//main.cpp
include myfunction.h
int y;
y = myfunction(12);
b_a
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2006-04-20
If you post the fill compile log after a rebuild-all, we will be able to see exactly what you are doing (i.e. what you ar etrying to link, and what is failing). I'm willing ot bet that given that information, you'll get an answer in one.
You were already asked to provide this information in the "<-PLEASE READ BEFORE POSTING A QUESTION", which by definition you will have read. ;O
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey guys, yes i do realize that i was very vague. But here is my program. What i want to do is put the float average function in a seperate .c file and link them together. I am not quite sure how to do this on Dev-C++. Thanks again.
include<stdio.h>
float average(long x, int pi)
{
return (float)(x)/ pi;
}
why would this be in any way specific to devc++?
1) take the function body
2) put it into a new C file, add it to the project
3) create a header with the prototype
4) include the header where you need to access the average func
5) done
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2006-04-21
You've had two responses since yout since you last posted. I previously bet that you would get a definitive answer in one, but ONLY if you posted the "full compile log after a rebuild all". I am guessing then that you are not really interested in solving this problem?
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am having a problem linking a header file to my source file and I do not understand what I am doing wrong with it. The fist thing I have done is go to file new source and type it in saving it has a .h file, which is a header file. The thing I need to know should I use source to save this in or resource and save it has an .h file. I’m just interested if anyone can tell me please? I also have these saved as a Win32Console.
This is the code to the PromptModule.h file below.
ifndef PromptModuleH
define PromptModuleH
void PauseForUserAcknowledgement(void);
endif
Here is the source file code below I didn’t put the header file in the project window it is in the same folder though.
include <iostream>
include "PromptModule.h"
using namespace std;
void PauseForUserAcknowledgement(void)
{
// Note: You must type sommething before Enter
char StopCharacter;
cout << endl << "Press a key and \"Enter\": ";
cin >> StopCharacter;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
well, then you should be familiar with the concept of Makefiles, a devc++ project file serves merely as a stub to create the corresponding Makefile from, in fact you can check out the created Makefile and even provide a custom one.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi people, I am having problems linking two files together. One file contains a function the other file contains the actual main() function. I get a linking error even though I included the file in the project. I guess I don't know how to link. Could someone please explain? When i include the function after the #include<stdio.h> it works fine.
I am using the latest version of Dev-C++ (4.9.9.2)
Any help would be appreciated. Thanks in advance.
OK, you have posted the same question twice, both on old threads! This one is 12 months old!
I answered your question in the other thread you tagged on to, but stop doing that!
Clifford
i realy can't be sure what's your problem. whats the exact error message? how does the part look where you (try to) include?
possibly the function needs the stdio.h file?
have you write it both time the same (ex. #include <file.h> and #include "file.h")?
if your a beginer in c++, perhaps you should look around the net for a beginer tutorial for c++. trust me, there are many good to find!
|sabid|
Not really enough information to go on here, but I'll give you a couple of pointers...
If you to use a function that's in one file in another, the second file has to know about the function. The way you would normally do this is make a header file with the function declaration and #include it in your other files.
So you'd end up with three files sort of like this (these are just quick, incomplete examples):
//myfunction.h
int myfunction(int x);
//myfunction.cpp
include myfunction.h
int myfunction(int x)
{return x + 1}
//main.cpp
include myfunction.h
int y;
y = myfunction(12);
b_a
If you post the fill compile log after a rebuild-all, we will be able to see exactly what you are doing (i.e. what you ar etrying to link, and what is failing). I'm willing ot bet that given that information, you'll get an answer in one.
You were already asked to provide this information in the "<-PLEASE READ BEFORE POSTING A QUESTION", which by definition you will have read. ;O
Clifford
Hey guys, yes i do realize that i was very vague. But here is my program. What i want to do is put the float average function in a seperate .c file and link them together. I am not quite sure how to do this on Dev-C++. Thanks again.
include<stdio.h>
float average(long x, int pi)
{
return (float)(x)/ pi;
}
int main (void)
{
float average(long x, int* y);
}
why would this be in any way specific to devc++?
1) take the function body
2) put it into a new C file, add it to the project
3) create a header with the prototype
4) include the header where you need to access the average func
5) done
6) buy a good C/C++ book.
You've had two responses since yout since you last posted. I previously bet that you would get a definitive answer in one, but ONLY if you posted the "full compile log after a rebuild all". I am guessing then that you are not really interested in solving this problem?
Clifford
This may help: https://sourceforge.net/forum/message.php?msg_id=3619753
Clifford
I am having a problem linking a header file to my source file and I do not understand what I am doing wrong with it. The fist thing I have done is go to file new source and type it in saving it has a .h file, which is a header file. The thing I need to know should I use source to save this in or resource and save it has an .h file. I’m just interested if anyone can tell me please? I also have these saved as a Win32Console.
This is the code to the PromptModule.h file below.
ifndef PromptModuleH
define PromptModuleH
void PauseForUserAcknowledgement(void);
endif
Here is the source file code below I didn’t put the header file in the project window it is in the same folder though.
include <iostream>
include "PromptModule.h"
using namespace std;
void PauseForUserAcknowledgement(void)
{
// Note: You must type sommething before Enter
char StopCharacter;
cout << endl << "Press a key and \"Enter\": ";
cin >> StopCharacter;
}
yes thankyou. I didn't know that to link you had to create a project first. That was the problem. Thanks again. (I'm a previous linux user)
well, then you should be familiar with the concept of Makefiles, a devc++ project file serves merely as a stub to create the corresponding Makefile from, in fact you can check out the created Makefile and even provide a custom one.