Error compiling a c++ with Python bindings using mingw and msys - c++

My environment: Windows 7 64 pro, mingw32 (installed with 2012-04-26.exe installer), msys 1.0, Python 2.7.3 installed using the Win64 installer from python.org
I'm trying to compile a c++ program that has python bindings, using mingw and msys. When I run config from the msys shell, I get the errors
Could not link test program to Python.
Maybe the main Python library has been installed in some non-standard library path.
If so, pass it to configure, via the LDFLAGS environment variable.
Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
============================================================================
ERROR!
You probably have to install the development version of the Python package
for your distribution. The exact name of this package varies among them.
============================================================================
I've tried to run configure with each of:
./configure LDFLAGS="-L/c/Python27/libs"
./configure LDFLAGS="-L/c/Python27/Lib"
./configure LDFLAGS="-Lc:/Python27/libs"
./configure LDFLAGS="-Lc:/Python27/libs"
and all give me the same final error. I've posted the entire config.log file at http://pastebin.com/fZVjTeub. Any help?

The problem was ultimately that I was using a 32-bit compiler and trying to link it to 64-bit Python.

In my case I've had to pass LDFLAGS="-L/c/Python27/libs" to ./configure

Related

How to use Boost.Python in Eclipse running on Linux Mint 18?

The objective is to compile a C++ program with Boost.Python in Eclipse on the OS on Linux Mint 18. In particularly, we want to run the template program:
#include<boost/version.hpp>
#include<boost/python.hpp>
#include<iostream>
using namespace std;
int main() {
cout << "My first boost program with version: " << BOOST_LIB_VERSION << endl;
return 0;
}
This personally took me quite a while to get working, so the tutorial below should serve as a one-stop-shop reference for anyone in a similar situation. Note on software used:
Boost version: 1.62.0
Python version: 2.7.12
OS: Linux Mint 18 Xfce 64-bit
Eclipse version: CDT 9.1.0 for Eclipse Neon.1
Installing Eclipse CDT
Make sure that you have Java installed. For the Java JDK (if you want to also develop Java programs), run:
sudo apt-get install default-jdk
To simply run Java programs (such as Eclipse), you can install the lighter Java JRE:
sudo apt-get install default-jre
Both JDK and JRE will work, but JDK takes up more space.
Go to CDT download webpage and download the Linux 64-bit file eclipse-cpp-neon-1-linux-gtk-x86_64.tar.gz
Assuming you downloaded the file in ~/Downloads/, run the following command to unpack ("install") Eclipse into the /opt/ directory:
sudo tar zxvf ~/Downloads/eclipse-cpp-neon-1-linux-gtk-x86_64.tar.gz -C /opt/
To create a desktop launcher icon, run
sudo gedit ~/.local/share/applications/eclipse.desktop
and in the text editor copy-paste:
[Desktop Entry]
Name=Eclipse
Type=Application
Exec=/opt/eclipse/eclipse
Terminal=false
Icon=/opt/eclipse/icon.xpm
Comment=Integrated Development Environment
NoDisplay=false
Categories=Development;IDE;
Name[en]=Eclipse
You now have Eclipse installed, but you don't need to run it yet, just keep reading and following the instructions :)
Installing Boost
The instructions are more or less given here, but for the sake of cohesion I write them here.
Download boost_1_62_0.tar.gz
Assuming you downloaded the file into ~/Downloads/, run the following command to unpack Boost into the /usr/include/ directory:
sudo tar zxvf ~/Downloads/boost_1_62_0.tar.gz -C /usr/include/
It's as easy as that - you now have Boost... but that's not all yet. Read on :)
Building Boost.Python and Boost.System
The Boost libraries Boost.Python and Boost.System must be built before they can be used. Here's how you do this:
Go into the Boost directory in your Terminal:
cd /usr/include/boost_1_62_0/
Run the command:
sudo ./bootstrap.sh --prefix=/usr/local
To build Boost.Python and Boost.System into the /usr/local/lib folder, run:
sudo ./b2 install --with-system --with-python
once the command has finished, you will find libboost_system and libboost_python (with various file endings) in /usr/local/lib
That's it for building the necessary Boost libraries. Note that any other Boost library that needs to be built can be done in the same way.
Preparing Python 2.7
Linux Mint 18 comes with Python 2.7 pre-installed. For me, running the command python --version returns the output Python 2.7.12. I'll assume this is the same for you - but probably it doesn't make a difference what the version is. However, to get our objective of the C++ program with Boost.Python to build and run, you have to execute the additional command:
sudo apt-get install python-dev
which places some additional necessary files (particularly pyconfig.h) into /usr/include/python2.7.
Installing Linux GCC
Linux GCC allows you to compile C++ programs. To install everything necessary, simply run:
sudo apt-get install build-essential
Making our program run in Eclipse
Now we've got everything configured to be able to write, build and run our program in Eclipse. So, let's do it!
Run Eclipse, either from the terminal (either by using the desktop icon we've created or by running /opt/eclipse/eclipse in the Terminal).
If it's your first time running Eclipse, you'll be prompted to choose a workspace (basically, a folder where all Eclipse project files will be stored):
Now go to File -> New -> C++ Project and enter the following and click Finish (you can use whatever Location you wish, including the default location (i.e. the one of your workspace)):
Now go to File -> New -> Source File, enter the following and click Finish:
In the main.cpp file that automatically opens in the editor, type in the program that we want to compile (note that I customized my Eclipse layout, so it looks different from the default layout you might have):
Now the secret sauce. Go to Project -> Properties -> C/C++ Build -> Settings where you will see:
Go to GCC C++ Compiler -> Includes and, using the little icon that looks like a folder with a green plus sign, add the following Include paths:
Go to GCC C++ Linker -> Libraries and add the following Libraries and Library search paths:
Press OK to close the Project Properties window.
Back in the main Eclipse window, first click the hammer icon to build the project, then the green play icon to run it (both buttons are highlighted in the below screenshot). In the console view you will first see a successful build, then the Terminal output of our program:
That's it! We've achieved our objective of building and running a C++ program with the Boost.Python library included. That's the end of this tutorial, I hope it helped you :)

install wx-widgets is driving me insane on Yosemite

I'm on Mac OS X Yosemite 10.10.2. As far as I know, wx-widgets were preinstalled on older versions on OS X (probably that's why google search doesn't help), but that's not the case anymore. I need to get started on a C++ project using wx-widgets, using any IDE (Eclipse, Codelite, or whatever is best). However, I simply cannot get wx-widgets to work. After a workaround I was able to compile on my machine wxWidgets-3.0.2. I called from terminal make and make install, but the libraries seem to not be correctly installed. Indeed, if I create a project on Codelite I get many "wx-config: Command not found" errors. Can someone help me to get me started on installing the libraries and creating a simple project that includes wx-widgets?
I use homebrew which is installed by copying and pasting one line from the homebrew website.
Then, the installation of wxWidgets is simplicity itself with:
brew install wxmac
Any problems, you just call the doctor with
brew doctor
Now you have a proper package manager you can install ImageMagick, GNU Parallel, GNU awk, Oxygen, webkit2html, zeromq, tree, SDL, Redis, sqlitebrowser, pandoc, exiftool, ffmpeg, 7zip, awscli, etc...
You can then compile your wxWidgets programs with
g++ `wx-config --cxxflags` -o sample sample.cpp `wx-config --libs`
I can successfully compile and install wxWidgets on Yosemite with these commands:
- Get the latest sources of wxWidgets 3 from wxwidgets.org and unpack them.
- Move the unpacked directory someplace where you want to keep it.
- Open a terminal and change into the wxwidgets directory.
- Create two directories: build-release and build-debug (don't rename those!)
- Change into wxwidgets/build-release
- Run
../configure --with-osx_cocoa --disable-shared --with-opengl --enable-universal-binary=i386,x86_64 --with-macosx-sdk=/Developer/SDKs/MacOSX10.6.sdk --with-macosx-version-min=10.6
- Run make, then sudo make install
- Change into wxwidgets/build-debug
- Run
../configure --enable-debug --with-osx_cocoa --with-opengl --enable-universal-binary=i386,x86_64 --with-macosx-sdk=/Developer/SDKs/MacOSX10.6.sdk --with-macosx-version-min=10.6
- Run make, then sudo make install
Be aware that these instructions are for compiling against the Mac OS X 10.6 SDK, which I have at /Developer/SDKs/MacOSX10.6.sdk. You can try to omit the --with-macosx-sdk parameter altogether, which will compile using the latest SDK. Also ensure that you have Xcode and the command line developer tools installed.
These commands will install static libraries for the release build and shared libraries for the debug build. You can change this by supplying or omitting the --disable-shared parameter.
The instructions for building and installing wxWidgets are included in the distribution and can also be viewed online.
If your IDE doesn't find wx-config, you must not have the location where you installed it (/usr/local/bin) by default in your PATH. Add it there to fix this.
Like suggested by VZ, you must change your PATH.
But not the variable PATH in your environment Windows but the variable PATH in your C++ project. It's strange but maybe it's different.
Go into (for eclipse) :
C/C++Build->Environment->PATH (add the path of wx-config in the beginning).
Press : Apply, OK and build the project.
I think is strange that Eclipse don't update the PATH after rebooting the OS. Maybe we must add an option to Eclipse for building WxWidget and force Eclipse to update the PATH, but I don't know it.
This change work for me.
Eclipse / MinGW-MSYS / WxWidget 2.8

mingw without g++ compiler

i am new to linux and I have the following question:
I am trying to install MINGW in Ubuntu.
I ran the command:
sudo apt-get install mingw-w64
It was installed, and if i put the command gcc it runs ok. The problem is g++ command does not work. I guess it is because i don't have the c++ compiler (as I read in similar questions in stackoverflow).
I read too that you can use the next command:
mingw-get install g++
but i don't have the executable program for this command.
My question is, how can I install that executable? or is there another way to update my mingw so I can use the g++ compiler?
Hope I have explained myself correctly. Thank you for any help I receive.
mingw-get is a windows specific package manager, it is not needed when you use a native linux package manager such as APT.
Installing package mingw-w64 depends on package g++-mingw-w64, which depends on g++-mingw-w64-i686 and g++-mingw-w64-x86-64.
These packages install the mingw cross compilers as
/usr/bin/x86_64-w64-mingw32-g++-posix
/usr/bin/x86_64-w64-mingw32-g++-win32
/usr/bin/i686-w64-mingw32-g++-posix
/usr/bin/i686-w64-mingw32-g++-win32
Older versions of mingw cross compiler shipped /usr/bin/i586-mingw32msvc-c++, which is replaced by i686-w64-mingw32-c++-win32
You can usually use this toolchain in a project by running ./configure CXX=i686-w64-mingw32-c++-win32 or make CXX=i686-w64-mingw32-c++-win32
Note: the above description is correct for the most recent toolchain in Debian unstable. It may need some minor tweaking for older systems.

target mingw with cygwin

I've tried building the gtest 1.5 library for MinGW
Using MSys to configure and then make results in a lot of errors, most about Win32API
On their website it says mingw is not supported but in the FAQ it is specified that a user managed to build it for mingw from cygwin configuring like this:
./configure CC="gcc -mno-cygwin" CXX="g++ -mno-cygwin"
This configure fails for me when running a sanity check for the C++ preprocessor ... something about "/lib/cpp".
I've tried a cygwin install with only mingw-gcc4 (4.3.4) and a cygwin install with mingw-gcc4 (4.3.4) and cygwin's own gcc (~3.4.4).
Generally, the library could be smoothly configured and built with cygwin gcc (3.4.4) using the flags you have specified above. You should only validate that gcc-mingw, gcc-mingw-core & gcc-mingw-g++ packages are installed in cygwin. There is no need in mingw-gcc4

How to compile for Windows on Linux with gcc/g++?

I have written some effects in C++ (g++) using freeglut on Linux, and I compile them with
g++ -Wall -lglut part8.cpp -o part8
So I was wondering if it is possible to have g++ make static compiled Windows executables that contains everything needed?
I don't have Windows, so it would be really cool, if I could do that on Linux :)
mingw32 exists as a package for Linux. You can cross-compile and -link Windows applications with it. There's a tutorial here at the Code::Blocks forum. Mind that the command changes to x86_64-w64-mingw32-gcc-win32, for example.
Ubuntu, for example, has MinGW in its repositories:
$ apt-cache search mingw
[...]
g++-mingw-w64 - GNU C++ compiler for MinGW-w64
gcc-mingw-w64 - GNU C compiler for MinGW-w64
mingw-w64 - Development environment targeting 32- and 64-bit Windows
[...]
Suggested method gave me error on Ubuntu 16.04: E: Unable to locate package mingw32
===========================================================================
To install this package on Ubuntu please use following:
sudo apt-get install mingw-w64
After install you can use it:
x86_64-w64-mingw32-g++
Please note!
For 64-bit use: x86_64-w64-mingw32-g++
For 32-bit use: i686-w64-mingw32-g++
One option of compiling for Windows in Linux is via mingw. I found a very helpful tutorial here.
To install mingw32 on Debian based systems, run the following command:
sudo apt-get install mingw32
To compile your code, you can use something like:
i586-mingw32msvc-g++ -o myApp.exe myApp.cpp
You'll sometimes want to test the new Windows application directly in Linux. You can use wine for that, although you should always keep in mind that wine could have bugs. This means that you might not be sure that a bug is in wine, your program, or both, so only use wine for general testing.
To install wine, run:
sudo apt-get install wine
Install a cross compiler, like mingw64 from your package manager.
Then compile in the following way: instead of simply calling gcc call i686-w64-mingw32-gcc for 32-bit Windows or x86_64-w64-mingw32-gcc" for 64-bit Windows. I would also use the --static option, as the target system may not have all the libraries.
If you want to compile other language, like Fortran, replace -gcc with -gfortran in the previous commands.
I've used mingw on Linux to make Windows executables in C, I suspect C++ would work as well.
I have a project, ELLCC, that packages clang and other things as a cross compiler tool chain. I use it to compile clang (C++), binutils, and GDB for Windows. Follow the download link at ellcc.org for pre-compiled binaries for several Linux hosts.
From: https://fedoraproject.org/wiki/MinGW/Tutorial
As of Fedora 17 it is possible to easily build (cross-compile) binaries for the win32 and win64 targets. This is realized using the mingw-w64 toolchain: http://mingw-w64.sf.net/. Using this toolchain allows you to build binaries for the following programming languages: C, C++, Objective-C, Objective-C++ and Fortran.
"Tips and tricks for using the Windows cross-compiler": https://fedoraproject.org/wiki/MinGW/Tips
For Fedora:
# Fedora 18 or greater
sudo dnf group install "MinGW cross-compiler"
# Or (not recommended, because of its deprecation)
sudo yum groupinstall -y "MinGW cross-compiler"