libpd / pd-for-ios

Pure Data for iOS
Other
265 stars 72 forks source link

'system' is unavailable: ... on iOS error - with the recent Xcode 9 #19

Open o-g-sus opened 6 years ago

o-g-sus commented 6 years ago

I have seen that people worked on that issue, but I still get an error with Xcode 9

s_file.c creates an error with system(cmdbuf);

static void sys_putpreference(const char key, const char value) { char cmdbuf[MAXPDSTRING]; snprintf(cmdbuf, MAXPDSTRING, "defaults write org.puredata.pd %s \"%s\" 2> /dev/null\n", key, value); system(cmdbuf); }

virusys commented 6 years ago

I just commented out the “system(cmdbuf)” line to get around this error and build my project with Xcode 9.

I know it’s not really a fix but I don’t really know any situations where you would need this to work with libpd projects. I could be wrong!

-c

On Sep 28, 2017, at 6:53 AM, Oliver Greschke notifications@github.com wrote:

I have seen that people worked on that issue, but I sill get it with Xcode 9

s_file.c creates an error with system(cmdbuf);

static void sys_putpreference(const char key, const char value) { char cmdbuf[MAXPDSTRING]; snprintf(cmdbuf, MAXPDSTRING, "defaults write org.puredata.pd %s "%s" 2> /dev/null\n", key, value); system(cmdbuf); }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/libpd/pd-for-ios/issues/19, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYB726dfpzS7IAg-ab1x-17J1ch3ARwks5sm3qYgaJpZM4PnFEq.

mariusjcb commented 6 years ago

My fix (using posix_spawn) for this problem:

#include <spawn.h>

extern char **environ;

void run_cmd(char *cmd)
{
    pid_t pid;
    char *argv[] = {"sh", "-c", cmd, NULL};
    int status;

    status = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ);
    if (status == 0) {
        if (waitpid(pid, &status, 0) == -1) {
            perror("waitpid");
        }
    }
}

and call run_cmd(cmdbuf); instead of system(cmdbuf);

danomatika commented 6 years ago

The fix is to simply not build s_file.c with the newer pd sources. This will be fixed in the next version of libpd which will come out soon, but you can try the current master if you need to be able to build/test for now.

danomatika commented 6 years ago

Also, problems like these are better opened on the main libpd repository as this repo is mainly for hosting the iOS examples.

NotAlexNoyle commented 6 years ago

@mariusjcb Your fix is great, thank you. Has helped me a lot over the last few months.