tags:

views:

74

answers:

3

Hi, i have code written in c++. its a console app that takes an input and displays output. Now i can just give my a.out to someone without giving them the code and it should work on another unix system. but what if they have windows environment. I would like to learn how to make dll for them so they can run that.

also, if they were going to use it as part of another program I guess i would need to make an api or function for them. But i am not sure how that works with dlls as i have never done this before.

A: 

This will get you started: Cross Compiler article on Wikipedia.

Trevoke
+4  A: 

Now i can just give my a.out to someone without giving them the code and it should work on another unix system.

No it shouldn't and almost certainly won't. Executables are not typically portable across even closely related operating systems, and most flavours of Unix are not too closely related. You need to compile your application for the specific (and "unix" is not specific enough) target OSs you are interested in.

anon
A: 

You need to recompile your application for Windows, either on a Windows machine or by using a crosscompiler. This requires that all routines which you use need to be available under Windows, too.

Either you wrote your application from scratch using portable libraries (read: no unix/posix system calls), or you will get problems porting your code to run under Windows. Cygwin can probably help, check it out.

If you say its a pure console app, I assume you're using std::cout and std::cin or other stuff from the C++ standard library. These are indeed universally available on every C++ implementation.

Alexander Gessler
Cygwin cannot be used with proprietary software without a special licence (which you have to pay for).
Chris Jester-Young
yes i am just using all std stuffs. soo would that be an issue on windows or unix? ofcourse i need to recomplile it fro each env for windows xp i am just not sure how all that dll stuff works.
djones2010
Why do you need a DLL if its an executable console app? A DLL is the Windows equivalent for a shared library (*.so) under linux. It allows applications to dynamically load external libraries and use them. In your case, you get a simple PE EXE file which is Windows' 'a.out'. The compiler will link to a few Windows system DLLs (i.e. kernel32.dll) but this is done automatically and they're part of Windows. 'Just' distribute your EXE to your friends and you're fine, hopefully.
Alexander Gessler
they have an a windows program that will use this app of mine. essentially they want to call this program from their program but i don't want to share my code. it is a thought that i would at least like to try out...i am not sure how they coudl use the dll...meaning would i have to create some api or something that they can pass in the input that a user would put via console and return the result as output? i am not sure
djones2010
If it's simply intercepting console input and output: give them your exe file- They just need to call it with modified stdin and stdout streams (that's possible using the Windows API `CreateProcess`). If redirecting stdint,stdout is not enough, a full API is required (and you really need a DLL or at least a static library).
Alexander Gessler
yea they were talking about a static library. so, if we choose the route of the dll with static library how would that work?
djones2010