编译求助

软件和网站开发以及相关技术探讨
回复
wangwg2007
帖子: 27
注册时间: 2007-11-13 15:01

编译求助

#1

帖子 wangwg2007 » 2009-01-01 21:39

#include <stdio.h>
#include <libgnomevfs/gnome-vfs.h>
#include <libgnomevfs/gnome-vfs-utils.h>

static GnomeVFSMethod method = {
sizeof (GnomeVFSMethod),
do_open, /* open */
do_create, /* create */
do_close, /* close */
do_read, /* read */
do_write, /* write */
NULL, /* seek */
NULL, /* tell */
NULL, /* truncate_handle */
do_open_directory, /* open_directory */
do_close_directory, /* close_directory */
do_read_directory, /* read_directory */
do_get_file_info, /* get_file_info */
NULL, /* get_file_info_from_handle */
do_is_local, /* is_local */
do_make_directory, /* make_directory */
do_remove_directory, /* remove_directory */
NULL, /* move */
do_unlink, /* unlink */
NULL, /* check_same_fs */
NULL, /* set_file_info */
NULL, /* truncate */
NULL, /* find_directory */
NULL, /* create_symbolic_link */
NULL, /* monitor_add */
NULL, /* monitor_cancel */
NULL /* file_control */
};

GnomeVFSMethod *
vfs_module_init (const char *method_name, const char *args)
{
return &method;
}

void
vfs_module_shutdown (GnomeVFSMethod *method)
{
}



static GnomeVFSResult
do_open_directory (GnomeVFSMethod *method,
GnomeVFSMethodHandle **method_handle,
GnomeVFSURI *uri,
GnomeVFSFileInfoOptions options,
GnomeVFSContext *context)
{
DirHandle *handle;
FakeNode *file;
handle = g_new0 (DirHandle, 1);
handle->options = options;

file = get_fake_node_from_uri (uri);
if (file) {
handle->gnode = file->gnode;
handle->current_child = handle->gnode->children;
} else {
return GNOME_VFS_ERROR_NOT_FOUND;
}
*method_handle = (GnomeVFSMethodHandle *) handle;
return GNOME_VFS_OK;
}

static GnomeVFSResult
do_read_directory (GnomeVFSMethod *method,
GnomeVFSMethodHandle *method_handle,
GnomeVFSFileInfo *file_info,
GnomeVFSContext *context)
{
DirHandle *handle = (DirHandle *) method_handle;
FakeNode *file;

if (!handle->current_child) {
return GNOME_VFS_ERROR_EOF;
}

file = handle->current_child->data;

if (file->directory) {
file_info->type = GNOME_VFS_FILE_TYPE_DIRECTORY;
file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_TYPE;
file_info->mime_type = g_strdup ("x-directory/normal");
file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE;
} else {
file_info->type = GNOME_VFS_FILE_TYPE_REGULAR;
file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_TYPE;
file_info->mime_type = g_strdup ("text/plain");
file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE;
file_info->size = file->size;
file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_SIZE;
}
file_info->name = g_strdup (file->name);
handle->current_child = handle->current_child->next;
return GNOME_VFS_OK;
}


static GnomeVFSResult
do_close_directory (GnomeVFSMethod *method,
GnomeVFSMethodHandle *method_handle,
GnomeVFSContext *context)
{
DirHandle *handle = (DirHandle *) method_handle;
g_free (handle);
return GNOME_VFS_OK;
}



static GnomeVFSResult
do_open (GnomeVFSMethod *method,
GnomeVFSMethodHandle **method_handle,
GnomeVFSURI *uri,
GnomeVFSOpenMode mode,
GnomeVFSContext *context)
{
FakeNode *file;
FileHandle *handle;
file = get_fake_node_from_uri (uri);
if (file && file->directory) {
return GNOME_VFS_ERROR_IS_DIRECTORY;
}
/* We don't support random mode. */
if (mode & GNOME_VFS_OPEN_RANDOM) {
return GNOME_VFS_ERROR_INVALID_OPEN_MODE;
}
if (mode & GNOME_VFS_OPEN_WRITE) {
/* Only handle reading so far */
/* Add the code to write here later in the tutorial */
return GNOME_VFS_ERROR_READ_ONLY;
} else if (mode & GNOME_VFS_OPEN_READ) {
file = get_fake_node_from_uri (uri);
if (!file) {
return GNOME_VFS_ERROR_NOT_FOUND;
}
} else {
return GNOME_VFS_ERROR_INVALID_OPEN_MODE;
}
handle = g_new0 (FileHandle, 1);
handle->fnode = file;
*method_handle = (GnomeVFSMethodHandle *) handle;
return GNOME_VFS_OK;
}


static GnomeVFSResult
do_read (GnomeVFSMethod *method,
GnomeVFSMethodHandle *method_handle,
gpointer buffer,
GnomeVFSFileSize bytes,
GnomeVFSFileSize *bytes_read,
GnomeVFSContext *context)
{
FileHandle *handle = (FileHandle *) method_handle;
if (!handle->str) {
/* This is the first pass, get the content string. */
handle->str = g_strdup (handle->fnode->content);
handle->size = handle->fnode->size;
handle->bytes_written = 0;
}
if (handle->bytes_written >= handle->len) {
/* The whole file is read, return EOF. */
*bytes_read = 0;
return GNOME_VFS_ERROR_EOF;
}
*bytes_read = MIN (bytes, handle->size - handle->bytes_written);
memcpy (buffer, handle->str + handle->bytes_written, *bytes_read);
handle->bytes_written += *bytes_read;
return GNOME_VFS_OK;
}


static GnomeVFSResult
do_close (GnomeVFSMethod *method,
GnomeVFSMethodHandle *method_handle,
GnomeVFSContext *context)
{
FileHandle *handle = (FileHandle *) method_handle;

g_free (handle->str);
g_free (handle);

return GNOME_VFS_OK;
}

static gboolean
do_is_local (GnomeVFSMethod *method,
const GnomeVFSURI *uri)
{
return TRUE;
}

static GnomeVFSResult
do_get_file_info (GnomeVFSMethod *method,
GnomeVFSURI *uri,
GnomeVFSFileInfo *file_info,
GnomeVFSFileInfoOptions options,
GnomeVFSContext *context)
{
FakeNode *file;

file = get_fake_node_from_uri (uri);
if (!file) {
return GNOME_VFS_ERROR_NOT_FOUND;
}

if (file->gnode == root) {
/* Root directory. */
file_info->name = g_strdup ("Tutorial");
} else {
file_info->name = g_strdup (file->name);
}

if (file->directory) {
file_info->type = GNOME_VFS_FILE_TYPE_DIRECTORY;
file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_TYPE;
file_info->mime_type = g_strdup ("x-directory/normal");
file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE;
} else {
file_info->type = GNOME_VFS_FILE_TYPE_REGULAR;
file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_TYPE;
file_info->mime_type = g_strdup ("text/plain");
file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE;
file_info->size = file->size;
file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_SIZE;
}

return GNOME_VFS_OK;
}


编译总是出错误
gcc -c -g -I/usr/include/gnome-vfs-module-2.0 -I/usr/include/gnome-vfs-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libxml2 -I/usr/include/gconf/2 -I/usr/include/orbit-2.0 -I/usr/include -MMD -MP -MF build/Debug/GNU-Linux-x86/newfile3.o.d -o build/Debug/GNU-Linux-x86/newfile3.o newfile3.c
newfile3.c:62: 错误: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘method’
newfile3.c:92: 错误: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
newfile3.c:99: 错误: expected ‘)’ before ‘*’ token
newfile3.c:106: 错误: expected ‘)’ before ‘*’ token
newfile3.c:129: 错误: expected ‘)’ before ‘*’ token
newfile3.c:163: 错误: expected ‘)’ before ‘*’ token
newfile3.c:175: 错误: expected ‘)’ before ‘*’ token
newfile3.c:211: 错误: expected ‘)’ before ‘*’ token
newfile3.c:238: 错误: expected ‘)’ before ‘*’ token
newfile3.c:251: 错误: expected ‘)’ before ‘*’ token
newfile3.c:258: 错误: expected ‘)’ before ‘*’ token
make: *** [build/Debug/GNU-Linux-x86/newfile3.o] 错误 1

生成 失败。 退出值 2。

有哪位大侠看出是怎么回事,
另外,求助Gnome VFS 模块是怎么编译的。
EricFisher
帖子: 13
注册时间: 2008-12-17 15:55

Re: 编译求助

#2

帖子 EricFisher » 2009-01-03 21:22

> newfile3.c:62: 错误: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘method’
一般情况是因为头文件没有正确包含进来,无法解析typedef类型,查一下62行,method前的类型定义。一种办法是gcc -save-temps ... 查一下预处理后的文件 newfile3.i 定义该类型的头文件是否被包含进来。
qter007
帖子: 17
注册时间: 2008-11-26 9:50

Re: 编译求助

#3

帖子 qter007 » 2009-01-04 20:49

我同意楼山的意见,应该是头文件的问题
vg471448
帖子: 20
注册时间: 2009-01-05 2:30

Your view is awesome!.

#4

帖子 vg471448 » 2009-01-15 22:06

Your view is awesome!






___________________________________________________________________
EVE ISK
Lotro Gold
Maple Story Mesos
回复