Compile OpenGL with GCC 64-bit - c++

I have a project that compiles with GCC 32-bit. I have been trying to migrate to GCC 64-bit on my native Windows machine (not through a VM). To do this I have downloaded w64devkit from https://github.com/skeeto/w64devkit/releases. My 32-bit install comes from https://sourceforge.net/projects/mingw/.
NOTE: Both installs cannot be active at the same time. Since the 32-bit version makes it into the path before we can add the 64-bit version through the environment variables, I modify the 32-bit MinGW folder name so that when the 64-bit version of GCC tries to use as.exe and ld.exe through the path, it will find the correct versions.
I have also downloaded glm, glew, and glfw for this project, and added folders to the path to get at least the 32-bit version working.
The working command line to compile the 32-bit version is as follows:
g++ -std=c++11 -O3 -ggdb src/main.cpp -o build/main -lopengl32 -L. -I"C:\lib\glm" -I"C:\lib\glew-2.1.0-win32\include" -I"C:\lib\glfw-3.3.8.bin.WIN32\include" "C:\lib\glfw-3.3.8.bin.WIN32\lib\libglfw3dll.a" "C:\lib\glew-2.1.0-win32\lib\Release\Win32\glew32.lib"
The following command line to compile the 64-bit version also works:
g++ -std=c++11 -O0 -ggdb src/main.cpp -o build/main -lopengl32 -L. -I"C:\lib\glm" -I"C:\lib\glew-2.1.0-win32\include" -I"C:\lib\glfw-3.3.8.bin.WIN64\include" "C:\lib\glfw-3.3.8.bin.WIN64\lib-mingw-w64\libglfw3dll.a" "C:\lib\glew-2.1.0-win32\lib\Release\x64\glew32.lib"
However whenever I try to run the executables, the 32-bit version runs and the 64-bit version gives me an error in a pop-up window. "The application was unable to start correctly (0xc000007b). Click OK to close the application."
When I try to run it in one of my debuggers I get a "Error: 32-bit processes are not supported". Another debugger says "During startup program exited with code 0xc000007b".
Clearly something is going horribly wrong, but I don't know what or where.

Related

g++ cross compile to windows from linux

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

Compiling 32-bit code with 64-bit MinGW GCC [duplicate]

I've downloaded MinGW from this link x64-4.8.1-posix-sjlj-rev1 but when I try to build for x86 target I've lots of linkage errors... seems that only x64 lib are installed...
I've need to build for x86 and x64 platforms on windows... Have I to download both x64 and x86 or are some simpler ways?
Edit I'm using eclipse keplero as IDE
I've tryed to build myself a simple hello world program with g++ -m32 -std=c++11 test.cpp -o test32.exe and g++ -m64 -std=c++11 test.cpp -o test64.exe. And all is ok... So the problem was with eclipse... After a little a discovered that I need to use MYSY ( set in PATH ) and set -m32 also in the c++ linkage options...
Now all is fine.
I've also tryed to use NetBeans C++ as IDE... seems a gread IDE!!!
It is not multilib enabled. That's why you are not able to compile 32-bit(x86) program. You can get multilib enabled toolchain from following link:
For 64-bit machine: 64-Bit
For 32-bit machine: 32-Bit

Cross-compiling a Windows DLL on Linux using Mingw

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

Install xgboost under python with 64-bit msys failing

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.

Getting a Botan library test program to compile under Windows 7 (MinGW, Code::Blocks)

I have been trying in vain to get this test program to compile
#include <botan/botan.h>
int main()
{
Botan::LibraryInitializer init;
}
I have downloaded library source from the website. I ran configure.py, which ran fine.
I then attempted to run MinGW-make
This is the error I got
c:\Botan-1.11.7>mingw32-make
g++ -m64 -pthread -fPIC -fvisibility=hidden -std=c++11 -D_REENTRANT -fstack-pro
tector -O3 -momit-leaf-frame-pointer -Wall -Wextra -Wstrict-aliasing -Wstrict-ov
erflow=5 -Wcast-align -Wmissing-declarations -Wpointer-arith -Wcast-qual -Wold-s
tyle-cast -Wzero-as-null-pointer-constant -Ibuild\include -c C:\Botan-1.11.7\src
\lib\algo_base\scan_name.cpp -o build\obj\lib\src_lib_algo_base_scan_name.obj
C:\Botan-1.11.7\src\lib\algo_base\scan_name.cpp:1:0: warning: -fPIC ignored for
target (all code is position independent) [enabled by default]
C:\Botan-1.11.7\src\lib\algo_base\scan_name.cpp:1:0: sorry, unimplemented: 64-bi
t mode not compiled in
mingw32-make: *** [build\obj\lib\src_lib_algo_base_scan_name.obj] Error 1
I searched Google and any available forum I could find. I found prebuilt libraries for windows in a hidden folder on their site. However the package contained lib and dll files and not .a files which MinGW requires. I tries to use a program LIB2A which created a .a file. I have added this file into my code::blocks linker options. I also included the include folder.
When I try to compile I get this error.
C:\botan\include\botan\init.h|41|undefined reference to `_imp___ZN5Botan18LibraryInitializer10initializeERKSs'|
It seems like it cannot see the library with function definitions, but I am lost on where to go from here.
mingw32-make has the -m64 flag set, which means it's trying to build a 64 bit library. To build a 64 bit library, you'll need to get MinGW-w64.
When you ran configure.py, it likely set up your MakeFile to build a 64 bit library. You'll want to check what options are set in its output. This includes the option to build 32 bit or 64 bit. Either way, you'll want some variant of this: python configure.py --os=mingw --cc=gcc
This question had a similar error, and suggested using MinGW-w64, which will allow you to build a 64 bit library: Building 64 bit dll with MinGW 32 bit in Eclipse
In order to build with mingw32-make off the command line, you'll need to also add the MinGW-w64 bin directory to your Windows path, and likely remove the Code::Blocks packaged MinGW from your path to avoid conflicts. You'll still use mingw32-make to build the library with MinGW-w64; even though it's named mingw32-make, it will build 64 bit.
If you decide to build the library 64 bit, you'll need to build your application 64 bit as well, so you'll want to set up MinGW-w64 for Code::Blocks. To set MinGW-w64 up in Code::Blocks, see this question: Setting up MingW and Code::Blocks in Windows 8 64 bit.