If I have a windows compiler based dll and .lib, can I link them with a app that I am compiling with cygwin g++ ? If not, will it work with a linux g++ library build ?
Are libraries generated from windows compiler, cygwin g++ and linux g++ cross linkable ??
No there are not. Libraries and executable files are specific to an operating system and to a processor. The only thing you can consider porting is source code, if it is written with great care. Some libraries (e.g. QtCore, Gtk/Glib, ...) are abstracting a platform and give you a common API (usable on many OSes), but you still have to compile for each system.
You could target a virtual machine (like JVM thru Java, or Lua bytecode, or Ocaml bytecode, ...) to get additional portability (at the expense of the cost of the VM implementation). You could also code software as scripts (e.g. using Python).
Related
What's different between the "GNU MCU Eclipse ARM
Embedded GCC " and "GNU ARM Embedded toolchain"? I'm new in Linux world and I need to programming STM32F4DISCOVERY board. And I can't understand what toolchain need is .
I would take a look at this article if you're curious about getting started with toolchains. It's from Nordic, not ST Micro, but it's very helpful to understand how the toolchain, makefile, and IDE all work together.
https://devzone.nordicsemi.com/tutorials/b/getting-started/posts/development-with-gcc-and-eclipse
I believe the brief answer to your question is that:
GNU MCU Eclipse ARM Embedded GCC is a family of extensions to the Eclipse IDE to develop code for ARM devices
GNU ARM Embedded toolchain is from ARM, and it's purely the compiler, linker, etc. needed to make a command line call to compile a C file and generate a binary for an ARM processor
If you're just looking to crank something out on your STM32, I would look to see if they have an IDE for your board/ application, as they're usually pre-bundled with the toolchain and an SDK.
GNU MCU Eclipse ARM Embedded GCC is based on the GNU ARM Embedded toolchain. From the README:
Compared to the ARM distribution, the build procedure is more or less the same and there should be no functional differences.
The only addition affects newlib, which was extended with printf()/scanf() support for long long and C99 formats (--enable-newlib-io-long-long and --enable-newlib-io-c99-formats).
The Docker images used to create the GNU MCU Eclipse ARM Embedded GCC release are also available on the project page, should you ever need it (probably not).
You should be fine with either of them installed along with the rest of the GNU MCU Eclipse suite.
Libraries built with Mingw-w64 require those dll:
libwinpthread-1.dll
libstdc++-6.dll
libgcc_s_seh-1.dll
I wonder what's up with that, what each dll does? Especially libgcc_s_seh, is that structured exception handling? I thought mingw couldn't work with seh.
Why mingw requires to always bring those dll with your exe?
I wonder if I'm just wasting my time by not just using visual studio as a windows compiler. It's so bloated though, 9 gb for installation.
Especially libgcc_s_seh, is that structured exception handling? I thought mingw couldn't work with seh.
Newer versions of GCC (4.8+ if I'm correct) should support SEH on MinGW.
I wonder what's up with that, what each dll does?
They provide the runtime and standard library.
libwinpthread: PThreads implementation on Windows (Threading)
libstdc++: C++ Standard Library (C/C++ library functions etc.)
libgcc_s_seh: Exception handling (SEH)
Why mingw requires to always bring those dll with your exe?
Because your program uses them. If you write a program without threads, standard library and exception and any OS interaction you wont need them.
These DLL's bring everything you need to run your program. Btw. this is not a MinGW only thing, and happens on other systems / compilers too. Often you just don't note this because the OS already ships the libraries, eg. MSVC libraries are very likely on a Windows machine. Dynamic linking always requires some sort of library files, that are .dll on Windows and .so on Linux.
If you have it available on your system use ldd <your application> to see what libraries are dynamically linked.
You can install these MinGW libraries into the system libraries or somewhere where the OS can find it. This enables your programs to use it and you no longer have to ship it with every application (what avoids duplication).
On the other side another option is to static link them. Unlike dynamic linking, you don't need any DLL; on the downside is a increase of you applications size (as now the three libraries are baked into the exe now).
I wonder if I'm just wasting my time by not just using visual studio as a windows compiler.
This depends on your situation. But probably my answer will give you some more insight.
I've read that mingw can be used on Linux to build a windows executable from C/C++.
Can other languages do this, and how about popular GUI libraries?
In particular I'm interested in OCaml and Haskell as languages and libSDL, wxWdgets, and GTK as libraries.
It doesn't matter whether the language has support - what matters is the compiler (unless you're using a WORA language like Java). To answer your question, it is possible to build a cross compiler on Linux to target the Windows platform. SDL, wxWidgets, and GTK all have Windows versions to my knowledge, but you have to compile them with a compiler targeting Windows to be able to get object code that can run.
Cross compiling is very messy because you need to have one copy of a library of each architecture and platform that you want to target, and they all have to be installed in different places, so you need to play with linker flags a lot.
Here's a blog post explaining how to get a GCC distribution for Linux targeting Windows. And regarding Haskell and OCaml, sadly I'm not knowledgable in these areas, but the general case will hold true.
I have source code for a linux application. It seems I can compile it on windows with CygWin. My question is, after compilation, can I run it on Windows?
Depends totally on what APIs you use. If you stick to C standard library things, like <stdio.h>, <stdlib.h>, etc. then yes, you can just compile and run on either OS. Or for C++ apps, there is the Standard C++ Library, which any OS / development environment should provide.
If you use any OS-specific APIs, then of course it will not be compatible with another OS. There are libraries however, like APR that try to abstract out the OS-specific bits.
From a casual glance at the code you've linked to, it appears to not use any OS-specific APIs. However:
Note that this code requires the Gnu Scientific Library, http://www.gnu.org/software/gsl/
you'll need to get that library installed as well.
The simple answer is yes; if you can compile a Linux application with Cygwin, then the compiled application will run on windows. Cygwin provides windows implementations of many unix system functions and libraries.
Cygwin/mingw(http://www.mingw.org/) should have most of the tools you need to build the binary. Once the build succeeds, you can run the binary (only) on windows.
Is there anyway to write dlls in linux?
Do I have to install windows to write dlls in linux? Right now one of my courses requires me to write a dll for this.
You should take a look into 'shared libraries'
http://www.linux.org/docs/ldp/howto/Program-Library-HOWTO/shared-libraries.html
Lots of folks are getting near the right answer but not providing it: gcc can generate win32 PE/COFF files without problem, and of course can always build as a cross compiler on any platform it can target. The binutils port targets windows .exe and .dll files natively, and there's a "dlltool" utility for handling the edge cases where Unix and Windows linkage metaphors are different.
Additionally, the "mingw32" project provides a set of link libraries and header files for building C applications against the win32 API. These likewise install just fine on any Unix.
Here's a site I turned up after a quick google with instructions for building the toolchain.
Not really. Building any kind of executable intended for OS "A" while using OS "B" is a process commonly known as cross-compilation. In this partciluar case, you would need a cross-compiler running on Linux, but targetting Windows. I don't know any vendor selling such a product.