How to develop cross platform shared libraries and an API? - linux

I want to write an shared library for Linux and Windows. My code must cross-compile on that operating systems. What is the best way to achieve this ? (compilers to be used are GCC on Linux and mingw on windows)

Related

Are there alternatives to gdi32 and ole32 under Linux?

I want to use some methods in the ole32 and gdi32 libraries under Linux, but these two libraries do not exist under Linux, so are there alternatives when using under Linux?
I am using CGO
Use the following way to quote
#cgo LDFLAGS: -lws2_32 -lgdi32 -lole32
No, there are no in-place alternatives for these libraries on Linux as they are part of proprietary Win32 API and facilities they provide are specific to Windows only.
To make your application build on Windows and Linux you will need to abstract parts of application that use Windows specific libraries and implement them again for Linux using relevant replacement libraries (likely with different interface). Typically this is done so that programming interface - such as functions, methods, types, etc. towards your application are same but the underlying implementation is platform specific (using e.g. gdi32 on Windows and your favorite GUI framework on Linux). To achieve this Go provides Build Constraints mechanism that tells compiler to pull-in/ignore only certain files from codebase on each platform.
Go's own os package is good example of doing this.
If your application is heavily dependent on Windows ecosystem and porting does not make sense, perhaps building Windows native binary and running it in Wine emulation layer on Linux might be cost-efficient option.

How can I convert Linux (PowerPC-based) Shared Library To X86 or X64 Linux?

I have an (xxx.so) shared library file and its based on powerpc linux.
now i want to use it in our project but first we need to convert it to X86 or X64 shared library for pc linux.
anyone can help me about this? Is it possible?
You can't: a binary file resulting from compilation of a C/C++ program is compiled for a specific Instruction Set Architecture. Since the two platforms have different instructions sets, you cannot convert the library of an architecture to the other. You need therefore to recompile the library.
First I would say that if you are trying to use functions from a library on one linux to another then there is a very good chance the library is available (somewhere) for your target machine. The odds are that the source code should be available.
If the library is specific to tat version of Linux then you should not be using it for cross platform work.
That said in principle you can :
Run the powerpc version of linux on an x86 or x64 system using a VM.
Try the the decompile-recompile route already suggested to you.
Write your own equivalent library for the target.
See if anyone has written a binary translation application for this purpose.
But if the library you want to use is simply not available for the system you are targeting, then you quite simply should not be trying to use it. It's practically suicidal programming practice.

Linux Kernel Examination in Windows

I want to examine the Linux kernel source code using Visual Studio on Windows. But I don't know how to do that. Do I need a virtual machine to run or debug the kernel or is there any special way for me to do that ???
What does "kernel examination" means to you?
Why can't you more simply study the source code of the Linux kernel?
It is free software, you cant fetch its source code from kernel.org
it is extremely likely that your Linux vendor publishes either the source code of his variant of Linux kernel, or patches against vanilla kernel source code. The GPLv2 license of the Linux kernel nearly requires such a behavior.
And a Linux system gives you a lot of tools (objdump, ....) to study ELF executable image (like the Linux kernel mostly is....)
You probably won't be able to compile the Linux kernel with Visual Studio. You need GCC (or a very compatible compiler). Linux source code uses many GCC extensions.
My advice is to install a Linux system on your development machine (you can have a dual boot if you want to keep Windows for games....) and to learn it and to use Linux tools (including emacs, grep, etags etc....) to study the source code of Linux. Remember that Linux is the preferred platform to build the Linux kernel... (if your distribution is Debian or Ubuntu or similar, learn about make-kpkg)
Also read some good books about Advanced Linux Programming and about the Linux kernel (there are many of them).
BTW, you could even customize your GCC compiler, e.g. with a plugin or a MELT extension, to measure, search, or even refactor the source code of the kernel. See also cocinelle.

Mac OS X shared library cross platform development

I should confess I do not even own a Mac, I have done Windows and Linux programming. Here I hope to learn something about Mac OS X by relating it to Linux if possible. And hopefully to be able to compile a Mac shared library without purchasing a Mac.
Note: There is absolutely no GUI, so Cocoa should not be required right? Also imagine I use C or c++0x, and POSIX for now.
What are the differences between Mac OS X shared library and Linux?
What is required to be able to run Linux .so files on Mac? Do I need a Mac-native replacement for ld-linux.so, and linux-gate.so or some other crt related object files?
Is there any cross platform gcc for Mac on Windows or Linux? (again no GUI)
Even though you don't need Cocoa/Objective-C, you still need to link against Mac OS X libraries (like libSystem, which is like libc on Linux). The file format is totally different (ELF vs. Mach-O) so there is no way to make a Linux library or tool work on a Mac without recompilation.
If you stick to POSIX/SUS APIs you can easily write things so they compile on both Linux and Mac without changes as long as you don't try any platform-specific things like reading Linux /proc files.
There doesn't seem to exist any cross-compiler for Linux-to-Mac development and I can't imagine anyone trying to do this: you'd be chasing a moving target without any real benefit.
The solution as always with these type of questions: buy a used MacMini on eBay or similar auction platform. They're cheap and will suffice.

What platforms are supported by gio and gvfs library?

When writing an application using the GIO and GVFS libraries from the GNOME stack what platforms will my application be available for? Will it be possible to compile the application on Windows, Solaris or *BSD, for example? Are the GIO/GVFS and dependent libraries available as binary packages on those systems?
GIO is part of glib; it uses POSIX APIs so it should work on all *nix systems, and it does have some support for Windows. GVFS is a client-server system, includes *nix-only headers and doesn't seem like it supports Windows at all.
I would start with the glib binaries on http://www.gtk.org/download-windows.html and go from there.

Resources