Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8792267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:57:22+00:00 2026-06-13T22:57:22+00:00

I’m trying to compile a file from my application,with this action: – (IBAction)build:(id)sender {

  • 0

I’m trying to compile a file from my application,with this action:

- (IBAction)build:(id)sender
{
    pid_t pid=fork();
    int status;
    if(!pid)
    {
        execl("/Developer/usr/bin/gcc","-o main ~/main.c");
        exit(0);
    }
    waitpid(pid, &status, 0);
}

The file main.c in my home directory is not compiled (I don’t find the executable).
And I would know:
1)How to pass arguments to gcc? I am passing ~/main.c, but I would like to pass the filename with full path of my document.How do I get the NSDocument’s filename?
2)How do I get the console output?I also need to print the gcc output, how to do this?

Edit: I modified the code to compile the file saved from the application:

- (IBAction)build:(id)sender
{
    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath:@"/Developer/usr/bin/gcc"];
    [task setArguments: @[@"-o",@"main",[self fileURL]] ];
    NSPipe *pipe = [NSPipe pipe];
    [task setStandardOutput:pipe];
    NSFileHandle *file = [pipe fileHandleForReading];
    [task launch];
    NSData *data = [file readDataToEndOfFile];
    NSString *output = [[NSString alloc] initWithData:data
                                             encoding:NSUTF8StringEncoding];
    NSLog (@"gcc output:\n%@", output);
}

But whenever the build method gets executed that’s what I get:

2012-11-07 19:04:30.636 Coder[1856:303] -[NSURL fileSystemRepresentation]: unrecognized selector sent to instance 0x100154c40
2012-11-07 19:04:30.638 Coder[1856:303] -[NSURL fileSystemRepresentation]: unrecognized selector sent to instance 0x100154c40
2012-11-07 19:04:30.642 Coder[1856:303] (
    0   CoreFoundation                      0x00007fff95b060a6 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff909793f0 objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff95b9c6ea -[NSObject(NSObject) doesNotRecognizeSelector:] + 186
    3   CoreFoundation                      0x00007fff95af45ce ___forwarding___ + 414
    4   CoreFoundation                      0x00007fff95af43b8 _CF_forwarding_prep_0 + 232
    5   Foundation                          0x00007fff8cbf8e67 -[NSConcreteTask launchWithDictionary:] + 814
    6   Coder                               0x0000000100001734 -[Document build:] + 452
    7   AppKit                              0x00007fff8d266a59 -[NSApplication sendAction:to:from:] + 342
    8   AppKit                              0x00007fff8d2668b7 -[NSControl sendAction:to:] + 85
    9   AppKit                              0x00007fff8d2667eb -[NSCell _sendActionFrom:] + 138
    10  AppKit                              0x00007fff8d264cd3 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 1855
    11  AppKit                              0x00007fff8d264521 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 504
    12  AppKit                              0x00007fff8d263c9c -[NSControl mouseDown:] + 820
    13  AppKit                              0x00007fff8d25b60e -[NSWindow sendEvent:] + 6853
    14  AppKit                              0x00007fff8d257744 -[NSApplication sendEvent:] + 5761
    15  AppKit                              0x00007fff8d16d2fa -[NSApplication run] + 636
    16  AppKit                              0x00007fff8d111cb6 NSApplicationMain + 869
    17  Coder                               0x00000001000011a2 main + 34
    18  libdyld.dylib                       0x00007fff93a577e1 start + 0
    19  ???                                 0x0000000000000003 0x0 + 3
)

trojanfoe code was working, but with this modification it doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:57:23+00:00Added an answer on June 13, 2026 at 10:57 pm

    Use NSTask instead (reference).

    Untested:

    NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *sourceFile = [docDir stringByAppendingPathComponent:@"main.c"];
    NSString *outFile = [docDir stringByAppendingPathComponent:@"main"];
    
    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath:@"/Developer/usr/bin/gcc"];
    [task setArguments:[NSArray arrayWithObjects: @"-o", outFile, sourceFile, nil]];
    
    NSPipe *pipe = [NSPipe pipe];
    [task setStandardOutput:pipe];
    
    NSFileHandle *file = [pipe fileHandleForReading];
    
    [task launch];
    
    NSData *data = [file readDataToEndOfFile];
    
    NSString *output = [[NSString alloc] initWithData:data
                                             encoding:NSUTF8StringEncoding];
    NSLog (@"gcc output:\n%@", output);
    
    [output release];
    [task release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.