如何在 Solaris 中使用 cc 编译 c?

How to compile c using cc in Solaris?

我想在不同的 OS 中测试我的程序,但是 gcc 在 Solaris 中并不能正常工作,但是有 cc.

下面是我用 gcc 编译的方法:

gcc -c quicksort.c sched.c -g -pthread -O3
gcc -o quicksort quicksort.o sched.o -Wall -g -pthread -O3

我尝试使用相同的参数使用 cc 进行编译,但这是我得到的结果:

quicksort.c:
sched.c:
"sched.c", line 233: warning: argument #3 is incompatible with prototype:
        prototype: pointer to function(pointer to void) returning pointer to void : "/usr/include/pthread.h", line 197
        argument : pointer to void

ld: fatal :  soname option (-h, --soname) is incompatible with building a dynamic executable
ld: fatal :  flags processing errors

这是第一个错误所在的行:

pthread_create(&s->tab_thread[i], NULL, (void *) main_thread, new_args_sched(i, s));

new_args_sched 只是一个用于将参数传递给函数 main_thread

的结构

我不知道应该使用什么选项,我尝试了 -mt-lpthread 但没有用。我有 3 个文件 quicksort.c,主文件 sched.hsched.c

编辑

Solaris 计算机在 ssh 中,它不是我的,我无法配置它。 gcc 的版本是 3.4.3,仅使用 C90 我的代码使用 C11。只有 cc 应该可以工作,但我不知道如何正确编译...

我正在使用一个结构来传递 main_thread,就像这样:

struct sched_args {
    int i;
    struct scheduler *s;
};

struct sched_args *
new_args_sched(int i, struct scheduler *s) {
    struct sched_args *args = malloc(sizeof(struct sched_args));
    if(args == NULL)
        return NULL;

    args->i = i;
    args->s = s;
    return args;
}

所以这就是我在使用 pthread_create 时如何在我的函数中获取它:

void main_thread(void *closure) {
    struct sched_args *args = (struct sched_args *)closure;
    int i = args->i;
    struct scheduler *s = args->s
    /* doing something */
}

这个代码

void main_thread(void *closure) {
    struct sched_args *args = (struct sched_args *)closure;
    int i = args->i;
    struct scheduler *s = args->s
    /* doing something */
}

需要

void *main_thread(void *closure) {
    struct sched_args *args = (struct sched_args *)closure;
    int i = args->i;
    struct scheduler *s = args->s
    /* doing something */
    return( NULL );
}

pthread_create() POSIX-standard function为原型

int pthread_create(pthread_t *restrict thread,
   const pthread_attr_t *restrict attr,
   void *(*start_routine)(void*), void *restrict arg);

请注意,第三个参数的类型为 void *(*start_routine)(void*) - 采用 void * 参数 并返回 void * 的函数的地址.