Compile A MSVC++2010 Project So It Can Run On Ubuntu - c++

I have a MSVC++ 2010 project. All the libraries it's using are cross platform (SDL, OpenGL and FLTK).
Obviously, all I have to do right now is press the debug button and it will compile a nice old .exe for me which can now run on Windows, as long as the DLL files are with it.
I had thought before that if you use cross platform libraries, then the generated .exe would run fine on Ubuntu too. I recently found out that this is not possible, and that the program must be compiled in a special way to run on a certain platform.
Is it possible to compile my project in this magical way with MSVC++ 2010 so that it can run on a Ubuntu computer? If so, then could you please answer my question with some clear steps as to what I should do to compile it this way, keeping in mind I'm new to how all this cross platform stuff works?
EDIT:
If I cannot compile a MSVC++ 2010 project for Ubuntu, is there an IDE I could use that could compile the project for both Windows and Ubuntu?
Thanks.

I suggest you use QT. http://qt.digia.com/
It's probably the best cross platform IDE that can let you compile for Windows, Mac and Linux(ubuntu) systems.

Nope, not possible. While the binary code corresponding to the program can be portable, that's not enough. Executable formats on various file systems are different and not compatible. The executable format is essentially a packaging of the binary data and wrapping it with a header that the target file system understands. In order to produce executables for Ubuntu, the linker must support it. MSVC++ doesn't support Linux formats.

Related

Converting a Linux Library Project into a Library Project usable in windows

I am attempting to convert the ndn library project found at "https://github.com/named-data/ndn-cpp" into something that can be imported into several existing mfc/wpf/forms Visual Studio Projects (building it as .lib or .dll would work).
As a note, it appears to have previously been converted into c# for windows for a older build of ndn, but is no long supported and will not connect with the current ndn network.(https://github.com/named-data/ndn-dot-net)
I have looked into the using the WSL features that they have added to windows 10, and the Visual studio Linux Cross Platform projects, but these all seem to only be able to make .exes that will run in windows not a .lib or .dll that can be imported into another project.
I have also look into the shared items project but what I was able to find didn't seem like it would work for what I'm trying to do.
Lastly, I tried using cygwin. I was able to compile and generate the linux style libraries(.a) on my windows 10 machine, but when i attempted to generate windows style dlls off the .o files(gcc -shared -o mydll.dll mydll.o) I ran into a large number of reference errors that I was unable to resolve.
Does anyone have any recommendations on which of these methods I should be using or if I should be attempting some other method entirely?
Does anyone have any good references or examples of how to do this for someone with limited Linux experience?
Thanks
Ok. I've tried going about this several ways now, and here's what I've learned that might be useful to someone else trying to do this and also where I stand so far:
If you have a simple Linux dll that you have written it's possible to compile it as a Windows dll using MSYS2 or MINGW, instructions are here: http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs
If you have something a bit more complicated like the program I'm trying to convert above, there is no quick fix to convert from Linux to windows, however you still might be able to compile your program for windows using Visual Studio.
Here's how you do it:
Download vcpkg from https://github.com/microsoft/vcpkg This is a linux package manager for windows, it will allow you to download windows equivalents to many common Linux packages (for the above I had to download boost and sqlite3)
Create your own unistd.h, here's a link to that: Is there a replacement for unistd.h for Windows (Visual C)?
Get dirent.h for windows, here's a link to that: https://github.com/tronkko/dirent
replace instances of gmtime with _mkgmtime or redefine gmtime as _mkgmtime: timegm cross platform
This got me about 90% of the way there (and from about 13,000 compiler errors to about 30), The rest of the errors so far have been for calls where there is no easy linux to windows conversion and those sections of code have had to be re-written. (In the code above this would be the socket code for the tcp/udp connections in the tranport files, Linux and Windows handle it pretty differently, boost does have a good guide for how to use it's sockets in windows though: https://www.boost.org/doc/libs/1_60_0/more/getting_started/windows.html)
So that's it. Hopefully this helps someone else down the line. I'll be adding more to this answer as I discover new things.

Compiling my C++ exe for Linux with VS2019

I have created a C++ standalone exe with VS2019.
This exe uses 1 external ressource file.
This exe creates WAV files.
It does not use any special libraries.
I have been asked if this application runs under Linux, too.
What would I have to do / check to see if / how I can compile my application for Linux, and would that be possible using VS2019?
Thank you very much for the help.
ps: Here is a screenshot of the properties of my project:
Usually to build C++ applications for Linux, you must first use a compiler that will build for the target OS. In this case VS2019 (and it's associated compiler) builds executables for Windows only.
If you're trying to target Linux, you have two options:
You can move over to a Linux system and build your project with the GNU c++ compiler (I recommend using CMAKE to build your project since it's not tied to any particular IDE and can generate makefiles for gcc). https://cmake.org/cmake-tutorial/
You can install the Windows Subsystem for Linux (WSL) and do a remote build with VS2019. You'll see more and more of this these days in production environments. https://devblogs.microsoft.com/cppblog/linux-development-with-c-in-visual-studio-2019-wsl-asan-for-linux-separation-of-build-and-debug/
Hope this helps!

Create Unix makefile from Visual Studio 2008 Solution

I'm writing a C++ static library using Visual Studio 2008. My static library needs to be loaded by different executables for Windows and Linux (Red Hat)
Now, for the windows build I've got no problems since I'm developing using its environment (as I've already said VS 2008 on Win 8).
My problems occurs when I move the code on Linux.
Sincerely I don't know what is the better solution.
So I'm here asking a few questions looking for the right choice:
Should I compile my executable on Windows using some tools to make a build for linux? Is this even possible? What tool? I tried Cmake but I hadn't found a way.
Should I compile my lib on windows, transfer it on my Linux system and compile in Linux an executable that loads my static library?
Is there a tool that merely converts my vcproj into a makefile? So in windows I only generate the makefile, send it to the Linux System and there compile everything?
The real problem is that I'm not that confident with makefiles, the project is really huge and create my own makefile from scratch is my last possible option and I'd like to avoid it since there's a lot of work to do and it could be time consumming
Thank in advance!
At the end of my journey searching for the right choice I've found the solution that best suits my needs.
What I've done was using Make It So that created makefiles for each project inside my solution, then transferred makefile together with source code, after a little customisation of the makefiles to suit my needs I compiled smoothly my code.
Thanks to those who commented, you helped me in my researches!
Cheers!

Eclipse CDT: From Windows to Linux

I have eclipse installed on windows and use cygwin to develop programs for linux. I compile using the cygwin toolchain and I also do my tests on cygwin.
Now I would like to compile my program also with the native linux toolchain and I also would like to debug it from the windows machine.
Is something possible with Indigo SR2? What is the best way to accomplish this?
I found this but then I would have two projects one for windows and one for linux. I would like to have just one project for both platforms to avoid syncrhonizing the sources back and forth.
Thanks.
I guess you want a cross platform development environment.
There are various tools for the job, but my choice would be CMake. Basically, you will write CMakelists.txt file instead of Eclipse .classpath and .project files, and generate those files with cmake executable. But in details, you will need to overcome some difficulties which are inherent in cross platform development.
I have successfully created more than one project with these tools, and they currently under a heavy load.

How to compile a .cpp file into a Windows executable (.exe) file in Linux

I make this program in C++ using Code::Blocks on Ubuntu. I need to turn it into a Windows executable binary (.exe file), but I don't know how to do this. Is it possible?
If you meant, compiling an executable for Windows on Linux you might find some pointers on how to do that here.
Both the MinGW32 distribution of GCC and Wine should be available for your distribution.
MinGW has instructions and winegcc wraps a similar compiler that comes with the Wine distribution.
I've used both to compile both applications and libraries for Windows.
You could read here on how to compile wxWidget applications on Linux for Windows using Code::Blocks.
This is a fairly unusual question. What you're asking is that you want to develop on Ubuntu, but the target platform is Windows?
My guess is that you have an assignment to turn in. My belief is that you should go to a lab and compile it and make sure it's working.
However, doing some research, you should try mingw at http://www.mingw.org/