当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 4 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : 编译求助
帖子发表于 : 2009-01-01 21:39 

注册: 2007-11-13 15:01
帖子: 27
送出感谢: 0 次
接收感谢: 0 次
#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 模块是怎么编译的。


页首
 用户资料  
 
2 楼 
 文章标题 : Re: 编译求助
帖子发表于 : 2009-01-03 21:22 

注册: 2008-12-17 15:55
帖子: 13
送出感谢: 0 次
接收感谢: 0 次
> newfile3.c:62: 错误: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘method’
一般情况是因为头文件没有正确包含进来,无法解析typedef类型,查一下62行,method前的类型定义。一种办法是gcc -save-temps ... 查一下预处理后的文件 newfile3.i 定义该类型的头文件是否被包含进来。


页首
 用户资料  
 
3 楼 
 文章标题 : Re: 编译求助
帖子发表于 : 2009-01-04 20:49 

注册: 2008-11-26 9:50
帖子: 17
送出感谢: 0 次
接收感谢: 0 次
我同意楼山的意见,应该是头文件的问题


页首
 用户资料  
 
4 楼 
 文章标题 : Your view is awesome!.
帖子发表于 : 2009-01-15 22:06 

注册: 2009-01-05 2:30
帖子: 20
送出感谢: 0 次
接收感谢: 0 次
Your view is awesome!






___________________________________________________________________
EVE ISK
Lotro Gold
Maple Story Mesos


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 4 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 2 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译