C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-06-2009, 05:27 PM   #1
Registered User
 
Join Date: Feb 2009
Posts: 21
Unhappy Confusing problem using Eclipse

Hi,

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;
	}
}
This is what I have so far. Not much I know, but I've only just started. Each of the .h files that this code 'links' to has something akin to
Code:
int wavelength();
and that alone.

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   Reply With Quote
Old 02-06-2009, 05:39 PM   #2
and the Hat of Guessing
 
tabstop's Avatar
 
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   Reply With Quote
Old 02-06-2009, 05:42 PM   #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"
and in each .h file it still says as it did before.
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   Reply With Quote
Old 02-06-2009, 05:49 PM   #4
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
Every function that is called must be defined.
tabstop is offline   Reply With Quote
Old 02-06-2009, 05:54 PM   #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   Reply With Quote
Old 02-06-2009, 06:03 PM   #6
Registered User
 
Join Date: Jun 2005
Posts: 1,343
Quote:
Originally Posted by typhonius View Post
Yes I've just created a .c file for each.
In each .c file it says
Code:
#include "wavelength.h"
and in each .h file it still says as it did before.
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; ?
It is the linker that needs placating, not the compiler. The linker is the program that ensures every attempt to call a function resolves to an actual function.

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;
}
The requirement then is that, during building, this source file is compiled (to an object file) and later that the linker combines all of the object files to create an executable.
grumpy is offline   Reply With Quote
Old 02-06-2009, 06:16 PM   #7
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
Quote:
Originally Posted by typhonius View Post
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
Usually that means that you put your function definition in a header file, but I suppose you could have done something else. In any event, both element_sort.c and Assessment 2.c both claim to have a function called "element_sort" now, which is one too many.
tabstop is offline   Reply With Quote
Old 02-06-2009, 06:16 PM   #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   Reply With Quote
Old 02-06-2009, 06:52 PM   #9
Registered User
 
Join Date: Jun 2005
Posts: 1,343
Quote:
Originally Posted by typhonius View Post
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?
Read my previous post above.
grumpy is offline   Reply With Quote
Old 02-06-2009, 07:18 PM   #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   Reply With Quote
Reply

Tags
eclipse, error, mac, xcode

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 03:08 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22