从Windows移植到Linux [英] Porting from Windows to Linux
问题描述
我一直用VC ++ 6.0开发一些库。我的工作现在已经完成了,并且代码工作得很好。它已在许多情况下在
下进行了测试,我没有遇到任何问题。现在,我想将b $ b移植到gcc。最初用gcc编译它产生了一些错误,在VC ++不会打扰的地方要求一些''const''声明。
。但是,我能够编译它并且
创建一个可执行文件。问题是当我运行
时可执行文件崩溃了。
我用cygwin最新版本和g ++在suse 8.1中尝试过。当我用
尝试使用DDD调试它时,程序会在我返回引用时停止。我检查了可能的内存问题,例如
返回本地变量的引用或者分配地址
分配的内存。但是没有这样的。
例如,我的程序暂停的地方是:
vector< unsigned>& GF :: primitive()
{
返回ir;
}
其中'' ir''是GF类的受保护数据成员,如图所示。
class GF {
....
受保护:
vector< unsigned> ir;
};
如果我试图单步返回,它会进入矢量类,我会失去
。
我不知道为什么会这样。有人可以对此表示敬意。
问候,
Prasanna。
< blockquote> Prasanna写道:
我一直在使用VC ++ 6.0开发一些库。我的工作现在已经完成,代码工作得很好。它已经在很多情况下进行了测试,我没有遇到任何问题。现在,我想将它移植到gcc。最初使用gcc编译它会产生一些错误,在VC ++不会打扰的地方要求一些''const''声明。但后来,我能够编译它并创建一个可执行文件。问题是当我运行
时可执行文件崩溃。
我用cygwin最新版本和g ++在suse 8.1中尝试过。当我试图使用DDD调试它时,程序会在我返回引用时停止。我检查了可能的内存问题,例如
返回本地变量的引用或者分配已分配内存的地址。但是没有这样的。
例如,我的程序暂停的地方是:
vector< unsigned>& GF :: primitive()
{
返回ir;
}
其中''ir''是GF类的受保护数据成员,如图所示。<类GF <
...
受保护:
向量< unsigned> ir;
};
调试器应该告诉你更多,比如参数(包括
''this''指针)。也许在调用原语时,''this''是一个空的
指针。
Prasanna写道:
我一直在使用VC ++ 6.0开发一些库。我的工作现在已经完成,代码工作得很好。它已经在很多情况下进行了测试,我没有遇到任何问题。现在,我想将它移植到gcc。最初使用gcc编译它会产生一些错误,在VC ++不会打扰的地方要求一些''const''声明。但后来,我能够编译它并创建一个可执行文件。问题是当我运行
时可执行文件崩溃。
我用cygwin最新版本和g ++在suse 8.1中尝试过。当我试图使用DDD调试它时,程序会在我返回引用时停止。我检查了可能的内存问题,例如
返回本地变量的引用或者分配已分配内存的地址。但是没有这样的。
例如,我的程序暂停的地方是:
vector< unsigned>& GF :: primitive()
{
返回ir;
}
其中''ir''是GF类的受保护数据成员,如图所示。<类GF <
....
受保护:
向量< unsigned> ir;
};
如果我尝试单步返回,它会进入矢量类,我会丢失。
我不知道为什么会这样。有人可以对此表示敬意。
问候,
Prasanna。
以下代码是否会崩溃?
#include< vector>
int main()
{
使用std :: vector;
班级考试
{
受保护:
vector< unsigned> ir;
>
public:
vector< unsigned>& primitive(){return ir; }
};
测试a;
vector< unsigned> & rir = a.primitive();
}
问候,
Ioannis Vranos
我找到了问题所在。问题是:
类GF {
public:
GF(){};
GF(向量< unsigned>);
GF(向量< unsigned> ;,无符号);
GF(GF&);
GF& operator =(vector< unsigned>&);
GF& operator =(GF&);
vector< unsigned> primitive();
vector< unsigned> element();
受保护:
vector< unsigned> ir;
vector< unsigned> el;
};
我在这样的代码段中使用上面的类:
/ /////////////
.....
vector< GF> f;
GF本地;
f.push_back(本地); //只是为了证明问题
unsigned m = f.size();
for(int i = 0; i< m ; i ++)
f [i] = GF(local.primitive(),i).element(); //< - 这就是它的地方
崩溃
......
///////// /////
我想要上面这行做的是创建一个GF对象并使用operator =将其
元素分配给f [i] 。 VC ++只是这样做的。但是gcc
执行以下操作。它创建一个GF对象,并使用GF :: element()返回的元素
来创建另一个GF对象,使用
GF :: GF(向量< unsigned>)构造函数,然后使用GF :: operator =(GF&)
将其分配给f [i]。
可能这是一个形成不良的情况。但是gcc和vc ++都没有发布任何关于它的警告。你能给我一些好的解决方案,因为我也想要这个GF :: GF(向量< unsigned>)。这使得使用班级
变得相当容易。
问候,
Prasanna。
Ioannis Vranos< iv*@guesswh.at.grad.com>在消息新闻中写道:< ca *********** @ ulysses.noc.ntua.gr> ...Prasanna写道:
我一直在使用VC ++ 6.0开发一些库。我的工作现在已经完成,代码工作得很好。它已经在很多情况下进行了测试,我没有遇到任何问题。现在,我想将它移植到gcc。最初使用gcc编译它会产生一些错误,在VC ++不会打扰的地方要求一些''const''声明。但后来,我能够编译它并创建一个可执行文件。问题是当我运行
时可执行文件崩溃。
我用cygwin最新版本和g ++在suse 8.1中尝试过。当我试图使用DDD调试它时,程序会在我返回引用时停止。我检查了可能的内存问题,例如
返回本地变量的引用或者分配已分配内存的地址。但是没有这样的。
例如,我的程序暂停的地方是:
vector< unsigned>& GF :: primitive()
{
返回ir;
}
其中''ir''是GF类的受保护数据成员,如图所示。<类GF <
....
受保护:
向量< unsigned> ir;
};
如果我尝试单步返回,它会进入矢量类,我会丢失。
我不知道为什么会这样。有人可以帮我这个。
问候,
Prasanna。
以下代码是否会崩溃?
#include< vector>
int main()
{
使用std :: vector;
类测试
{<受保护的:
向量< unsigned> ir;
公众:
向量< unsigned>& primitive(){return ir; }
};
测试a;
向量< unsigned> & rir = a.primitive();
}
问候,
Ioannis Vranos
Hi,
I have been developing some libraries using VC++ 6.0. My work is
complete now and the code works just fine. It has been tested under
many circumstances and i have not encountered any problems. Now, I
would like to port it to gcc. Initially compiling it with gcc produced
a few errors, asking for some ''const'' declarations in places where
VC++ would not bother to. But then, i was able to compile it and
create an executable. The problem is the executable crashes when i run
it.
I tried it with cygwin latest version and g++ in suse 8.1. When i
tried to debug it with DDD in suse, the program halts when i am
returning a reference. I checked for possible memory problems, like
returning a reference for a local variable or chaning the address of
an allocated memory. But there are none like that.
For example, the place where my program halts is this:
vector<unsigned>& GF::primitive()
{
return ir;
}
where ''ir'' is a protected data member of class GF, as shown.
class GF{
....
protected:
vector<unsigned> ir;
};
If i try to step through return, it goes inside vector class and i get
lost.
I have no idea why this happens. Can someone elighten me on this.
Regards,
Prasanna.
Prasanna wrote:
Hi,
I have been developing some libraries using VC++ 6.0. My work is
complete now and the code works just fine. It has been tested under
many circumstances and i have not encountered any problems. Now, I
would like to port it to gcc. Initially compiling it with gcc produced
a few errors, asking for some ''const'' declarations in places where
VC++ would not bother to. But then, i was able to compile it and
create an executable. The problem is the executable crashes when i run
it.
I tried it with cygwin latest version and g++ in suse 8.1. When i
tried to debug it with DDD in suse, the program halts when i am
returning a reference. I checked for possible memory problems, like
returning a reference for a local variable or chaning the address of
an allocated memory. But there are none like that.
For example, the place where my program halts is this:
vector<unsigned>& GF::primitive()
{
return ir;
}
where ''ir'' is a protected data member of class GF, as shown.
class GF{
...
protected:
vector<unsigned> ir;
};
The debugger should tell you more, like the parameters (including the
''this'' pointer). Maybe on the call to primitive, ''this'' was a null
pointer.
Prasanna wrote:Hi,
I have been developing some libraries using VC++ 6.0. My work is
complete now and the code works just fine. It has been tested under
many circumstances and i have not encountered any problems. Now, I
would like to port it to gcc. Initially compiling it with gcc produced
a few errors, asking for some ''const'' declarations in places where
VC++ would not bother to. But then, i was able to compile it and
create an executable. The problem is the executable crashes when i run
it.
I tried it with cygwin latest version and g++ in suse 8.1. When i
tried to debug it with DDD in suse, the program halts when i am
returning a reference. I checked for possible memory problems, like
returning a reference for a local variable or chaning the address of
an allocated memory. But there are none like that.
For example, the place where my program halts is this:
vector<unsigned>& GF::primitive()
{
return ir;
}
where ''ir'' is a protected data member of class GF, as shown.
class GF{
....
protected:
vector<unsigned> ir;
};
If i try to step through return, it goes inside vector class and i get
lost.
I have no idea why this happens. Can someone elighten me on this.
Regards,
Prasanna.
Does the following code crash to you?
#include <vector>
int main()
{
using std::vector;
class test
{
protected:
vector<unsigned>ir;
public:
vector<unsigned>& primitive() { return ir; }
};
test a;
vector<unsigned> &rir=a.primitive();
}
Regards,
Ioannis Vranos
I was able to locate the problem. The problem is:
class GF{
public:
GF(){};
GF(vector<unsigned>);
GF(vector<unsigned>, unsigned);
GF(GF&);
GF& operator=(vector<unsigned>&);
GF& operator=(GF&);
vector<unsigned> primitive();
vector<unsigned> element();
protected:
vector<unsigned> ir;
vector<unsigned> el;
};
I am using the above class in a code segment like this:
//////////////
.....
vector<GF> f;
GF local;
f.push_back(local); // just to demonstrate the problem
unsigned m = f.size();
for(int i=0;i<m;i++)
f[i] = GF(local.primitive(),i).element(); //<-- this is where it
crashes
......
//////////////
What i want the above line to do is create a GF object and assign its
element to f[i] using operator =. VC++ is doing only that. But gcc
does the following. It creates a GF object and uses its element
returned by GF::element() to create another GF object using the
GF::GF(vector<unsigned>) constructor and then uses GF::operator=(GF&)
to assign it to f[i].
May be this is a ill formed situation. But neither gcc nor vc++ issues
any warnings about it. Can u suggest me some good solution, coz i also
want this GF::GF(vector<unsigned>). That makes usage of the class
quite easier.
Regards,
Prasanna.
Ioannis Vranos <iv*@guesswh.at.grad.com> wrote in message news:<ca***********@ulysses.noc.ntua.gr>...Prasanna wrote:Hi,
I have been developing some libraries using VC++ 6.0. My work is
complete now and the code works just fine. It has been tested under
many circumstances and i have not encountered any problems. Now, I
would like to port it to gcc. Initially compiling it with gcc produced
a few errors, asking for some ''const'' declarations in places where
VC++ would not bother to. But then, i was able to compile it and
create an executable. The problem is the executable crashes when i run
it.
I tried it with cygwin latest version and g++ in suse 8.1. When i
tried to debug it with DDD in suse, the program halts when i am
returning a reference. I checked for possible memory problems, like
returning a reference for a local variable or chaning the address of
an allocated memory. But there are none like that.
For example, the place where my program halts is this:
vector<unsigned>& GF::primitive()
{
return ir;
}
where ''ir'' is a protected data member of class GF, as shown.
class GF{
....
protected:
vector<unsigned> ir;
};
If i try to step through return, it goes inside vector class and i get
lost.
I have no idea why this happens. Can someone elighten me on this.
Regards,
Prasanna.
Does the following code crash to you?
#include <vector>
int main()
{
using std::vector;
class test
{
protected:
vector<unsigned>ir;
public:
vector<unsigned>& primitive() { return ir; }
};
test a;
vector<unsigned> &rir=a.primitive();
}
Regards,
Ioannis Vranos
这篇关于从Windows移植到Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!