【发布时间】:2018-10-21 19:35:22
【问题描述】:
我想在不同的操作系统中测试我的程序,但 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.h 和 sched.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 */
}
【问题讨论】:
-
你可以找到一个用于 Solaris 的
gcc二进制文件,你可以从上面的源代码构建GCC。你应该在你的 Solaris 机器上试试man cc -
您可能应该删除
pthread_create中的(void*)转换为main_thread。但可以肯定的是,您需要提供一些minimal reproducible example -
显示
main_thread的签名。 -
另外,
new_args_sched(i, s)返回什么,还是宏? -
我编辑了我的帖子。对于 (void *) 如果我不使用它,我的 MacOS 中的 clang 无法识别它。 丢弃错误和警告消息是错误的方法。现在你知道为什么了。