Thread: Help with includes

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    3

    Help with includes

    i'm having a problem with gcc can anyone help me


    I have two archives
    test1.c e test2.c

    in test1.c i have :

    int Area ;
    ...
    include "test2.c"
    ...

    in test2.c i have:
    ...
    Area = Area+10
    ...

    this led me to a error :
    Area undeclared (first use this function)

    why this ocorrur, i'm newbie in c.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Don't #include a .c file - create a separate header file for "test2.c" (e.g. "test2.h") and include that. See here for a simple demonstration: How to create a C project with multiple source files

    this led me to a error :
    Area undeclared (first use this function)
    We'd have to see the source to know what you're doing wrong. But it sounds like you just want "test2.c" to contain a function that receives an argument, adds ten, and returns the result. Then you call that function from "test1.c" (with "test2.h" included, of course).

    You also might consider looking into the "extern" keyword.
    Last edited by Matticus; 02-26-2015 at 09:01 AM.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Why are you including a source file? Source files should be added to your project, not included.

    You haven't shown enough content for me to determine your actual problem. I suggest you post the smallest complete program that illustrates your problem.


    Jim

  4. #4
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Multiple Source Files C
    Extern to share variables

    Not to mention, you should avoid global variables.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  5. #5
    Registered User
    Join Date
    Feb 2015
    Posts
    3
    Quote Originally Posted by jimblumberg View Post
    Why are you including a source file? Source files should be added to your project, not included.

    You haven't shown enough content for me to determine your actual problem. I suggest you post the smallest complete program that illustrates your problem.


    Jim
    Its a legacy code

  6. #6
    Registered User
    Join Date
    Feb 2015
    Posts
    3
    i dont put all code becaus is too big

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Its a legacy code
    What's this have to do with anything? You still should never include a source file. If this is a "legacy" system my suggestion is that you first fix this problem, then maybe some of your errors might "magically" disappear. Plus you still haven't shown enough information for me to even guess as to what is wrong.

    i dont put all code becaus is too big
    That's why I suggested showing the smallest possible complete program that illustrates the problem.

    By the way, what do you consider too big?


    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Best Practices For Includes
    By valaris in forum C++ Programming
    Replies: 13
    Last Post: 03-09-2009, 03:12 AM
  2. who includes who?
    By sept in forum C++ Programming
    Replies: 5
    Last Post: 02-23-2008, 06:53 AM
  3. Different includes
    By Ganoosh in forum C++ Programming
    Replies: 10
    Last Post: 06-22-2005, 01:52 PM
  4. Includes
    By golfinguy4 in forum Windows Programming
    Replies: 7
    Last Post: 01-29-2002, 05:29 PM
  5. #includes
    By RedLenses in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2002, 03:59 PM