GCC


19 posts
by ZacharyI123 » Sun Jun 17, 2012 1:12 pm
How do I set up/download/configure GCC to compile c and objective c foundation code?

Would I use terminal for gcc or what?

What would I type in terminal to compile c and objective c foundation?
Don't be mean, I'm only thirteen 8-)
User avatar
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
by jecxjo » Sun Jun 17, 2012 3:42 pm
Which distro are you running? For example if you are running Arch you'd want to install base-devel which includes everything you need for c/c++ development (includes make, patch, binutils, etc). If you are looking for objective C then you'd want to install gcc-objc. For Debian you should install gcc and gobjc

Archlinux
Code: Select all
pacman -S base-devel
pacman -S gcc-objc


Debian
Code: Select all
apt-get install gcc
apt-get install gobjc


As for the Foundation Framework I assume you are looking for OSX development and not NeXTSTEP or GNUStep. I don't do OSX Development but AFAIK you can't build anything outside of a Mac running OSX. But I'm sure there are some OSX Devs on here that can give you more info.
IRC (w/ SSL Support): jecxjo.mdns.org
Blog: http://jecxjo.motd.org/code
ProjectEuler Friend: 79556084281370_44d12dd95e92b1d9453aba2bdc94101b
User avatar
Posts: 157
Joined: Sat May 19, 2012 5:22 pm
Location: Ames, IA (USA)
by ZacharyI123 » Sun Jun 17, 2012 4:47 pm
jecxjo wrote:Which distro are you running? For example if you are running Arch you'd want to install base-devel which includes everything you need for c/c++ development (includes make, patch, binutils, etc). If you are looking for objective C then you'd want to install gcc-objc. For Debian you should install gcc and gobjc

Archlinux
Code: Select all
pacman -S base-devel
pacman -S gcc-objc


Debian
Code: Select all
apt-get install gcc
apt-get install gobjc


As for the Foundation Framework I assume you are looking for OSX development and not NeXTSTEP or GNUStep. I don't do OSX Development but AFAIK you can't build anything outside of a Mac running OSX. But I'm sure there are some OSX Devs on here that can give you more info.


I will be using Debian. Would I run that code before I load the UI or in terminal? Also, from there how would I compile c and objective c foundation?
Don't be mean, I'm only thirteen 8-)
User avatar
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
by jecxjo » Sun Jun 17, 2012 4:54 pm
You can install software from a terminal. From that point you can use gcc to compile C code. Let me see if we can possible get some sticky threads up in the language specific forums on some good tutorials for the languages. Are you new to C/ObjC development?

For the moment, this other thread covers a bit on how to create functions but the basics of using gcc are covered at the end.
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=33&t=8316
IRC (w/ SSL Support): jecxjo.mdns.org
Blog: http://jecxjo.motd.org/code
ProjectEuler Friend: 79556084281370_44d12dd95e92b1d9453aba2bdc94101b
User avatar
Posts: 157
Joined: Sat May 19, 2012 5:22 pm
Location: Ames, IA (USA)
by ZacharyI123 » Sun Jun 17, 2012 4:58 pm
jecxjo wrote:You can install software from a terminal. From that point you can use gcc to compile C code. Let me see if we can possible get some sticky threads up in the language specific forums on some good tutorials for the languages. Are you new to C/ObjC development?

For the moment, this other thread covers a bit on how to create functions but the basics of using gcc are covered at the end.
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=33&t=8316


Once I've installed it what is the exact code to compile a .c file and a .m file and how do I set the directory. I'm not new to c or obj c it's just all this unix stuff :s
Don't be mean, I'm only thirteen 8-)
User avatar
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
by jecxjo » Sun Jun 17, 2012 5:06 pm
ZacharyI123 wrote:Once I've installed it what is the exact code to compile a .c file and a .m file and how do I set the directory. I'm not new to c or obj c it's just all this unix stuff :s


Ah ok. Well the bare minimum for C files is
Code: Select all
gcc -c file1.c
gcc -c file2.c
gcc -o prog file1.o file2.o


gcc can now compile objective c file once you've installed the packaged listed above.
Code: Select all
gcc -o hello hello.m -lobjc


Just as an FYI there are tons more flags so you'll want to read up on the GCC documentation for how they all work.
IRC (w/ SSL Support): jecxjo.mdns.org
Blog: http://jecxjo.motd.org/code
ProjectEuler Friend: 79556084281370_44d12dd95e92b1d9453aba2bdc94101b
User avatar
Posts: 157
Joined: Sat May 19, 2012 5:22 pm
Location: Ames, IA (USA)
by ZacharyI123 » Sun Jun 17, 2012 7:29 pm
jecxjo wrote:
ZacharyI123 wrote:Once I've installed it what is the exact code to compile a .c file and a .m file and how do I set the directory. I'm not new to c or obj c it's just all this unix stuff :s


Ah ok. Well the bare minimum for C files is
Code: Select all
gcc -c file1.c
gcc -c file2.c
gcc -o prog file1.o file2.o


gcc can now compile objective c file once you've installed the packaged listed above.
Code: Select all
gcc -o hello hello.m -lobjc


Just as an FYI there are tons more flags so you'll want to read up on the GCC documentation for how they all work.


Which ones do what and what are the files and output files? Also can you send me the GCC docs.
Don't be mean, I'm only thirteen 8-)
User avatar
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
by ZacharyI123 » Sun Jun 17, 2012 8:36 pm
jecxjo wrote:
ZacharyI123 wrote:Once I've installed it what is the exact code to compile a .c file and a .m file and how do I set the directory. I'm not new to c or obj c it's just all this unix stuff :s


Ah ok. Well the bare minimum for C files is
Code: Select all
gcc -c file1.c
gcc -c file2.c
gcc -o prog file1.o file2.o


gcc can now compile objective c file once you've installed the packaged listed above.
Code: Select all
gcc -o hello hello.m -lobjc


Just as an FYI there are tons more flags so you'll want to read up on the GCC documentation for how they all work.


Does this work:

cd /directoryoffile/

gcc -o hello hello.m -lobjc

Or 

gcc hello.c -o hello
Don't be mean, I'm only thirteen 8-)
User avatar
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
by johnbeetem » Sun Jun 17, 2012 8:37 pm
ZacharyI123 wrote:Also can you send me the GCC docs.


GCC docs are available here: http://gcc.gnu.org/onlinedocs/
User avatar
Posts: 942
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Coast
by jecxjo » Sun Jun 17, 2012 10:15 pm
ZacharyI123 wrote:
jecxjo wrote:
ZacharyI123 wrote:Once I've installed it what is the exact code to compile a .c file and a .m file and how do I set the directory. I'm not new to c or obj c it's just all this unix stuff :s


Ah ok. Well the bare minimum for C files is
Code: Select all
gcc -c file1.c
gcc -c file2.c
gcc -o prog file1.o file2.o


gcc can now compile objective c file once you've installed the packaged listed above.
Code: Select all
gcc -o hello hello.m -lobjc


Just as an FYI there are tons more flags so you'll want to read up on the GCC documentation for how they all work.


Does this work:

cd /directoryoffile/

gcc -o hello hello.m -lobjc

Or 

gcc hello.c -o hello


Depends on if you are working with Objective C or C99/ANSI C. Looking at the file extensions should give away that hello.m is an Objective-C file and hello.c is a C file. Maybe I'm not understanding what your issue is.
IRC (w/ SSL Support): jecxjo.mdns.org
Blog: http://jecxjo.motd.org/code
ProjectEuler Friend: 79556084281370_44d12dd95e92b1d9453aba2bdc94101b
User avatar
Posts: 157
Joined: Sat May 19, 2012 5:22 pm
Location: Ames, IA (USA)
by ZacharyI123 » Mon Jun 18, 2012 2:49 pm
I want to compile an objective c file which starts by importing foundation. It is command line.

Is that the correct code?

Also is this correct for c
gcc something.c -o something
?
Don't be mean, I'm only thirteen 8-)
User avatar
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
by jecxjo » Mon Jun 18, 2012 3:07 pm
ZacharyI123 wrote:I want to compile an objective c file which starts by importing foundation. It is command line.

Is that the correct code?


Are you asking how to import Foundation Code?

Also is this correct for c
gcc something.c -o something
?


This line will both compile and link the C file and generate a binary output (32bit ELF).
IRC (w/ SSL Support): jecxjo.mdns.org
Blog: http://jecxjo.motd.org/code
ProjectEuler Friend: 79556084281370_44d12dd95e92b1d9453aba2bdc94101b
User avatar
Posts: 157
Joined: Sat May 19, 2012 5:22 pm
Location: Ames, IA (USA)
by ZacharyI123 » Mon Jun 18, 2012 3:34 pm
Yes foundation objective c code?
Don't be mean, I'm only thirteen 8-)
User avatar
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
by tufty » Mon Jun 18, 2012 5:16 pm
ZacharyI123 wrote:Yes foundation objective c code?

Ok. Foundation.framework is part of OSX. It doesn't generally exist under linux.

You may be able to get around this by installing gnustep, which is a gpl implementation of much of openstep 4.2, which latter went on to become osx. I'm not sure where gnustep is wrt osx source code compatibility. Apple have changed a lot of stuff since 2000.

Simon
Posts: 1368
Joined: Sun Sep 11, 2011 2:32 pm
by ZacharyI123 » Mon Jun 18, 2012 5:26 pm
Exactly how would I install the stuff so I can use the following to compile c?
gcc a.c -o a

How would I compile and install the compiler that would compile the following when saved in a text editor as a .m file?

#import <Foundation/Foundation.h>
#import <math.h>

@interface mainObj: Object {}
-(void)main;
@end

@implementation mainObj

NSString *function(int input)
{
    char* numbers[10];
    numbers[0] = "";
    numbers[1] = "one";
    numbers[2] = "two";
    numbers[3] = "three";
    numbers[4] = "four";
    numbers[5] = "five";
    numbers[6] = "six";
    numbers[7] = "seven";
    numbers[8] = "eight";
    numbers[9] = "nine";
    
    char* tens[10];
    tens[0] = "";
    tens[1] = "ten";
    tens[2] = "twenty";
    tens[3] = "thirty";
    tens[4] = "forty";
    tens[5] = "fifty";
    tens[6] = "sixty";
    tens[7] = "seventy";
    tens[8] = "eighty";
    tens[9] = "ninety";
    
    char* teens[10];
    teens[0] = "ten";
    teens[1] = "eleven";
    teens[2] = "twelve";
    teens[3] = "thirteen";
    teens[4] = "fourteen";
    teens[5] = "fifteen";
    teens[6] = "sixteen";
    teens[7] = "seventeen";
    teens[8] = "eighteen";
    teens[9] = "nineteen";
    
    int iDig = input%10;
    input /= 10;
    int iTen = input%10;
    input /= 10;
    int iHundred = input%10;
    
    if (iTen==0 && iDig==0 && iHundred>0) {
        return [NSString stringWithFormat:@"%s hundred",numbers[iHundred]];
    } else if (iTen == 1 && iHundred>0) {
        return [NSString stringWithFormat:@"%s hundred and %s\n",numbers[iHundred], teens[iDig]];
    } else if (iHundred>0) {
        return [NSString stringWithFormat:@"%s hundred and %s %s\n",numbers[iHundred], tens[iTen], numbers[iDig]];
    } else {
        return [NSString stringWithFormat:@"%s %s",tens[iTen], numbers[iDig]];
    }
}

-(void)main {
            int input;
            scanf("%d",&input);
            
            int iDig = input%1000;
            input /= 1000;
            int iThousand = input%1000;
            input /= 1000;
            int iMillion = input%1000;
            input /= 1000;
            int iBillion = input%1000;
            input /= 1000;
            int iTrillion = input%1000;
            
            if (iTrillion>0) {
                NSLog(@"%@ trillion", function(iTrillion));
            } if (iBillion>0) {
                NSLog(@"%@ billion", function(iBillion));
            } if (iMillion>0) {
                NSLog(@"%@ million", function(iMillion));
            } if (iThousand>0) {
                NSLog(@"%@ thousand", function(iThousand));
            } if (iDig>0) {
                NSLog(@"%@", function(iDig));
            }
}

int main() {
  id obj=[[mainObj alloc] init];
  [obj main];
  return 0;
}
@end
Don't be mean, I'm only thirteen 8-)
User avatar
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
by jecxjo » Mon Jun 18, 2012 5:33 pm
Exactly how would I install the stuff so I can use the following to compile c?
gcc a.c -o a


Previous posts have covered how you install the compiler. GNUstep can be installed in Debian via apt-get. Notice how we installed the compiler the same way in a previous post.

Code: Select all
sudo apt-get install gnustep


Here is a link to the GNUstep tutorial provided by the creators of GCC.

http://www.nongnu.org/gstutorial/en/index.html

Also if you read the GCC documentation provided by johnbeetem you'll get an understanding for all the flags you need.
IRC (w/ SSL Support): jecxjo.mdns.org
Blog: http://jecxjo.motd.org/code
ProjectEuler Friend: 79556084281370_44d12dd95e92b1d9453aba2bdc94101b
User avatar
Posts: 157
Joined: Sat May 19, 2012 5:22 pm
Location: Ames, IA (USA)
by ZacharyI123 » Mon Jun 18, 2012 6:28 pm
I would run that install code in terminal.

To compile a c file (import stdio)
gcc a.c -o a

To compile objective c foundation (import foundation)

$ gcc -o hello hello.m -framework Foundation

$ gcc -o hello hello.m -I /usr/lib/GNUstep/System/Library/Headers \
-L /usr/lib/GNUstep/System/Library/Libraries/ -lgnustep-base \
-fconstant-string-class=NSConstantString


$ gcc -o hello hello.m -I /usr/include/GNUstep/ -L /usr/lib/GNUstep/ \
-lgnustep-base -fconstant-string-class=NSConstantString


$ gcc -o hello hello.m -I /GNUstep/System/Library/Headers \
-L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base
Info: resolving ___objc_class_name_NXConstantString by linking to __imp____objc_class_name_NXConstantString (auto-import)
Info: resolving ___objc_class_name_NSObject by linking to __imp____objc_class_name_NSObject (auto-import)

Which?

Also, would I use cd to set the directory of the input and output files?
Don't be mean, I'm only thirteen 8-)
User avatar
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
by jecxjo » Mon Jun 18, 2012 7:22 pm
In Debian you can find out the files install by a package via apt-file.

Code: Select all
apt-file list gnustep


From there you should be able to figure out what the locations of the header and library files are to input into your -L and -I flags. As of this point have you checked any of the locations supplied by the flags in your choices? If you go through the tutorials and documentation for GCC's implementation of Object C the purpose of the flags should make it obvious on what you should be looking for.

From your multiple choice question the last one is obviously not correct as the package would not install directly to root like that (/GNUstep). Please do a little bit of searching before you post again. Better to understand what you are doing than someone just telling you.

ZacharyI123 wrote:Also, would I use cd to set the directory of the input and output files?


Not sure what you mean here.
IRC (w/ SSL Support): jecxjo.mdns.org
Blog: http://jecxjo.motd.org/code
ProjectEuler Friend: 79556084281370_44d12dd95e92b1d9453aba2bdc94101b
User avatar
Posts: 157
Joined: Sat May 19, 2012 5:22 pm
Location: Ames, IA (USA)
by jamesh » Mon Jun 18, 2012 9:39 pm
Just like to reiterate what jecxjo said - please do at least some research before asking further questions. To me you sound like someone who is trying to get someone else to do their homework...Everything you need has been mentioned above, and with a little work you should be able to achieve what you want.
Soon to be employed engineer - Hurrah! Volunteer at the Raspberry Pi Foundation, helper at PiAcademy September 2014.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11926
Joined: Sat Jul 30, 2011 7:41 pm