用Cygwin无法编译! [英] Can't compile this with Cygwin!

查看:61
本文介绍了用Cygwin无法编译!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用winXP并安装了Cygwin。我使用Dev-C ++和Cygwin

编译器,但由于某种原因我不能编译这段代码:


#include< setjmp.h> ;

#include< stdio.h>

#include< stdlib.h>

typedef int othread_t;


typedef struct _othread_attr_t {

} othread_attr_t;


#define STACK_SIZE 1024

struct pcb {

void *(* start_routine)(void *);

void * arg;

jmp_buf state;

int stak [STACK_SIZE];

};


静态struct pcb first_thread;


struct pcb * current =& ; first_thread;

struct pcb * ready = NULL;

int othread_create(othread_t * threadp,

const othread_attr_t * attr,

void *(* start_routine)(void *),

void * arg)

{

int * state_pointer;

int lokalt_reserveret;


struct pcb * pcb_pointer;


pcb_pointer =(struct pcb *)malloc(sizeof(struct pcb));

if(pcb_pointer == NULL){


exit(-1);

}


pcb_pointer-> start_routine = start_routine;

pcb_pointer-> arg = arg;


if(setjmp(pcb_pointer-> state)){


current-> start_routine(current-> arg);


printf(" en tr?d harreneretre - alt stoppes\\\
);

退出(0);

}


state_pointer =(int *)& pcb_pointer-> state;

lokalt_reserveret = state_pointer [JB_BP] ​​- state_pointer [JB_SP];

state_pointer [JB_BP] =(int)(pcb_pointer-> stak + STACK_SIZE);

state_pointer [JB_SP] =(int)state_pointer [JB_BP] ​​- lokalt_reserveret;

ready = pcb_pointer;

* threadp =(int)pcb_pointer;


返回0;

}

int othread_yield(void)

{

if(ready!= NULL){


struct pcb * old = curren t;

current = ready;

ready = old;

if(setjmp(old-> state)== 0){

longjmp(当前 - >州,1);

}

}


返回0 ;

}


void * other(void * arg)

{

printf(" ;来自其他人的世界\ n");


othread_yield();


printf(其他仍然强大的\ n ;);


othread_yield();


printf(来自其他人的再见世界);


返回NULL;

}

int main(无效)

{

othread_t t1;


othread_create(& t1,NULL,other,NULL);


printf("来自main \\\
的Hello world) ;);


othread_yield();


printf(" main still going strong\\\
);


othread_yield();


printf("来自main \ n的再见世界);


othread_yield();

printf(永远不会到达\ n);


返回0;

}


我得到的错误是:


56 H:\thread\thread.c`JB_BP''未申报(首次使用此处)功能)

(每个未声明的标识符只报告一次

,对于它出现的每个功能。)


56 H:\\ \\ _thread\thread.c`JB_SP''未声明(首次使用此函数)

make H:\thread\make *** [thread.o]错误1


当我在Linux上编译相同的代码时它运行正常!但我确信我使用Cygwin这样就可以和使用Linux一样好了。


希望有人可以提供帮助

I use winXP and have installed Cygwin. I use Dev-C++ and the Cygwin
compiler, but for some reason I can''t compile this code:

#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
typedef int othread_t;

typedef struct _othread_attr_t {
} othread_attr_t;

#define STACK_SIZE 1024
struct pcb {
void *(*start_routine) (void *);
void *arg;
jmp_buf state;
int stak[STACK_SIZE];
};

static struct pcb first_thread;

struct pcb *current = &first_thread;
struct pcb *ready = NULL;

int othread_create (othread_t *threadp,
const othread_attr_t *attr,
void *(*start_routine) (void *),
void *arg)
{
int *state_pointer;
int lokalt_reserveret;

struct pcb *pcb_pointer;

pcb_pointer = (struct pcb *) malloc(sizeof(struct pcb));
if(pcb_pointer == NULL) {

exit(-1);
}

pcb_pointer->start_routine = start_routine;
pcb_pointer->arg = arg;

if(setjmp(pcb_pointer->state)) {

current->start_routine(current->arg);

printf("En tr?d har returneret - alt stoppes\n");
exit(0);
}

state_pointer = (int *) &pcb_pointer->state;
lokalt_reserveret = state_pointer[JB_BP] - state_pointer[JB_SP];
state_pointer[JB_BP] = (int) (pcb_pointer->stak + STACK_SIZE);
state_pointer[JB_SP] = (int) state_pointer[JB_BP] - lokalt_reserveret;
ready = pcb_pointer;
*threadp = (int) pcb_pointer;

return 0;
}
int othread_yield (void)
{
if(ready != NULL) {

struct pcb *old = current;
current = ready;
ready = old;
if(setjmp(old->state) == 0) {
longjmp(current->state, 1);
}
}

return 0;
}

void *other(void *arg)
{
printf("Hello world from other\n");

othread_yield();

printf("other still going strong\n");

othread_yield();

printf("Godbye world from other\n");

return NULL;
}
int main(void)
{
othread_t t1;

othread_create(&t1, NULL, other, NULL);

printf("Hello world from main\n");

othread_yield();

printf("main still going strong\n");

othread_yield();

printf("Godbye world from main\n");

othread_yield();
printf("Is never reached\n");

return 0;
}

The error I get is:

56 H:\thread\thread.c `JB_BP'' undeclared (first use in this function)
(Each undeclared identifier is reported only once
for each function it appears in.)

56 H:\thread\thread.c `JB_SP'' undeclared (first use in this function)
make H:\thread\make *** [thread.o] Error 1

when I compile the same code on Linux it works fine! But I am sure that I
use Cygwin so that should be as good as using Linux.

Hope someone can help

推荐答案

JS< sf **** @ asdas.com>写道:


<很多cde剪切>
JS <sf****@asdas.com> wrote:

<lots of cde snipped>
我得到的错误是:
56 H:\thread \\ \\ _thread.c`JB_BP''未声明(在此函数中首次使用)
(每个未声明的标识符仅针对其出现的每个函数报告一次。)
56 H:\ thread \thread.c`JB_SP''未声明(首次使用此函数)
使H:\thread; \\ make *** [thread.o]错误1
当我编译相同的代码时在Linux上它工作正常!但我相信我会使用Cygwin,这应该和使用Linux一样好。
The error I get is: 56 H:\thread\thread.c `JB_BP'' undeclared (first use in this function)
(Each undeclared identifier is reported only once
for each function it appears in.) 56 H:\thread\thread.c `JB_SP'' undeclared (first use in this function)
make H:\thread\make *** [thread.o] Error 1 when I compile the same code on Linux it works fine! But I am sure that I
use Cygwin so that should be as good as using Linux.




不,它不编译,甚至不编译Linux操作系统。我刚拿了你的代码

并尝试编译它(在Linux下),瞧,


thr.c:55:错误:`JB_BP''未申报(首次使用此功能)

thr.c:55:错误:(每个未声明的标识符仅报告一次

thr.c:55:错误:每个函数它出现在。)

thr.c:55:错误:`JB_SP''未声明(首次使用此函数)

thr.c:27:警告:未使用的参数`attr''

thr.c:在函数`other'':

thr.c:86:警告:未使用的参数`arg''


基本相同的错误信息。所以你必须在你不显示的地方定义''JS_BP''

和''JB_BP''。它在你发布的

代码中没有定义(我不知道它们应该是什么),所以

编译器完全正确地抱怨。 (顺便说一句,没有好的

理由来施放malloc()的返回值,标识符开始

用下划线保留给实现,你的类型 -

def''othread_attr_t'看起来很神秘(一个没有

成员的结构),你的演员阵容看起来很奇怪(int'和

指针可能有不同的大小),而且更多的东西没有任何意义

。这一切应该做什么?


问候,Jens

-

\ Jens Thoms Toerring ___ < a href =mailto:Je *********** @ physik.fu-berlin.de> Je *********** @ physik.fu-berlin.de

\ __________________________ http://www.toerring.de


文章< 3a ************* @ uni-berlin.de>,

< Je *********** @ physik.fu-berlin.de>写道:

:基本相同的错误信息。所以你必须在你不显示的地方定义''JS_BP''

:和''JB_BP''。它没有在

中定义:你发布的代码(我不知道它们应该是什么),


它们似乎在< ; SETJMP.H>至少在某些系统上。


我的标准副本目前是打包的,所以我不能检查

来查看标准是否有关于跳跃缓冲区的内部结构是什么的任何说法。

-

如果你喜欢VT-52,那就太开心了。
In article <3a*************@uni-berlin.de>,
<Je***********@physik.fu-berlin.de> wrote:
:basically the same error message. So you must be defining ''JS_BP''
:and ''JB_BP'' in places you don''t show. It''s nowhere defined in the
:code you posted (and I have no idea what they should be),

They appear to be in <setjmp.h> at least on some systems.

My copy of the standard is packed at the moment, so I can''t check
to see whether the standard has anything to say about what the
interior structure of a jump buffer is.
--
Feep if you love VT-52''s.


2005年3月19日星期六00:18:40 +0000,Jens.Toerring写道:
On Sat, 19 Mar 2005 00:18:40 +0000, Jens.Toerring wrote:
JS< sf****@asdas.com>写道:

<很多cde snipped>
JS <sf****@asdas.com> wrote:

<lots of cde snipped>
我得到的错误是:


56 H:\thread\thread.c`JB_BP''未声明(在此函数中首次使用)
(每个未声明的标识符仅报告一次
对于它出现的每个函数。)
56 H:\thread\thread.c `JB_BP'' undeclared (first use in this function)
(Each undeclared identifier is reported only once
for each function it appears in.)


56 H:\thread \thread.c`JB_SP''未声明(首次使用此功能)
制作H:\thread \ make *** [thread.o]错误1
56 H:\thread\thread.c `JB_SP'' undeclared (first use in this function)
make H:\thread\make *** [thread.o] Error 1


当我在Linux上编译相同的代码时它运行正常!但我确信我会使用Cygwin,这应该和使用Linux一样好。
when I compile the same code on Linux it works fine! But I am sure that I
use Cygwin so that should be as good as using Linux.



不,它不会编译,甚至不能在Linux上编译。我刚拿了你的代码
并尝试编译它(在Linux下),瞧,

thr.c:55:错误:`JB_BP''未声明(首次使用此函数)
thr.c:55:错误:(每个未声明的标识符只报告一次
thr.c:55:错误:对于它出现的每个函数。)
thr.c:55:错误:`JB_SP''未声明(首次使用此函数)
thr.c:27:警告:未使用的参数`attr''
thr.c:在函数`other'':
thr.c:86:警告:未使用的参数`arg''

基本相同的错误信息。所以你必须在你不显示的地方定义''JS_BP''
和'JB_BP'。它在你发布的代码中没有定义(我不知道它们应该是什么),所以
编译器完全正确地抱怨。 (顺便说一句,没有好的理由来推测malloc()的返回值,以下划线开头的标识符是为实现保留的,你的类型 -
def为'' othread_attr_t''看起来很神秘(没有
成员的结构),你的演员看起来很奇怪,至少可以说(int'和
指针可能有不同的大小),以及更多的东西<完全没有意义。这一切应该做什么?

问候,Jens



No, it doesn''t compile, not even on Linux. I just took your code
and tried to compile it (under Linux) and, voila,

thr.c:55: error: `JB_BP'' undeclared (first use in this function)
thr.c:55: error: (Each undeclared identifier is reported only once
thr.c:55: error: for each function it appears in.)
thr.c:55: error: `JB_SP'' undeclared (first use in this function)
thr.c:27: warning: unused parameter `attr''
thr.c: In function `other'':
thr.c:86: warning: unused parameter `arg''

basically the same error message. So you must be defining ''JS_BP''
and ''JB_BP'' in places you don''t show. It''s nowhere defined in the
code you posted (and I have no idea what they should be), so the
compiler is completely right in complaining. (BTW, there''s no good
reason to cast the return value of malloc(), identifiers starting
with an underscore are reserved for the implementation, your type-
def of ''othread_attr_t'' looks mysterious (a structure with no
members), your casts look very strange to say the least (int''s and
pointers may have different sizes), and lots more of things that
make no sense at all). What that''s all supposed to do?

Regards, Jens



它在我的Ubuntu Linux上编译得很好....


Well it compiles fine on my Ubuntu Linux....


这篇关于用Cygwin无法编译!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆