GCC生成.o文件而不是可执行文件

12

我正在尝试调试claws-mail通知插件,我的代码类似于:

#include "notification_indicator.h"
#include "notification_prefs.h"
#include "notification_core.h"

#include "folder.h"
#include "common/utils.h"

#include <messaging-menu.h>
#include <unity.h>

#define CLAWS_DESKTOP_FILE "claws-mail.desktop"

#include <stdio.h>

void main(void)
{
  GList *cur_mb;
  gint total_message_count;


  total_message_count = 0;
  /* check accounts for new/unread counts */
  for(cur_mb = folder_get_list(); cur_mb; cur_mb = cur_mb->next) {
    Folder *folder = cur_mb->data;
    NotificationMsgCount count;

    if(!folder->name) {
      printf("Notification plugin: Warning: Ignoring unnamed mailbox in indicator applet\n");
      continue;
    }
    gchar *id = folder->name;
    notification_core_get_msg_count_of_foldername(folder->name, &count);
    printf("%s: %d\n", folder->name, count.unread_msgs);
  }
}

我正在使用以下命令编译它:

gcc  -I/home/kuba/Pobrane/claws-mail-3.13.2/src/
     -I/usr/include/gtk-2.0/
     -I/usr/include/cairo/
     -I/usr/include/pango-1.0
     -I/usr/lib/i386-linux-gnu/gtk-2.0/include/
     -I/usr/include/gdk-pixbuf-2.0/
     -I/usr/include/atk-1.0/
     -I/home/kuba/Pobrane/claws-mail-3.13.2/src/common
     -I/home/kuba/Pobrane/claws-mail-3.13.2/src/gtk
     -I/usr/include/messaging-menu/
     -I/usr/include/unity/unity/
     -I/usr/include/dee-1.0/
     -I/usr/include/libdbusmenu-glib-0.4/
     -c `pkg-config --cflags glib-2.0` test.c

但是gcc创建的对象文件是test.o而不是a.out,我该如何创建可执行文件?我在Xubuntu上运行。


2
这就是“-c”选项的全部意义所在。它告诉编译器只创建一个目标文件而不是链接成可执行文件。如果你不想要这个,就不要使用这个选项。 - Barmar
1个回答

21

从命令行中移除-c选项(该选项生成目标文件而不是可执行文件)。

来自man gcc

-c
编译或汇编源文件,但不进行链接。链接阶段根本没有完成。每个源文件的最终输出形式是一个目标文件。

示例:

生成目标文件(`.o' 文件)的命令:

gcc -c test.c 
生成可执行文件的方法为:
gcc test.c -o test
(如果省略-o test,根据惯例它会生成可执行文件a.out。)

为什么你不给一个像 gcc -c file2alias.c 这样的例子呢?我是在寻找生成 .o 文件而不是可执行文件的方法,抱歉。 - Sérgio
@Sérgio 因为问题不是那个!无论如何,我现在已经添加了几个例子。 - P.P
现在,我可以改变我的投票 :) ,谢谢。 - Sérgio

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接