#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    184
    Rep Power
    29

    Question Eclipse compiler problems with multiple C files


    I am not by any means and expert using eclipse and I am having a problem that does not make any sense to me. This should be fairly straight forward. create a *.h file for the *.c file and include the *.h file in my main c file and compile. But when I use the function name in my main function I get a undefined reference error. So, I was wondering if there is something else I need to do?

    Code:
    /*  
    * gpiotests.h  
    *  
    *  Created on: Feb 6, 2013  
    *       
    */  
    #ifndef GPIOTESTS_H_ 
    #define GPIOTESTS_H_  
    void gpiotests(void);  
    #endif 
    /* GPIOTESTS_H_ */
    Code:
    /*  
    * gpiotests.c  
    *  
    *  Created on: Feb 6, 2013  
    *     
    */  
    #define __GPIOTESTS_C__  
    #include <stdint.h> 
    #include "print.h" 
    #include "gpiotests.h"  
    
    char stringbuffer[MAX_STRINGBUFFER_SIZE]; 
     
    void gpiotests(void) 
    {  	
    
        sprintf(stringbuffer, "\n\rGPIO Tests\n\r");
        printString(stringbuffer);  
    }
    Code:
    /*
    
    Module Name:
    
        main.c
    
    Module Description:
    
        Used to call other features.
    
    Author:
    
    
    --*/
    #define __MAIN_C__
    
    #include <stdio.h>
    #include "print.h"
    #include "gpiotests.h"
    
    char stringbuffer[MAX_STRINGBUFFER_SIZE];
    
    
    int main( void )
    {
      
                
        gpiotests();
        
    
        return 0;
    }
    
    /*void gpiotests(void)
    {
    
    	sprintf(stringbuffer, "\n\rGPIO Tests\n\r");
    	printString(stringbuffer);
    
    }*/
    :(
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    I've never used Eclipse myself, but I would assume that it has features common to many other integrated development environments (IDEs). Such as project management.

    Under File | New, it allows you to create a new project. Have you done that?

    There should be a way to add files to that project, but I cannot find it (Visual Studio has it!). However, under File | New, you can add new files or classes or various other things.

    The bottom line is that the project needs some way of knowing which files are part of the project. Once those files become part of the project, then whenever you build that project it will know to also compile those files and link their object files together. If they are not part of the project, then that won't happen and you will get undefined/unresolved references.

    General principles of IDEs and project management.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    184
    Rep Power
    29
    Originally Posted by dwise1_aol
    I've never used Eclipse myself, but I would assume that it has features common to many other integrated development environments (IDEs). Such as project management.

    Under File | New, it allows you to create a new project. Have you done that?

    There should be a way to add files to that project, but I cannot find it (Visual Studio has it!). However, under File | New, you can add new files or classes or various other things.

    The bottom line is that the project needs some way of knowing which files are part of the project. Once those files become part of the project, then whenever you build that project it will know to also compile those files and link their object files together. If they are not part of the project, then that won't happen and you will get undefined/unresolved references.

    General principles of IDEs and project management.
    Yes, I did all that. It was part of a larger project that was working before until I added the new files. I did do the exact same thing in visual studio and it worked like I thought it should. I don't have an option of using a different compiler though.
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    As I said, I have never worked with Eclipse, though I did load it in a failed attempt to create a development environment for Android apps.

    In Microsoft's Visual Studio, you have the "Project Explorer" tree-view that lists all files that have been added to the project. Do you have the same thing available for Eclipse?

    Many IDEs allow you to generate a makefile for that project. Does Eclipse allow that as well? If so, then what does that makefile show you?

    Sorry, but I'm at the end of my own rope at this point.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    184
    Rep Power
    29
    Originally Posted by dwise1_aol
    As I said, I have never worked with Eclipse, though I did load it in a failed attempt to create a development environment for Android apps.

    In Microsoft's Visual Studio, you have the "Project Explorer" tree-view that lists all files that have been added to the project. Do you have the same thing available for Eclipse?

    Many IDEs allow you to generate a makefile for that project. Does Eclipse allow that as well? If so, then what does that makefile show you?

    Sorry, but I'm at the end of my own rope at this point.
    Okay, well thanks for trying.

    In Microsoft's Visual Studio, you have the "Project Explorer" tree-view that lists all files that have been added to the project. Do you have the same thing available for Eclipse?
    Yes, it has the same thing.

    Many IDEs allow you to generate a makefile for that project. Does Eclipse allow that as well? If so, then what does that makefile show you?
    Well, eclipse has the ability to compile with or without a make file. I chose both and had the same problem though I did not actually look at the make file. That is a good idea.

    I did download another copy of eclipse, the juno version today and noticed it had the same problem. I also noticed that compiling a C++ project worked, but doing the exact same thing with the C project does not work.

    Again, thanks for trying.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    184
    Rep Power
    29
    Originally Posted by dwise1_aol
    As I said, I have never worked with Eclipse, though I did load it in a failed attempt to create a development environment for Android apps.

    In Microsoft's Visual Studio, you have the "Project Explorer" tree-view that lists all files that have been added to the project. Do you have the same thing available for Eclipse?

    Many IDEs allow you to generate a makefile for that project. Does Eclipse allow that as well? If so, then what does that makefile show you?

    Sorry, but I'm at the end of my own rope at this point.
    You were correct about the make file. I added the file to the make file by hand and it worked. I was assuming that would be done when I just added the new files, but I guess not. I don't use make files a lot. Of course I also had some problems where my virus scanner was deleting my executable, but that is another story. Anyway, it works now.

IMN logo majestic logo threadwatch logo seochat tools logo