Compiling C++ on MS Windows

R

rays

Hi,
I am trying to port a C++ program which is supposed to be standards
compliant. It works fine on Linux with GCC (4.x). But as I try to
compile it on Windows, all hell breaks loose. I have been struggling
with several free (as beer) compilers on windows, but none of them
does the job. I am not sure how much of the blame goes to our code and
how much to the compilers. By the way the platform is Windows XP and
all the softwares mentioned below are their latest versions.

Here are my experiences:

Visual C++ 2005 Express ( Microsoft C compiler ) :
It does not seem to have sufficient template support. The
particular, the problem is, we have some template overloading. I do
not know if it is a violation of C++ standards to overload template
parameters ( could not find any instance of it in Lippman ), but it
compiles fine with gcc. The functions definitions are like:
bool set( MyData* e, const FieldInfo* f ){...}
bool set( MyData* e, const string& f ){...}
template < class T > bool set( MyData* e, const FieldInfo* f, T v )
{...}
template < class T > bool set( MyData* e, const string& f, T v ){...}
template < class T1, class T2 > bool set(MyData* e, const FieldInfo*
f, T1 v1, T2 v2 ){...}
template < class T1, class T2 > bool set(MyData* e, const string& f,
T1 v1, T2 v2 ){...}

I could work-around this by renaming the overloaded functions but I
would really hate to do so unless I am sure that we are violating
standards here, because boreland C++ and mingw do not have any problem
with these definitions.

Borland C++ Builder (Developer Studio-2006)/ Free command line
tools :
It compiles fine in debug build, though giving a lot of unwanted
warnings for derived classes overloading some virtual function in
baseclass.
"[C++ Warning] DerivedFieldInfo.h(132): W8022
'DerivedFieldInfo::match(const MyData *,unsigned int) const' hides
virtual function 'FieldInfo::match(MyData *,const string &) const'"

But when I try to do a release build the compiler fails without much
information:
"[Linker Fatal Error] Fatal: Illegal SEGMENT fixup index in module
'E:\myproject\basecode\SharedFieldInfo.cpp'"
I have no idea how to resolve this error.

MingW - 5.1.3 (mingw-runtime 3.12):
Compiles fine both with and without -g in CFLAGS.

Now, although borland and mingw can compile and link it, the
executable seems to have some problem. There are some assertions for
testing that fails in the same place for executable generated by both
compilers. In mingw it just says assertion failed, with line number
etc. and borland pops up a message window saying:
"Project myproject.exe raised an exception class EAccessVioltion with
message 'AccessViolation'".

It may be some problem with static initializations that I have to look
at. But right now it will be nice if somebody could cast some light on
what is the most standard compliant and full featured C++ compiler for
windows. So I could embark on the wild-goose-chase with the most
reliable tool ( which itself does not camouflage as the wild goose).
Please note that I am not bothered about compilation speed or
executable size at this point. I just want to make sure the problem
lies with the code or with the build process / windows platform itself
( without getting into too much of a flame war).
I would appreciate any feedback from the community.

Thanks in advance,
Ray S.
 
V

Victor Bazarov

rays said:
I am trying to port a C++ program which is supposed to be standards
compliant. It works fine on Linux with GCC (4.x). But as I try to
compile it on Windows, all hell breaks loose. [..]

FAQ 5.8.
It may be some problem with static initializations that I have to look
at. But right now it will be nice if somebody could cast some light on
what is the most standard compliant and full featured C++ compiler for
windows. [..]

Comeau C++ is good. Microsoft Visual C++ Express is close, but check
out their "Code Name Orcas", it's not in alpha, IIRC.

If you think your problem is specific to MS Windows (I don't know, and
I don't think so, but still...) try posting to a Windows newsgroup.
Who knows, maybe somebody there knows more?

V
 
A

ajk

Hi,
I am trying to port a C++ program which is supposed to be standards
compliant. It works fine on Linux with GCC (4.x). But as I try to
compile it on Windows, all hell breaks loose. I have been struggling
with several free (as beer) compilers on windows, but none of them
does the job. I am not sure how much of the blame goes to our code and
how much to the compilers. By the way the platform is Windows XP and
all the softwares mentioned below are their latest versions.
gcc for windows would be a good bet :)
 
Z

Zeppe

rays said:
Here are my experiences:

Visual C++ 2005 Express ( Microsoft C compiler ) :
It does not seem to have sufficient template support.

That's funny, my experience is that visual studio 2005 is much more
compliant than gcc 4.

And another experience is that I tried this code:

#include <iostream>
#include <string>

using namespace std;

typedef int MyData;
typedef char FieldInfo;


bool set( MyData* e, const FieldInfo* f )
{
std::cout << "version 1\n";
return false;
}


bool set( MyData* e, const string& f )
{
std::cout << "version 2\n";
return false;
}


template < class T > bool set( MyData* e, const FieldInfo* f, T v )
{
std::cout << "version 3\n";
return false;
}


template < class T > bool set( MyData* e, const string& f, T v )
{
std::cout << "version 4\n";
return false;
}


template < class T1, class T2 > bool set(MyData* e, const FieldInfo* f,
T1 v1, T2 v2 )
{
std::cout << "version 5\n";
return false;
}


template < class T1, class T2 > bool set(MyData* e, const string& f, T1
v1, T2 v2 )
{
std::cout << "version 6\n";
return false;
}



int main()
{
int a = 0;
char b = 0;
std::string c;
double dummyType1 = 0;
bool dummyType2 = false;
set(&a,&b);
set(&a, c);
set(&a, &b, dummyType1);
set(&a, c, dummyType1);

set(&a, &b, dummyType1, dummyType2);
set(&a, c, dummyType1, dummyType2);

std::cout << "hello world!\n";
return 0;
}




the produced result is:

version 1
version 2
version 3
version 4
version 5
version 6

as expected.

Try to post a minimal example that is not compiled in visual studio
2005, and we'll try to sort it out.

But don't do like those people that are really convinced about
something, and when they check in the encyclopaedia and they find out
that it doesn't agree with them, they conclude that the encyclopaedia
must be wrong! ;)

Regards,

Zeppe
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Hi,
I am trying to port a C++ program which is supposed to be standards
compliant. It works fine on Linux with GCC (4.x). But as I try to
compile it on Windows, all hell breaks loose. I have been struggling
with several free (as beer) compilers on windows, but none of them
does the job. I am not sure how much of the blame goes to our code and
how much to the compilers. By the way the platform is Windows XP and
all the softwares mentioned below are their latest versions.

Here are my experiences:

Visual C++ 2005 Express ( Microsoft C compiler ) :
It does not seem to have sufficient template support. The
particular, the problem is, we have some template overloading. I do
not know if it is a violation of C++ standards to overload template
parameters ( could not find any instance of it in Lippman ), but it
compiles fine with gcc. The functions definitions are like:
bool set( MyData* e, const FieldInfo* f ){...}
bool set( MyData* e, const string& f ){...}
template < class T > bool set( MyData* e, const FieldInfo* f, T v )
{...}
template < class T > bool set( MyData* e, const string& f, T v ){...}
template < class T1, class T2 > bool set(MyData* e, const FieldInfo*
f, T1 v1, T2 v2 ){...}
template < class T1, class T2 > bool set(MyData* e, const string& f,
T1 v1, T2 v2 ){...}

I could work-around this by renaming the overloaded functions but I
would really hate to do so unless I am sure that we are violating
standards here, because boreland C++ and mingw do not have any problem
with these definitions.

Borland C++ Builder (Developer Studio-2006)/ Free command line
tools :
It compiles fine in debug build, though giving a lot of unwanted
warnings for derived classes overloading some virtual function in
baseclass.
"[C++ Warning] DerivedFieldInfo.h(132): W8022
'DerivedFieldInfo::match(const MyData *,unsigned int) const' hides
virtual function 'FieldInfo::match(MyData *,const string &) const'"

But when I try to do a release build the compiler fails without much
information:
"[Linker Fatal Error] Fatal: Illegal SEGMENT fixup index in module
'E:\myproject\basecode\SharedFieldInfo.cpp'"
I have no idea how to resolve this error.

MingW - 5.1.3 (mingw-runtime 3.12):
Compiles fine both with and without -g in CFLAGS.

Now, although borland and mingw can compile and link it, the
executable seems to have some problem. There are some assertions for
testing that fails in the same place for executable generated by both
compilers. In mingw it just says assertion failed, with line number
etc. and borland pops up a message window saying:
"Project myproject.exe raised an exception class EAccessVioltion with
message 'AccessViolation'".

It may be some problem with static initializations that I have to look
at. But right now it will be nice if somebody could cast some light on
what is the most standard compliant and full featured C++ compiler for
windows. So I could embark on the wild-goose-chase with the most
reliable tool ( which itself does not camouflage as the wild goose).
Please note that I am not bothered about compilation speed or
executable size at this point. I just want to make sure the problem
lies with the code or with the build process / windows platform itself
( without getting into too much of a flame war).
I would appreciate any feedback from the community.

As Zeppe pointed out, try to localize the code that does not compile as
much as possible and then post it here and someone might tell you if
it's the code of not. Another thing to check is you use any compiler-
specific extensions when compiling it on Linux.
 
W

Walter Bright

rays said:
I am trying to port a C++ program which is supposed to be standards
compliant. It works fine on Linux with GCC (4.x). But as I try to
compile it on Windows, all hell breaks loose. I have been struggling
with several free (as beer) compilers on windows, but none of them
does the job.

Try the Digital Mars C++ compiler for Windows.
 
R

rays

Thank you all, Victor, ajk, Lionel, Zeppe, Erik and Walter for your
prompt and helpful response . I have partially got around the VC++
problem, as it turned out that it needed inlining for template
specializations somewhere else in the code.Now all three are in the
same rank with the same assertion failing in the executable. I guess
it something goes wrong with windows executable layout that is
generated, may be the code has some bug that is not visible in linux
or may be I am missing something in the build setting. I shall
peacefully set on debugging now.
And by the way, I was trying to use make file for building, instead
of using the IDE, which made life more frustrating and perhaps
generated some unkind comments from my part. I should retract it. The
Visual Studio Express GUI is amazing and it works quite automagically
- making me feel a bit stupid.

Thanks and regards,
Ray S.
 
L

Lynn McGuire

I am trying to port a C++ program which is supposed to be standards
compliant. It works fine on Linux with GCC (4.x). But as I try to
compile it on Windows, all hell breaks loose. I have been struggling
with several free (as beer) compilers on windows, but none of them
does the job. I am not sure how much of the blame goes to our code and
how much to the compilers. By the way the platform is Windows XP and
all the softwares mentioned below are their latest versions.

Did you try the free open source compiler, Open Watcom C++,
at http://www.openwatcom.org/ ?

You may have template problems there also as template partial
specialization is still being worked on. Version 1.7 in a month
or so will improve this.

Lynn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top