Reputation: 2106
I am experiencing some difficulties while creating a simple "Hello world" cross-platform C++ app in Netbeans 8.0.1 for both Linux and Windows operating systems. I found very few instructions for Windows and none for Linux (my OS is Ubuntu 14.04).
My research over the Internet brought me to a conclusion that there should be created one more makefile for Windows OS. Usually, while creating a C++ project Netbeans kindly proposes us to create a makefile for us. And it's great, but it's just for Linux.
I stuck on Makefile creation (never done this before manually), so these were my steps to creating makefile for Windows:
As a result, after making this fresh baked makefile in my GNU-amd64-Windows folder appears an object file (main.o) and an executable file (hello-world), but still executable only in Linux. When I try to run it in Windows command line, I get the error:
"Bad Command or file name"
Just in case here is my main.cpp content:
#include <iostream>
int main( int argc, char** argv )
{
std::cout << "Hello world" << std::endl;
return 0;
}
If I have chosen a wrong way, then how should it be done?
Upvotes: 2
Views: 2020
Reputation: 2106
As mentioned Borgleader, only C++ code can be cross-platform. Here is my solution:
Firstly, we shouldn't use Linux GCC compiler for compiling Windows applications. That's why we need to install Windows compiler for Linux:
sudo apt-get install mingw32 mingw32-binutils mingw32-runtime
Secondly, while creating makefile we should specify alternative compiler. Use:
/usr/bin/i586-mingw32msvc-g++
insteat of default:
g++
Finally, after making this makefile our output file becomes executable on Windows platforms.
Upvotes: 2