西姆格。如何将main.c分成几部分?

Simgrid. How to divide main.c into parts?

这是master-worker的例子。 main.c 文件由三个函数组成,结构如下:

#include <simgrid/msg.h>
XBT_LOG_NEW_DEFAULT_CATEGORY(tuto, "all the info and defbug messages of this tutorial");

int master(int argc, char *argv[]){...}
int worker(int argc, char *argv[]){...}
int main(argc, char *argv[]){...}

我想将main.c分成三个文件:main.cworker.cmaster.c。 但是如果我写

XBT_LOG_NEW_DEFAULT_CATEGORY(tuto, "all the info and debug messages of this tutorial") 在每个文件中它都会给出一个错误:

multiple definition of `_simgrid_log_category__tuto__constructor__'

如果我只定义一次我就不能在其他文件中使用XBT_INFO。 如何避免?

XBT_LOG_NEW_DEFAULT_CATEGORY(tuto, "...") 定义了一个日志记录类别,因此您应该只在一个 .c 文件中使用它。您可以在另一个文件中声明(和使用)此类别:

XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tuto);

一旦你在一个文件中调用了这些宏之一,你就可以在这个文件中使用 XBT_INFO(...) 和朋友。