I am writing a c++ program specifically for Windows operating system. However, I am writing it on a Mac OS. I know it seems counter productive, but I have my reasons that would take the next paragraph to explain. What I want is to be able to compile it on my Mac, and turn it into a .exe file, but I won't be running it on a Mac. I'll be running it on a Windows machine. The header that I want to use, but I obviously have problems with is windows.h. Using the standard g++ on a Mac I am unable to do this.
However, winegcc using wineg++ is able to do this. I have seen that you are able to install these on a Linux machine. I want to know if it is possible to do on a Mac as well.
This will allow you to import windows.h on a Mac OS, you just won't be able to run it on a Mac OS
The comment that said to install MinGW worked great. I just ran brew install mingw-w64 in terminal, then this example command worked on a mac and compiled a windows executable file:
i686-w64-mingw32-g++ shell.cpp -o shellv1.exe -lws2_32 -s -ffunction-sections -fdata-sections -Wno-write-strings -fno-exceptions -fmerge-all-constants -static-libstdc++ -static-libgcc
Related
Im trying to cross compile a c++ application to windows from linux. I want to be able to use the normal g++ compiler as I have always used.
I tried looking online for help on this issue and found only mingw or clang stuff or stuff with a long complex setup.
Is there like a one line command I can use like g++ -windows to get it to build a windows executable right there. My code doesnt use any windows libaries so should compile just fine.
Thanks for the help.
Is really not that hard. The only thing you need to do is install g++-mingw-w64 with:
sudo apt install g++-mingw-w64 -y
After that, the only thing you need to do is compile with:
x86_64-w64-mingw32-g++ hello.c -o hello.exe
That is going to give you a 64-bit executable for windows that just runs. That's how I do it and I haven't had any problems.
If you want a 32-bit executable just do:
i686-w64-mingw32-g++ hello.c -o hello.exe
I am trying to deliver a Windows DLL (as well as a .so) from a Linux box using Mingw.
I am following this example, which consists of three files, the DLL source example_dll.cpp, header example_dll.h, and a client application example_exe.cpp. These I have located in a folder shared by my Linux host and Windows 7 VM. Both boxes have Mingw installed.
The build commands for the DLL are
g++ -c -DBUILDING_EXAMPLE_DLL example_dll.cpp
g++ -shared -o example_dll.dll example_dll.o -Wl,--out-implib,libexample_dll.a
and for the client app
g++ -c example_exe.cpp
g++ -o example_exe.exe example_exe.o -L. -lexample_dll
All compiles and runs perfectly on a Windows 7 VM with Mingw installed.
All compiles perfectly under Ubuntu 16.04 with Mingw installed, replacing g++ with i686-w64-mingw32-g++.
But in this case, when the executable is run from the Windows VM, "The program can't start because libgcc_s_sjlj-1.dll is missing.
What mistake am I making?
I can force the "missing" DLLs into the executable, by replacing 4. with i686-w64-mingw32-g++ -o example_exe.exe example_exe.o -L. -lexample_dll -static-libgcc -static-libstdc++ on Linux, and that works perfectly on the Windows VM.
But I need to deliver a DLL, not an executable.
I have noticed that the DLL libgcc_s_sjlj-1.dll exists on the Linux box but not the Windows box.
I have also noticed that the Linux box has Mingw 5.3.1 while the Windows box has Mingw 6.3.0
I want to install xgboost using anaconda python. In this process, I am trying to install xgboost. While trying to "make" the xgboost i am getting the below error:
C:\GitRepository\xgboost>
g++ -m64 -c -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -fopenmp -fPIC
-o updater.o src/tree/updater.cpp
src/tree/updater.cpp:1:0: warning: -fPIC ignored for target (all code is positio
n independent)
// Copyright 2014 by Contributors
^
src/tree/updater.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in
make: *** [updater.o] Error 1
I understood from the other Stack overflow posts that 32 bit gcc cannot go with the 64bit anaconda that i am using. However when i installed mingw-w64 i could see that it has g++ only for mingw32 and not for mingw-w64. Under the mingw-w64 package, g++ and other applications+folders are present only for mingw32 and not for 64. For mingw-64 only a batch file and a internet short cut is present.
Could you please guide me what is going wrong or guide me to an appropriate place from where i can download for mingw-64.
Thanks in advance.
If you are really using MSYS2, then you should not be downloading separate compilers. You should install 64-bit g++ using MSYS2's package manager, by running pacman -S mingw-w64-x86_64-toolchain. Then make sure that you start the MSYS2 shell using the shortcut that is named something like "MSYS2 Win64 Shell" in your start menu. Type which g++ in Bash and make sure it outputs /mingw64/bin/g++. Then you should be able to compile code for 64-bit Windows.
I'm not sure that this answer is complete. If you need more help with MSYS2, it would be good to post the exact commands you are running to download/extract the source code and build so that others can reproduce the error.
I have recently installed GCC 4.9.2 (port name gcc49) through MacPorts. I am quite happy with its new features such as colorized diagnostics and C++1y/C++14 support improvements, etc.
However, since I started to compile code using GCC 4.9.2, I realized that it is not generating debug symbol directory *.dSYM and gdb says "no debugging symbols found" when I try to debug a program I compiled with -g flag.
Is this a MacPorts specific bug or is there a problem with GCC 4.9?
Thanks
It is not a MacPorts specific issue. MacPorts doesn't really do much to customize the gcc ports.
If you want to create a dSYM bundle and strip your executable, you should just do something like:
gcc-mp-4.9 -g3 -c example.c
gcc-mp-4.9 example.o -o example
dsymutil --out example.dSYM example
strip -S -x example
As a side note, if you want C++11/C++14 support, I suggest you use the clang-3.5 port as that will allow you to use libc++ from the system instead of libstdc++ from MacPorts (and allow you to use system and MacPorts C++ libraries rather than just the STL). Also, lldb is really the preferred debugger for OS X these days.
When building C++ projects using make on OSX 10.6, I have determined that the preprocessor definition __LP64__ seems to be always automatically set by the compiler (i.e., it is not defined in any header file) (see Where is __LP64__ defined for default builds of C++ applications on OSX 10.6?). This leads to the question: Is it even possible to build a 32-bit application on OSX 10.6 that targets (and runs) on another OSX 10.6 system?
I have heard that OSX 10.6 is always a 64-bit OS - that it's not even possible to run OSX 10.6 as a 32-bit operating system. If this is the case, it would make sense that it is impossible to build a 32-bit application on OSX 10.6 that will run on another OSX 10.6 system.
I need to know this so I can know whether I'm building a 64-bit application or not (I have been attempting to build my current project as a 32-bit application, since the corresponding Windows version is also being built as 32-bit - but perhaps I need to enable all 64-bit flags and build the OSX 10.6 version of this application as a full-fledged 64-bit application).
Yes, it is perfectly possible to do that. One limited demonstration:
$ tar -xf Packages/range-1.14.tgz
$ cd range-1.14
$ ls
COPYING Makefile README gpl-3.0.txt range.c range.mk stderr.c stderr.h
$ rmk CC='gcc -m32'
gcc -m32 -g -c stderr.c
gcc -m32 -g -c range.c
gcc -m32 -o range -g stderr.o range.o
$ file range
range: Mach-O executable i386
$ rmk -u CC='gcc -m64'
gcc -m64 -g -c stderr.c
gcc -m64 -g -c range.c
gcc -m64 -o range -g stderr.o range.o
$ file range
range: Mach-O 64-bit executable x86_64
$
rmk -u is equivalent to (GNU) make -B. This GCC is my home-built 4.6.0. You can do more with the Apple-provided versions of GCC - like cross-compiling and/or universal builds.
Mac OS X 10.6 runs perfectly well on 32-bit Intel Macs. It dropped support for PowerPC. Future versions of Mac OS X (cough cough NDA cough) may or may not drop support for 32-bit Intel Macs, requiring a 64-bit system.
Even a 64-bit Mac, however, has implicit support for running 32-bit processes, and GCC can cross-compile for i386 targets (or PPC/PPC64/ARMv6/ARMv7 targets.) You must make sure the desired architectures are specified in your build flags however, or it will default to the native architecture (i.e. x86_64.)
If you use the xcodebuild command-line utility and pass it the path to an Xcode project bundle, it will automatically use the build settings in the project when calling on GCC. There's rarely a need to use GCC directly on Mac OS X unless you're compiling from generic *NIX sources.
If you tell us why you're using make on Mac OS X, we may be able to give you more specific advice, but the preferred command-line compilation method on Mac OS X is still xcodebuild.