compile multiple files

This is a discussion on compile multiple files within the C Programming forums, part of the General Programming Boards category; I would like to ask you this: how can i compile a program that includes a header that i make? ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    63

    compile multiple files

    I would like to ask you this: how can i compile a program that includes a header that i make?
    Example: we have test.c and we need for the compile the header that is in another folder.How can i tell to gcc to search for the header in the correct folder?

    Another question:
    I found on the web a project in C.In the folder except the source code ,there are also some files with names makefile.inc and makefile.What exactly are these? How can i produce for my code these files?
    Thanks!!!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,309
    You just need to include the header, not compile it.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    63
    @laserlight
    yes, i know this , but i am asking you how the compiler see the header file.(the header file is in another folder)

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    give the compiler the explicit path liek this -
    Code:
    #include "c:\somefolder\header.h"
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    63
    Thanks abachler. It works the way you suggested me.
    Is there any other way?

    also anyone for my second question?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Absolute paths are dumb. You can't move the project around at all with absolute paths.
    Use the -I option to tell the compiler where to look.

    Eg.
    gcc -I/path/to/header prog.c


    > I found on the web a project in C.In the folder except the source code ,there are also
    > some files with names makefile.inc and makefile.What exactly are these?
    > How can i produce for my code these files?
    Which OS?
    Which Compiler?
    Which IDE?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    63
    Quote Originally Posted by Salem View Post
    Absolute paths are dumb. You can't move the project around at all

    > I found on the web a project in C.In the folder except the source code ,there are also
    > some files with names makefile.inc and makefile.What exactly are these?
    > How can i produce for my code these files?
    Which OS?
    Which Compiler?
    Which IDE?
    OS is linux
    compiler is gcc
    there is no IDE

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Do you have a script called "configure" ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Aug 2007
    Posts
    63
    Quote Originally Posted by Salem View Post
    Do you have a script called "configure" ?
    no . But i can tell what the makefile.inc tells if i open it with word:
    Code:
    CC = g++
    
    # this line gives compiler optimizations that are geared towards g++ and Pentium4 
    # computers. Comment it out if you don't have a Pentium 4 (or Athlon XP) or up
    
    
    #CFLAGS = -O3 -mcpu=pentium4 -mtune=pentium4 \
    # -mfpmath=sse -msse -mmmx -msse2 -pipe -fomit-frame-pointer -s 
    
    LFLAGS = -lm -lpthread 
    
    # Uncomment these two lines to use with any Pentium with MMX or up.
    
    # CFLAGS = -Wno-deprecated -mcpu=pentium -march=pentium -pipe \
    # -fomit-frame-pointer -mmmx -funroll-all-loops -s
    
    # Uncomment these lines for some "safe" optimization flags
    
    #CFLAGS = -O3 -pipe -fomit-frame-pointer -funroll-all-loops -s

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    I guess you just type
    make
    at the command line.

    Makefiles are just text files. It's definitely worth looking on the web for some tutorials on the subject. You'll see a lot of them in Unix/Linux developments.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, you could add -I path-to-your-header-file in the CFLAGS (if you always want the same one regardless of what option you choose, do:
    Code:
    CFLAGS += -I somepath
    at the end of makefile.inc.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User
    Join Date
    Aug 2008
    Posts
    15
    to compile multiple files you can write a shell script which includes complation statements for all files...

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by nishkarsh View Post
    to compile multiple files you can write a shell script which includes complation statements for all files...
    Or use makefiles, whcih is a much more intelligent way to solve the problem as:
    1. It allows you to only recompile parts that actually have changes (or code that is dependent on the changes).
    2. The makefile can use "templates", so you don't have to specify every step for every file, just what they depend on and a generic way to produce the expected output (for example "To make a .o file from a .cpp file you do ... ", although the syntax is of course not English)

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with multiple cpp files
    By Sclorch in forum C++ Programming
    Replies: 9
    Last Post: 02-11-2009, 10:58 AM
  2. Packed Files (Puting multiple files in one file)
    By MrKnights in forum C++ Programming
    Replies: 17
    Last Post: 07-22-2007, 05:21 PM
  3. need assistance with multiple files
    By c++.prog.newbie in forum C++ Programming
    Replies: 7
    Last Post: 03-21-2006, 01:44 AM
  4. Windows shell commands - multiple files
    By Magos in forum Tech Board
    Replies: 3
    Last Post: 02-28-2006, 01:56 AM
  5. opening multiple files sequentially
    By moonwalker in forum C Programming
    Replies: 5
    Last Post: 08-20-2002, 10:57 PM

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