Linking Problems

This is a discussion on Linking Problems within the C++ Programming forums, part of the General Programming Boards category; Using g++ in Linux, I have 2 .C files and a .h file: Code: //Fibonacci.h #ifndef FIBONACCI_H #define FIBONACCI_H unsigned ...

  1. #1
    Registered User Mini_Maggit's Avatar
    Join Date
    Mar 2004
    Posts
    3

    Linking Problems

    Using g++ in Linux, I have 2 .C files and a .h file:

    Code:
    //Fibonacci.h
    
    #ifndef FIBONACCI_H
    #define FIBONACCI_H
    
    unsigned int Fibonacci (unsigned int);
    
    #endif	/* FIBONACCI_H */
    Code:
    //Fibonacci.C
    
    #include "Fibonacci.h"
    
    unsigned int Fibonacci (unsigned int n)
    {
    	if ( (n == 0) || (n == 1) )
    		return 1;
    	else
    		return (Fibonacci(n-1) + Fibonacci(n-2));
    }
    Code:
    //main.C
    
    #include <iostream>
    using namespace std;
    
    #include "Fibonacci.h"
    
    int main() {
    	unsigned int n;
    	for (n=1; n<10; n++) {
    		cout << Fibonacci(n) << " ";
    	}
    	cout << endl;
    	return 1;
    }

    I've also got a Makefile, so I run

    Code:
    make -f main
    and get the following error message:

    Code:
    undefined reference to 'Fibonacci(unsigned)'
    I've tried numerous things to correct this, but to no avail.

    Does anyone know what I'm doing wrong?

    Any help would be really appreciated.
    Thanks

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    What's the makefile look like?

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Oh, and have you tried just typing:

    make

  4. #4
    Registered User Mini_Maggit's Avatar
    Join Date
    Mar 2004
    Posts
    3
    Originally posted by swoopy
    Oh, and have you tried just typing:

    make
    Yes, well... Don't I feel like an ass..?
    That worked perfectly

    Thanks for your trouble

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ OpenGL linking problems
    By KoshiB in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2006, 04:25 PM
  2. Linking problems, class problems
    By Kheila in forum C++ Programming
    Replies: 12
    Last Post: 11-22-2005, 12:47 AM
  3. Linking problems trying to compile QT application
    By Maragato in forum C++ Programming
    Replies: 1
    Last Post: 08-19-2005, 09:08 PM
  4. Grrr.... SDL Linking Problem
    By 7EVEN in forum Game Programming
    Replies: 5
    Last Post: 08-12-2005, 08:44 PM
  5. More linker problems
    By Ganoosh in forum C++ Programming
    Replies: 4
    Last Post: 07-12-2005, 10:27 PM

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