3 files: .c .c .h

Sharky Forums


Results 1 to 6 of 6

Thread: 3 files: .c .c .h

  1. #1
    Reef Shark barton boi's Avatar
    Join Date
    Sep 2003
    Location
    California
    Posts
    364

    3 files: .c .c .h

    I want to compile and link 2 .c files, and include 1 .h file.

    I have BCC for windows, and GCC for linux. I can try this on either one. I believe I need to create a makefile, or is there an easier way?

    Thanks
    • 1.5GHZ Pentium M | 768MB PC2700 | ATI Radeon 9600 pro 128MB Turbo | 60GB 7200RPM | 4X DVD+RW | 15.4" WSXGA+ | 802.11b | Logitech MX310 | XP Pro | Slackware 10

  2. #2
    Hammerhead Shark
    Join Date
    Feb 2001
    Location
    Columbus, Ohio
    Posts
    1,277
    should be able to do:

    gcc -o file.o file.c
    gcc -o file file.o


    it's been awhile but I"m pretty sure that's right.

    Oh yah, you'll prolly want to include the file in the .c files.
    Last edited by anfpunk; 09-24-2003 at 01:21 AM.

  3. #3
    Hammerhead Shark EverlastingGod's Avatar
    Join Date
    Feb 2003
    Location
    MD
    Posts
    1,364
    Assuming the .h file is included by a #include in one of the two .c files...

    gcc file1.c file2.c

    or

    gcc -c file1.c
    gcc -c file2.c
    gcc file1.o file2.o


    or

    gcc -c file1.c
    gcc file1.o file2.c


    or

    gcc -c file2.c
    gcc file2.o file1.c


    or

    any other variation on this

    Note: Add -o executablename if you want an program name other than the default one.
    Stay cool
    and be somebody's fool this year

  4. #4
    Catfish gameboy1234's Avatar
    Join Date
    Aug 2002
    Posts
    238

    echo "test: file1.c file2.c file.h" > Makefile
    echo " gcc -o test file1.c file2.c" >> Makefile
    make

    After that, just type "make" to rebuild. Only works in Unix land, or if you've installed msys and mingw on your Windows system. Makes an executable called test (or test.exe under windows).
    Last edited by gameboy1234; 09-25-2003 at 04:12 AM.

  5. #5
    Hammerhead Shark EverlastingGod's Avatar
    Join Date
    Feb 2003
    Location
    MD
    Posts
    1,364
    Originally posted by gameboy1234

    echo "test: file1.c file2.c file.h" > Makefile
    echo " gcc -o test file1.c file2.c" >> Makefile
    make
    I think the forum chopped the whitespace... should be a tab before "gcc"
    Stay cool
    and be somebody's fool this year

  6. #6
    Catfish gameboy1234's Avatar
    Join Date
    Aug 2002
    Posts
    238
    Yeah that's a tab not a space.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •