I thought I would ask while this thread is active "What is the best Ubuntu c++ compiler that allows VC++ code?" I really like Visual C++ as it has great debugging features that Dev-c++ could never match. But how do I compile my VC++ projects to run on Ubuntu?

use Wine?

use Wine?

But then my compiled result wont be Ubuntu compatible (not directly). In other words I am looking for a Ubuntu compiler that accepts the VC++ code so the compilation result is a Ubuntu application. But as for wine I'm sure not many people would like to use wine to run all my c++ applications.

See post #6 of this thread from the Ubuntu forums:
http://ubuntuforums.org/showthread.php?t=976202

I thought I clearly explained this in my previous post. I want to create Ubuntu programs using the Microsoft c++ library. The standard library that comes with Dev-c++ and Mingw compilers just don't work for me. I only like working with the libraries that come with VC++. However I want my apps to be able to end up in a Ubuntu repository and to run without any emulators. In other words I want a true linux app using c++ and the Microsoft Standard Template Library. Any ideas? Can't make it much clearer.

Member Avatar for iamthwee

This question is non-sense.

Just.

This question is non-sense.

Just.

Could you explain why?

Member Avatar for iamthwee

Post a sample of your vc++ code...

Below is a simple script but I really like using the advanced engines for things like 3d games and they all require the VC++ libraries.

//#include<stdio.h>   
#include<string.h>   
#include<malloc.h>   
#include<math.h>   
#include<stdlib.h>   
#include<iostream>

#define rotateleft(x,n) ((x<<n) | (x>>(32-n)))   
#define rotateright(x,n) ((x>>n) | (x<<(32-n)))   
    
void SHA1(unsigned char * str1)   
{   
	int i;
    unsigned long int h0,h1,h2,h3,h4,a,b,c,d,e,f,k,temp;   
    
    h0 = 0x67452301;   
    h1 = 0xEFCDAB89;   
    h2 = 0x98BADCFE;   
    h3 = 0x10325476;   
    h4 = 0xC3D2E1F0;   
    
    unsigned char * str;   
    str = (unsigned char *)malloc(strlen((const char *)str1)+100);   
    strcpy((char *)str,(const char *)str1);   
    
    int current_length = strlen((const char *)str);   
    int original_length = current_length;   
    str[current_length] = 0x80;   
    str[current_length + 1] = '\0';   
    
    char ic = str[current_length];   
    current_length++;   
    
    int ib = current_length % 64;   
    if(ib<56)   
        ib = 56-ib;   
    else   
        ib = 120 - ib;   
    
    for(i=0;i < ib;i++)   
    {   
        str[current_length]=0x00;   
        current_length++;   
    }   
    str[current_length + 1]='\0';   
    
    for(i=0;i<6;i++)   
    {   
        str[current_length]=0x0;   
        current_length++;   
    }   
    str[current_length] = (original_length * 8) / 0x100 ;   
    current_length++;   
    str[current_length] = (original_length * 8) % 0x100;   
    current_length++;   
    str[current_length+i]='\0';   
    
    int number_of_chunks = current_length/64;   
    unsigned long int word[80];   
    for(i=0;i<number_of_chunks;i++)   
    {   
        for(int j=0;j<16;j++)   
        {   
            word[j] = str[i*64 + j*4 + 0] * 0x1000000 + str[i*64 + j*4 + 1] * 0x10000 + str[i*64 + j*4 + 2] * 0x100 + str[i*64 + j*4 + 3];   
        }   
        for(int j=16;j<80;j++)   
        {   
            word[j] = rotateleft((word[j-3] ^ word[j-8] ^ word[j-14] ^ word[j-16]),1);   
        }   
    
        a = h0;   
        b = h1;   
        c = h2;   
        d = h3;   
        e = h4;   
    
        for(int m=0;m<80;m++)   
        {   
            if(m<=19)   
            {   
                f = (b & c) | ((~b) & d);   
                k = 0x5A827999;   
            }   
            else if(m<=39)   
            {   
                f = b ^ c ^ d;   
                k = 0x6ED9EBA1;   
            }   
            else if(m<=59)   
            {   
                f = (b & c) | (b & d) | (c & d);   
                k = 0x8F1BBCDC;   
            }   
            else   
            {   
                f = b ^ c ^ d;   
                k = 0xCA62C1D6;    
            }   
    
            temp = (rotateleft(a,5) + f + e + k + word[m]) & 0xFFFFFFFF;   
            e = d;   
            d = c;   
            c = rotateleft(b,30);   
            b = a;   
            a = temp;   
    
        }   
    
        h0 = h0 + a;   
        h1 = h1 + b;   
        h2 = h2 + c;   
        h3 = h3 + d;   
        h4 = h4 + e;   
    
    }   
    
	printf("Hash: %x %x %x %x %x",h0, h1, h2, h3, h4);
	std::cout << std::endl << "Hash: " << h0 << " " << h1 << " " << h2 << " " << h3 << " " << h4 << std::endl;
	
}   
//----------------------------------------------
// edit below
//----------------------------------------------
std::string *parts8(std::string originalhash) {
	int arr_pos=0;
	std::string chrset="";
	std::string *parts;
	parts = new std::string[5];
	for (int i=0; i<40; i++) {
		double tmp=(i+1)/8;
		arr_pos=floor(tmp)-1;
		tmp=((i+1.0)/8.0)-1.0;

		std::string str;
		str=originalhash.at(i);
		chrset=chrset.append(str.c_str());
		if (arr_pos==tmp) {
			parts[arr_pos]=chrset;
			chrset="";
			}
		}
	
	return parts;
}
long hex2int(const std::string& hexStr) {
  char *offset;

  if (hexStr.length( ) > 2) {
    if (hexStr[0] == '0' && hexStr[1] == 'x') {
      return strtol(hexStr.c_str( ), &offset, 0);
    }else{
		std::string str="0x";
		str.append(hexStr);
		return strtol(str.c_str( ), &offset, 0);
    }
  }
}
std::string dehash_SHA1 (std::string originalhash) {
	if (originalhash.length()!=40) {
		return "^Error: Invalid hash";
	} else {
		std::string *arr;
		arr=parts8(originalhash);
		
		int *parts;
		parts = new int[5];
	parts[0]=hex2int(arr[0]);
	parts[1]=hex2int(arr[1]);
	parts[2]=hex2int(arr[2]);
	parts[3]=hex2int(arr[3]);
	parts[4]=hex2int(arr[4]);

	std::cout << parts[0] << std::endl;
	std::cout << parts[1] << std::endl;
	std::cout << parts[2] << std::endl;
	std::cout << parts[3] << std::endl;
	std::cout << parts[4] << std::endl;
	return "";
	}
}

void main()   
{   
	std::string tmp;
	coda:
	system("CLS");
    SHA1((unsigned char *)"The quick brown fox jumps over the lazy dog");
	
	//above and below are same hash

	tmp=dehash_SHA1("2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
	std::cout << tmp.c_str() << std::endl;

	system("PAUSE");
	goto coda;
}
Member Avatar for iamthwee

Well, I thought you were using some vc++ dot net bastardised code.

However, your code with a few exceptions, for example, the system calls and god forbid, 'void main' should run OK under g++.

Do a sudo apt-get install g++.

3d stuff will most likely not work. You'll be looking for openGL stuff.
In short the best way to check if something works is to compile it under ubunutu. Dunno if that helped.

Well, I thought you were using some vc++ dot net bastardised code.

However, your code with a few exceptions for example, the system calls and, god forbid, 'void main' should run OK under g++.

Do a sudo apt-get install g++.

3d stuff will most likely not work. You'll be looking for openGL stuff.
In short the best way to check if something works is to compile it under ubunutu. Dunno if that helped.

Names of any compilers that are most compatible with VC++ code so I can search from the repository?

Member Avatar for iamthwee

I'd go for g++.

I managed to find a Ubuntu c++ compiler which supports every variation of c++ and its name is Codelite. But I have one problem. When I compile my above code I get the below error message.

----------Building project:[ Dehasher - Debug ]----------
/bin/sh: cl.exe: not found
make[1]: *** [Debug/main.obj] Error 127
cl.exe /nologo /c  "/home/cwarn23/.codelite/Workspace1/Workspace1/main.cpp" /Zi  /FoDebug/main.obj "/I"C:/Program Files/Microsoft Visual Studio 8/VC/include"" "/I."  
make: *** [All] Error 2
----------Build Ended----------
0 errors, 0 warnings

Does anybody know how to fix the "cl.exe not found" message? I think that is the source of the problem. Thanks.

Basically, none. MFC does not work under linux. Neither does Win32-API specific stuff. If you want that, you HAVE to use WINE.

And if you do so, im pretty sure you must then licence it under the LGPL because it links to non-free libaries?

If you have standards-compliant C++ which doesnt use any MS libaries than of course, it will work fine. In that case, use netbeans/c++ or eclipse IDEs, they are the most visual-studio like (but not offer visual interface editing anywhere near as good as MSVC).

And tip: On ubuntu to install the basic C++ devel (command line) tools, like MAKE and G++, install the metapackage build-essential

commented: spot on. +11

Your IDE is trying to run the compiler contained in Visual Studio. "cl" is how you can invoke the compiler from the command line.

@crarn: IMO your best solution would be to use Code::Blocks/MinGW on both MS-Windows and Ubantu. I like Microsoft compilers a lot too, but it isn't cross-platform to *nix. OpenGL would be the engine you need, not DirectX. It seems to me that you need to be more open minded and use the tools that produce the end-result you want instead of attempting to force the end result to meed the tools that you like.

@crarn: IMO your best solution would be to use Code::Blocks/MinGW on both MS-Windows and Ubantu. I like Microsoft compilers a lot too, but it isn't cross-platform to *nix. OpenGL would be the engine you need, not DirectX. It seems to me that you need to be more open minded and use the tools that produce the end-result you want instead of attempting to force the end result to meed the tools that you like.

I can understand OpenGL having to be used since linux doesn't have directX but I mainly do command line stuff and the Mingw/g++ libraries seem to not behave the same as the Microsoft Libraries. So although I don't mind not using the directx libraries I would still like the same string+math libraries etc.

Those are standard C++ libraries and implementation is nearly identical in all c++ compliant compilers. Unless you can provide us a specific instance where the two implementations are significantly different then your concern is unfounded. If you use Code::Blocks on both os then there will be no difference in how the standard libraries are implemented. I understand that some software houses only use Microsoft compilers, but that has to change when opting for cross-platform programs. And if you don't change then you will probably never get the project off the ground, or sit around waiting for several years until some miracle happens like Microsoft porting Visual Studio to *nix.

I managed to find a Ubuntu c++ compiler which supports every variation of c++ and its name is Codelite.

I guess you mean Codelite IDE

I guess you mean Codelite IDE

Indeed and the Codelite IDE from the Ubuntu repository/synaptic package manager seems to come with the above error when I select MSVC++ Library. I'm starting to suspect that since Codelite IDE is cross platform, that particular feature may not work in Ubuntu. Can anybody confirm this?

I would suggest you contact Author at DL forums. Eran is very cooperative!
I will suggest you stick with AD's suggestion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.