LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-16-2009, 08:48 AM   #1
Ace Blackwell
Member
 
Registered: Mar 2004
Location: Kentucky, USA
Distribution: SlamD 12.1 / Slack 12.0 ~ 14.2_64
Posts: 345

Rep: Reputation: 54
Cross Platform Programming


I want to start up programming (or learning programming) again. I am reading up on the KDeveloper package given that I can't find a Dev C++ for linux.

KDevelop looks pretty detailed but with a lot of capability. My concern is being KDE dependant. For me it's not a problem because I use Linux, but for other ppl I may want to share with will still be using Windows. So in short, my question is...

If I write something with KDeveloper and it has all the widgets and events being QT dependent, will I be able to use the code elsewhere or only in KDE?

Along the same lines, If I write a program that uses QT or allegro, why do I still need the libraries after it's compiled. Wouldn't compiling it to binary have the lib sections included, making the bin files independent?

Thanks

Ace
 
Old 01-16-2009, 09:45 AM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
If you stick to programming using libraries and functions/functionalities provided by Qt, you will be fine - it's when you incorporate the KDE-specific libraries (like IPC and application embedding) that it starts to become dependent on KDE.

You do not need the libraries - after compiling - only if you do a static compile. I don't know the option to pass to G++/GCC to statically link it - check the man page.

As for the binary files you are left with afterwards, they, alone are not system-independent simply because Window and Linux (and even BSD) all use different binary formats (byte-ordering, and the like). BSDs use a.out (at least, I think they still do), Linux uses ELF and I do not know what Windows uses, off the top of my head.

My opinion - for doing cross-platform programming - would be to write in Java; I suggest Java because of your, apparent, inclination towards C++ and I wanted to suggest a language with similar syntax. It's not a pretty language, but at least you know Java written on a Linux box will work on a Windows box, or an Apple box (only as long as you do not go near pathnames). In what little spare time I have, I am working on a portable pathname library for Java (I have not come across one, yet).

My only other choice for a language for cross-platform programming would be Common Lisp; but the syntax looks nothing like C or C++, or Java. It has a built-in portable pathname library.

Last edited by indienick; 01-16-2009 at 09:49 AM. Reason: Lispaganda
 
Old 01-16-2009, 10:15 AM   #3
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Quote:
You do not need the libraries - after compiling - only if you do a static compile.
This is back to front. You DO need the libraries after compiling as the binary will dynamically link back to the shared library.

Compiling statically involves linking the library in to the binary. The library has to be a static version itself.

Quote:
As for the binary files you are left with afterwards, they, alone are not system-independent simply because Window and Linux (and even BSD) all use different binary formats (byte-ordering, and the like). BSDs use a.out (at least, I think they still do), Linux uses ELF and I do not know what Windows uses, off the top of my head.
It's not just the executable file format that is the problem. The underlying OS's are entirely different and system calls etc are not compatible across the platforms. Even if the file PE and ELF formats were compatible the binaries would not be cross-platform. T
 
Old 01-16-2009, 10:25 AM   #4
Ace Blackwell
Member
 
Registered: Mar 2004
Location: Kentucky, USA
Distribution: SlamD 12.1 / Slack 12.0 ~ 14.2_64
Posts: 345

Original Poster
Rep: Reputation: 54
Thanks to both.

What I was asking on the bin files, wasn't whether an EXE would work in Linux and I know the source would have to be compiled with the needed libraries under each OS. My question (after having installed several Linux packages with dependencies) is if I compile a program with the needed libs, and then take the executable of that compilation and move it to a different computer of the same OS. The machine I went to shouldn't need the libraries right? Wouldn't the compiler already have taken the needed functions with it during the compiling?

Along with that, if I compile a simply hello world program that used the QT libs for any event catching (mouse click buttons etc) If I then took that code to Windows and compiled it, wouldn't it fail? Or would I need a Windows version of QT before I could compile it?


Ace

Last edited by Ace Blackwell; 01-16-2009 at 10:29 AM. Reason: Addendum (sp?)
 
Old 01-16-2009, 10:29 AM   #5
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Quote:
Originally Posted by Ace Blackwell
Wouldn't the comiler already have taken the needed functions with it during the compiling?
Only if you ran a static compile - and it was linked to statically-built libraries. I am pretty sure GCC defaults to dynamically-linked compilation
 
Old 01-16-2009, 10:48 AM   #6
Ace Blackwell
Member
 
Registered: Mar 2004
Location: Kentucky, USA
Distribution: SlamD 12.1 / Slack 12.0 ~ 14.2_64
Posts: 345

Original Poster
Rep: Reputation: 54
Ok I think I'm getting it. But the original concern was with KDeveloper. I'm reading a tutorial (I know, just enough information to be confused) From the tutorial there is so much QT set up, version, CVS setup and things of this nature. My concern is with all this extra baggage, I wouldn't be able to use the code for anything but a Linux GUI enviroment.

Most compilers I'm used to (M$ Quick C, and Dev C++) just compiles the code you write and adds only what you tell it(from my novice perspective). But just to do a "Yo World" type program in KDeveloper requires a detailed lengthy set up that gerenates various files of classes and configurations, that I'm afraid will make the program unique to Linux?

Am I'm make any sense? LOL

Last edited by Ace Blackwell; 01-16-2009 at 10:49 AM. Reason: files
 
Old 01-16-2009, 10:49 AM   #7
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Quote:
Along with that, if I compile a simply hello world program that used the QT libs for any event catching (mouse click buttons etc) If I then took that code to Windows and compiled it, wouldn't it fail? Or would I need a Windows version of QT before I could compile it?
If you have a Windows version of QT it will compile on Windows and work. This is why there are Windows versions of QT available. This is from the QT page here:
Quote:
Qt is a cross-platform application framework. Using Qt, you can write applications once and deploy them across many desktop and embedded operating systems without rewriting the source code.
kind of says it all I think.
 
Old 01-16-2009, 10:55 AM   #8
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Quote:
Most compilers I'm used to (M$ Quick C, and Dev C++) just compiles the code you write and adds only what you tell it(from my novice perspective). But just to do a "Yo World" type program in KDeveloper requires a detailed lengthy set up that gerenates various files of classes and configurations, that I'm afraid will make the program unique to Linux?
Don't confuse the files created by the IDE and version control system and the source code itself. The IDE may create config and Makefiles along with others but the basic source code (in your .c/.cpp) will be portable.

A bubble sort in KDevelop is a bubble sort in Visual Studio etc. it's just when you call OS/library dependent stuff the choice of platforms becomes limited.
 
Old 01-16-2009, 10:56 AM   #9
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Yes, yes. This is where most people (including myself) get a little fed up with IDEs.

If you want to do a simple "Yo World"-type of program, a text editor and an Xterm are your best bet.

All the stuff it's walking you through, is helping you set up things like Qt compatibility settings (because Qt is a cross-platform library) and CVS for code revision. Nothing in this should (theoretically) pin you to one platform.
 
Old 01-16-2009, 11:08 AM   #10
Ace Blackwell
Member
 
Registered: Mar 2004
Location: Kentucky, USA
Distribution: SlamD 12.1 / Slack 12.0 ~ 14.2_64
Posts: 345

Original Poster
Rep: Reputation: 54
Thanks guys, thats reassuring. I'll continue to read on in my tutorial. BTW there isn't a Dev C++ type compiler for Linux is there. I found one but requires buying the CD. Which I may do later if I can't find an alternative. I like the possibilities of KDev but at this time it really seems like overkill for my weak programs and tends to confuse me with all the added class work. I have to weed through numerous lines of code/files to look for my simple

cout<<"Yo World!!!";

Of course I could use your suggestion of a simple editor and command line compiling.

Thanks again for the attention and answers
Ace
 
Old 01-16-2009, 11:18 AM   #11
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
If you want cross-platform, there's always Java. It's a better language than C++ anyway (but what isn't?)
 
Old 01-16-2009, 11:35 AM   #12
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
To run a native linux app on Windows, the libraries need to be available as Windows DLLs. A very substantial number of Linux libs are available this way, including the QT suite and the gtk suite of tools.

There are some differences between Linux source and Windows source, mostly having to do with system calls. I handle this with #define statements and #ifdef statements at appropriate places in the C++ (or C) code.

I am cross-compiling a project of mine that I am rewriting from end to end. The new version will run in Linux but my major market will be in Windows. I am developing using Kdevelop in Linux and cross-compiling for Windows using mingw, which is the gcc toolset used as a cross-compiler.

I have found that the best way to do this is to create a double sub-directory structure in my project directory; one structure for Linux and the other for Windows. I have hard-linked all the c, cc, h, and hh files between the two projects to ensure that the code remains constant. In the Linux directory structure, I use kdevelop; in the Windows directory structure I use a makefile.

A handful of files ARE different between the two projects; the Linux version doesn't support MSSQL and the Windows version doesn't support MYSQL (mostly because I can't get the interface code to compile correctly). Also, I have an include file called target.h which exists separately in both systems. The Windows version of this file says:

#ifndef MS_WINDOWS_TARGET
#define MS_WINDOWS_TARGET
#include "windows.h"
#endif

while the Linux version says

#ifndef LINUX_TARGET
#define LINUX_TARGET
#endif

The include file is included by all source code that needs it.

Then, for instance, I have code segments that look like this:
Code:
#ifdef MS_WINDOWS_TARGET
sw=GetSystemMetrics(SM_CXSCREEN);
#endif
#ifdef LINUX_TARGET
sw=gdk_screen_get_width(screen);
#endif
This actually works pretty well, and makes it straightforward for me to go back and forth between target platforms while developing and testing.

Last edited by jiml8; 01-16-2009 at 11:49 AM. Reason: correct info on target_platform.h
 
Old 01-16-2009, 01:49 PM   #13
Ace Blackwell
Member
 
Registered: Mar 2004
Location: Kentucky, USA
Distribution: SlamD 12.1 / Slack 12.0 ~ 14.2_64
Posts: 345

Original Poster
Rep: Reputation: 54
Jim,

Thanks. This is a little advanced for me but I get the jest of it. And the skinny of the overall question is No, developing something in KDevelop doesn't lock it in to KDE or Linux.

Thanks again.
 
Old 01-16-2009, 06:15 PM   #14
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
If you want a slightly simpler IDE, and you are interested in QT then try QDevelop. It is an IDE for QT development, written using QT and so it is available in both Windows and Linux. You might find it easier to start with over KDevelop.
 
Old 01-25-2009, 01:34 PM   #15
Ace Blackwell
Member
 
Registered: Mar 2004
Location: Kentucky, USA
Distribution: SlamD 12.1 / Slack 12.0 ~ 14.2_64
Posts: 345

Original Poster
Rep: Reputation: 54
Well I've decided to try eclipse. I have it installed and of course it works great in Linux. It installed fine in Windows as well. I installed Cywin in Windows with gcc packages installed. The problem I have now is, how do I link the eclipse with gcc from Cywin? I run a simple program (YO World) but it won't build due to some make file issue. I believe its because it's not getting access to gcc. The reason I believe this is it is the same set of errors I was getting before I installed cywin and gcc.

Any suggestions?

Thanks
Ace
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Cross-Platform programming language? Romanus81 Programming 13 04-07-2008 07:57 PM
Cross-platform programming drbongo Programming 3 07-28-2007 10:09 PM
Cross-Platform Programming JMJ_coder Programming 7 03-11-2007 12:59 PM
Good resources for cross-platform Qt/ KDevelop programming TemplaraPheonix Programming 1 12-19-2005 09:03 PM
Cross Platform c++ gui programming djadhav Programming 8 05-25-2004 02:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration