![]() |
| | #1 |
| Registered User Join Date: Feb 2009
Posts: 21
| I'm a university student taking a module in C programming. While I am enjoying the module, we have recently been set an assignment that has pushed me. I have to use .h files within my code to tie together 4 different questions. Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "element_sort.h"
#include "wavelength.h"
#include "quadratic.h"
#include "element_info.h"
int decision;
int main()
{
printf("This program has the ability to do four tasks. "
"\n\nPlease pick the corresponding number related"
" to the task you wish to be done.\n\n"
"1. Sort elements stored on file by either name or abundance.\n"
"2. Find maxima from data on wavelengths and absorbances.\n"
"3. Root Finding\n"
"4. Element Database");
while(1)
{
scanf("%i", &decision);
if (decision == 1)
{
printf("You have selected option 1");
element_sort();
}
if (decision == 2)
{
printf("You have selected option 2");
wavelength();
}
if (decision == 3)
{
printf("You have selected option 3");
quadratic();
}
if (decision == 4)
{
printf("You have selected option 4");
element_info();
}
else
{
printf("Invalid Number");
continue;
}
return 0;
}
}
Code: int wavelength(); My problem arises when I try to build I get two errors, with Assessment 2 being the title of the piece. make: *** [Assessment2] Error 1 Assessment 2 symbol(s) not found Assessment 2 unfortunately these both do not reference anywhere in particular that the error is to be found. Please note I have used Eclipse before and it has worked. I also get a similar problem when I attempt to use xcode. Any help would be very much appreciated. Thanks |
| typhonius is offline | |
| | #2 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| The reason it doesn't reference anywhere in particular is that the problem is you haven't written any of the functions yet. If you have a wavelength.h file with a function prototype in it, then that means you need to have a wavelength.c file with the actual function itself in it. (Of course you can call it what you want, but using the same name for the .h and the .c is customary.) |
| tabstop is offline | |
| | #3 |
| Registered User Join Date: Feb 2009
Posts: 21
| Yes I've just created a .c file for each. In each .c file it says Code: #include "wavelength.h" I just need something to placate my compiler so I can run it. Rather than wait til all the code is in. Is there a simple way to do this. Maybe just putting in a return 0; ? |
| typhonius is offline | |
| | #4 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| Every function that is called must be defined. |
| tabstop is offline | |
| | #5 |
| Registered User Join Date: Feb 2009
Posts: 21
| I'm sorry, I'm very new to C and I thought I had defined all my functions. The error has changed now to this. duplicate symbol _element_sort in ./src/element_sort.o and ./src/Assessment 2.o Assessment and make: *** [Assessment2] Error 1 Assessment 2 0 C/C++ Problem I'm not looking for someone to do my work for me, I just need a little help getting out of this rut. Thanks in advance |
| typhonius is offline | |
| | #6 | |
| Registered User Join Date: Jun 2005
Posts: 1,343
| Quote:
You need to provide implementations of the functions you are calling. Or, to use the more formal langage, a definition. The declaration in the header tells the compiler the functions are defined (implemented) somewhere. You need to provide the definitions, otherwise you are deceiving the compiler. The linker picks up the deception. For example, your build process needs to include a source file (wavelength.c) with the code; Code: #include <stdio.h>
#include "wavelength.h" /* This contains a DECLARATION of wavelength() */
int wavelength() /* this is the DEFINITION of wavelength() */
{
printf("Typhonius needs to implement wavelength()\n");
return -100;
}
| |
| grumpy is offline | |
| | #7 | |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| Quote:
| |
| tabstop is offline | |
| | #8 |
| Registered User Join Date: Feb 2009
Posts: 21
| Thanks for the help in amending my code. That has removed some of the minor problems, however Eclipse keeps telling me that "symbols aren't found" and "make: *** [file name] Error 1 Can anyone shed any light on this? |
| typhonius is offline | |
| | #9 |
| Registered User Join Date: Jun 2005
Posts: 1,343
| |
| grumpy is offline | |
| | #10 |
| Registered User Join Date: Feb 2009
Posts: 21
| Yeah I understand now. I was trying to do the main and referencing nothing. I've referenced part of my first equation and it now works. Thanks for your help guys. I understand if it is infuriating talking to a dimwit :P |
| typhonius is offline | |
![]() |
| Tags |
| eclipse, error, mac, xcode |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Weird problem on '02 3.4L V6 auto | Bubba | General Discussions | 8 | 01-12-2006 12:05 AM |
| Sorting problem.. well actually more of a string problem | fatdunky | C Programming | 5 | 11-07-2005 11:34 PM |
| half ADT (nested struct) problem... | CyC|OpS | C Programming | 1 | 10-26-2002 08:37 AM |
| binary tree problem - help needed | sanju | C Programming | 4 | 10-16-2002 05:18 AM |
| problem with output | Garfield | C Programming | 2 | 11-18-2001 08:34 PM |