Linking with pe-i386 object file and a pe-x86-64 object file - ld

Because my understanding of this problem is limited, please excuse me if I provide irrelevant details.
Question
I have two versions of MingGW on my computer, and both are 32-bit. The first one is what I call "basic MinGW", and it's the one I installed using mingw-get several years ago. The other one came with MSYS2.
Here are the constraints I am dealing with, details provided in the postscript:
My program depends on library A, which I can only compile from source using the MSYS2 MinGW.
My program depends on B.dll, a file that was provided to me. I do not have the source.
Using objdump, I discovered that B.dll has file format pe-i386
Using objdump, I discovered that programs compiled with the basic MinGW have file format pe-i386
Using objdump, I discovered that programs compiled with the MSYS2 MinGW have file format pe-x86-64
The end result is this:
My program cannot compile with the basic MinGW because library A (which must be compiled with MSYS2 MinGW) is incompatible
My program cannot compile with the MSYS2 MinGW because B.dll is incompatible
What is the difference between these two file formats? If they are both 32-bit, why can't I compile them together? Is it possible to convert B.dll to be compatible with the MSYS2 MinGW?
Details
Library A is libevent. At some point, libevent requires netioapi.h which does not appear to be present in the basic MinGW. However, MSYS2 MinGW is able to compile libevent.
B.dll is provided to me in Modelsim. It is the library you must link against fro compiling Verilog PLI programs.

Related

How do I specify a compiler in a different directory than MinGW in a NetBeans Toolchain module

I am attempting to make a simple ToolChain for the Borland 4.5 compiler with the Pharlap extender based on instructions at the Apache website: https://netbeans.apache.org/kb/docs/cnd/toolchain.html
I am basing the ToolChain on MinGW so that I can use those tools for make.
I cannot get the new toolset to find the Borland compilers the way MinGW is automatically discovered. If I use g++ as the compiler name, Netbeans finds that OK. The issue seems to be with the directory. I'm assuming an installation directory of C:\BC45\BIN and attempting to find BCC32.EXE in that directory.
When I run (clean, build, then run) the test installation of the netbeans module, I see my new toolchain in C/C++, but the field for the C++ compiler is always empty unless I specify a program in the c:\mingw\bin (base) directory.
I have tried variations on the following in my cpp xml file, making sure from time to time that it works just fine with g++ as the name:
<cpp>
<compiler name="bcc32.exe"/>
<recognizer pattern=".*[\\/]bc45.*[\\/]bin[\\/]?$"/>
I haven't found documents beyond the Apache website. I'm basing my guesses on what I have found in: %appdata%\NetBeans\12.4\config\CND\ToolChain\MinGW.xml
The XML above was OK as far as it goes. The example at apache.org only fills in the subclass of c++ (cpp). When I also subclassed the c, assembler, and linker, I ended up with the fields in the C++ options automatically populating as expected.
vcc4n (https://sourceforge.net/p/vcc4n/wiki/Home/) has a good example of implementing the four important classes for those build tools, but really just continuing the example to create and fill in the additional XML as specified in layer.xml is straightforward enough.

why does the error regarding gcc is occuring in matlab?

I have download that code from github.
Whenever that code tries to check mexopencv (a file inside lib folder). It shows an error on Matlab 2017a that is:
[error 3] please make sure gcc >= 4.4 g++ >= 4.4 is installed ...
I am having a gcc version of 8.8.0
Following is the description of system
Window 10
Visual Studio 2012
Matlab 2017a
opencv 2.4.10
mexopencv (install from your folder LIB)
You might lack of standard libraries (.dll in Windows but .lib in Linux). The code was developed under Linux (help is also only provided for Linux systems) and once tested under Windows 7.
The method was tested under OS linux lubuntu 14.04, CPU intel i5 and
16GB of RAM. This guide was written under a linux-based distribution
scope, more precisely debian. Unfortunately we lack experience to
address bugs or any problem that could emerge in non-linux OS, we will
provide only linux OS help regarding execution problems, we apologise.
we tested this code on Windows7. We successfully installed opencv
2.4.10 following this tutorial: [http://www.learnopencv.com/install-opencv3-on-windows/]
This suggests that the mex-function is also linux-based. The error should vanish if you compile the source code yourself on your system, e.g. with MinGW (also GCC), see here.
EDITED:
the README.markdown file (under LIB/mexopencv-master.zip) provides a little guide through the installation process of both, openCV and the mexopencv function for unix (including ubuntu 14.04) and Windows systems. The latter states:
Browse to mexopencv root folder, and type the following in the MATLAB
command window:
>> mexopencv.make
By default, mexopencv assumes the OpenCV library is installed in
C:\opencv. If this is not the case, specify the path as an argument:
>> mexopencv.make('opencv_path', 'c:\your\path\to\opencv')
Note that if you build OpenCV from source, this path specification
might not work out of the box. You need to replace dll files in the
OpenCV package with newly built binaries. Or, you need to modify
+mexopencv/make.m to correctly link your MEX-files with the library.
To remove existing mexopencv binaries, use the following command.
>> mexopencv.make('clean', true)
It requires a standard C++ compiler supported by Matlab (see here), any Visual Studio installation should be OK, as an open-source option MinGW is recommended. Just remember to pick the right system (usually 64-bit).

How to compile distributable Fortran binaries on Mac OS X Mountain Lion?

Since Apple have stopped distributing gfortran with Xcode, how should I compile architecture independent Fortran code? I have Mac OS X Mountain Lion (10.8), and XCode 4.4 installed, with the Command Line Tools package installed.
Apple's Native Compilers
As far as I can tell, the Xcode C / C++ / ObjC compilers use a fork of the GNU compiler collection, with llvm as a backend; the latter I figure enables compiling and optimising "universal" binaries, for both Intel and PPC architectures.
3rd party binary Fortran compilers
HPC
I've only found a single website that distributes a binary version of gfortran specifically for Mountain Lion: the HPC website. However, I failed to get this to compile SciPy, and later saw in SciPy's README that it is "known to generate buggy scipy binaries".
CRAN/R
SciPy's recommended (free) Fortran compiler is the one on CRAN's R server, but this has not been updated for Mountain Lion yet. They provide instructions and a script for Building a Universal Compiler, but, again, this hasn't been updated for Mountain Lion yet..
G95
The G95 project hasn't had an update since 2010, so I didn't try it.. Anyone tried this on Mountain Lion?
MacPorts
I guess this will be the easiest way to get gfortran installed, but port search gfortran comes up with nothing, and I've not had any joy with MacPorts in the past (no offence to MacPorts; it's looks like a very active project, but I've been spoilt with Linux package managers, my favourite manager being aptitude) so on Mac OS X I've compiled software and libraries from source code in the past. Never been a problem 'til now...
Building a Fortran compiler
Having dug around on the internet a lot in the last couple of days, I've found other Fortran compilers, but I've failed to get any to cross-compile universal binaries, or to compile SciPy.
GCC - The Gnu Compiler Collection
I compiled the entire GCC collection (v4.6.3), including autotools, automake, libtool and m4 - like the GCC wiki and this blog describe - but the resulting compilers didn't compile universal binaries, probably because LLVM wasn't used as a backend.
DragonEgg
DragonEgg is a "gcc plugin that replaces GCC's optimisers and code-generators ... with LLVM". This looks interesting, but I don't know how I could use it to compile 'llvm-gfortran-4.x'. Can this be done?
Compatibility
Libraries
The compiler that comes with Xcode is (a fork of?) GCC v4.2. But GCC's current release and development branches are versions 4.6 and 4.7, respectively. Apparently, a GNU license change, or something, stopped Apple from updating to more modern versions of GCC. So, if I was to build dynamic libraries made with GCC's gfortran v4.6, could they then be linked with C code compiled by Xcode's native compiler? At a minimum, I figure resulting Mach-O binaries need both x86_64 and i386 code paths. Do GCC provide backwards compatibility with Apple's (forks of?) GCC? I know gfortran has the -ff2c flag, but is this stable across versions?
Compile flags
The GCC Fortran compiler I built from source didn't support the use of the -arch compile flag. I had been including the flags -arch x86_64 -arch i386 in both CFLAGS and FFLAGS environment variables on earlier OSX versions (Snow Leopard to Lion). Python's distutils, and probably other OSX compilers, expect these flags to work, when configured to build apps or frameworks, using Xcode's universal SDK.
In case you're wondering what compile flags I use, I've uploaded the script I use to pastebin, which I source before I compile anything, using: source ~/.bash_devenv.
The Ideal OSX Fortran Compiler
Create ppc and intel (32 and 64bit) universal binaries, specified by using the -arch flags.
Makes binaries compatible with XCode's linker.
Compiles SciPy, giving no errors (compatible with numpy's distutils and f2py).
I don't use Xcode so much, but integration with it would surely benefit other users. Even Intel are still having problems integrating ifort into Xcode 4.4, so this is not something I expect to work..
If you read all the above, then thank you! You can probably tell that I'm not averse to building my own Fortran compiler from source, but is it even possible? Have I missed something? A configure flag maybe? And if such a compiler is not available yet, then why not?!
(Update:) Apple's GCC
Apple provide the source code for their patched version of GCC, at opensource.apple.com. This actually includes the source code for gfortran, but what do you know - it doesn't compile (easily). I'm in the process of writing a build script to get this to work. Unfortunately, I've had to apply a couple of patches, and learn about "the Apple way" of building GNU software. This is the way to go I think. Any reasons why it shouldn't be? I'll update with an answer if I get it to work...
I managed to compile after installing gfortran from http://r.research.att.com/tools/gcc-42-5666.3-darwin11.pkg, as explained here. I had to try to open the package a couple of times, though. First time it said that only apps from App Store can be installed. After installing gfortran, python setup.py build and python setup.py install worked fine. The unit tests of scipy though give a fairly high number of fails, not sure it's normal.
Ran 5481 tests in 82.079s
FAILED (KNOWNFAIL=13, SKIP=42, errors=11, failures=72)
<nose.result.TextTestResult run=5481 errors=11 failures=72>
In case you didn't already notice this: In newer versions of Xcode you have to explicitly install command line tools in the following way:
Preferences -> Downloads -> Components
And then click the "install" button for command line tools. This includes gfortran:
> gfortran -v
Using built-in specs.
Target: i686-apple-darwin10
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5664)
Admittedly, this does not solve all of my fortran needs (in some cases "./configure" scripts will complain that they cannot "compile a simple fotran program").
You could use brew (or Homebrew) to install gfortran.
$ brew install gfortran
I know you said you don't like MacPorts, but if you install the gcc48 port, it does in fact include gfortran (although you'll also have to do sudo port select --set gcc mp-gcc48 to get it to set up the symlink named gfortran).
Also, FWIW, the MacPorts option is not necessarily a binary - MacPorts can actually build it from source, which is why it sometimes takes a while. On the other hand, it also sometimes seems to get archived binaries from somewhere, but I think it depends on what the original author of the portfile uploaded.
I ended up compiling gfortran the source code provided at Apple's developer tools source code page. This seems to be working okay now - I've successfully compiled x86-64 and i386/i686 LAPACK, ATLAS and BLAS fortran libraries - but there are some ranlib tests which fail, when running make -k test in the build directories. (I could provide more info on that pastebin or somewhere, if someone wants...)
Build process
After asking the question, I downloaded Apple's llvmgcc42 source code tar archive, which includes the source code for llvm/gcc C, C++, ObjC and fortran compilers, and spent some time trying to compile a universal build of gfortran. The build takes about 30-60 minutes on my quad-core 2.8GHz Mac Pro, and became quite an involved process, so I wrote a set of build scripts for it, which I've shared at github.com.
....
I'll keep a tar archive of my build here for the time being, if anyone would like a copy. (Updated 26-Sep-2012) It'll only work if installed with a prefix of /usr/local/ though, unless you run install_name_tool on the executables and dylibs, to change the prefix from /usr/local to wherever you want to put it. You can test install_name's with otool -L filename (more info on the reasons for this is here).
The final build I'm now using also includes updates to the gcc/fortran and libgfortran directories, which I got from GNU GCC 4.2.4. These sources I got from my local GCC's mirror. There were only minor changes between 4.2.1 and 4.2.4, and the build scripts include the patches needed to upgrade the code.
The build-gfortran.sh script I wrote downloads missing dependencies (mpfr and gmp), compiles and cross-compiles them, patches differing headers with architecture-dependent preprocessor macros, and runs lipo to create universal binaries and libraries, eventually supporting both i386 and x86_64 architectures. The process is similar for llvmCore, and then GCC. I mostly copied code from the build_llvm and build_gcc bash scripts provided with Apple's llvmgcc42, but had some of it had to be modified, including a few lipo and install_name_tool commands.
The official way to compile Apple's gcc, using Xcode's gnumake just didn't work for me. I thought this should work just byadding "fortran" to the LANGUAGES variable in build_gcc.
With regards to compiling Scipy, still can't get that building perfectly. I've had to use clang and clang++ as C/C++ compilers, or else I get EXC_BAD_ACCESS malloc errors. Haven't tried the gcc/g++ compilers I built, just used the system ones. This is as reported for Lion, on the Scipy install page. I'm down to 11 errors and 1 failure, which are all raised from the same 3 function calls (_fitpack._bspleval, numeric.asarray, testing.utils.chk_same_position). Think that's pretty good, but I'd like every test to pass...

How do you set up an x64 development environment based on gcc and eclipse?

I want to create 64 bit apps for (for example) 64 bit Windows 7. I've searched the web and found some help but couldn't get it to work.
Sorry I've taken so long to respond but I have tried to get the packages suggested to work but they're not easy or else I'm doing something wrong.
Anyway I ran across an environment called pellesc. It consists of a development environment around a compiler which traces is roots back to a 32-bit version that was once (according to Wikipedia) used to develop Quake. From what I've seen so far it's very promising and generates good code too!
In spite of what other people are saying, Eclipse actually has very good support for C++, even in Windows: check out the CDT project. It's very mature and well-supported -- it works for C/C++ at least as well as Eclipse JDT works for Java.
As for the compiler itself, VonC is right, MinGW-w64 (but the mingw-w64 project is moving to mingw-w64.org so i suggest to use mingw-w64.org) is the best option. Eclipse CDT has built-in support for MinGW so as long as you install MinGW first, Eclipse should automatically detect it.
This Eclipse MinGW64 tutorial mentions:
update (Nov 9, 2010): recent MinGW-w64 versions come with 'as', 'g++', and 'gcc' commands. This step may be unnecessary in your MinGW build.
Meaning you won't have anymore to update the GCC assembler, C++ compiler, C compiler and C++ linker, with 'x86_64-w64-mingw32-as', 'x86_64-w64-mingw32-g++', 'x86_64-w64-mingw32-gcc', and 'x86_64-w64-mingw32-g++'.
Other great source for w64 development tools:
Native windows x64 software develop with Mingw-w64 on drangon.org
A 64-bit version of GCC for Windows is available at http://tdm-gcc.tdragon.net/download. I can't see why you would want to use Eclipse for C or C++ programming - try the Code::Blocks IDE at http://www.codeblocks.org instead.
Honestly, I use cygwin. Its compatable with unix so you can easily move systems and has tons of functionality that is gcc friendly (autoconf, make, makedepends, ...). To use gcc to compile to 64 bit add the -m64 option. To compile for windows use the -mno-cygwin option. Make sure though that you're using gcc 3 and not 4 (then you'd use the mingw compiler series). Otherwise, its all the same as unix which is really useful.

Recompile Arduino Target for Simulink for Windows 64 bit

I want to use Arduino Target for Simulink. It is made only for 32bit versions of Windows, but I read that you can recompile it and use it in 64-bit Windows.
I have tried, but I have not succeeded. I think that the files you need to create are the ones ending on .mexw32. What do you use to recompile these?
From http://www.mathworks.com/matlabcentral/fileexchange/24675-arduino-target:
To compile the C files for win64 (or
another platform), first make sure you
have a supported compiler:
http://www.mathworks.com/support/compilers/R2010b/win64.html
Once you have a compiler installed,
you can run "mex -setup" to point to
the appropriate compiler.
Finally, you can run "mex filename.c"
to compile all the functions in the
blocks directory.