LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-17-2008, 08:24 AM   #1
samitpmc
LQ Newbie
 
Registered: Jul 2008
Posts: 8

Rep: Reputation: 0
compiling x64 application from ubuntu x86 using gcc compiler


Hello,

I want to compile my sample code for x64 platform.
I have ubuntu 7.0 installed on my box. I am using gcc 4.1.2 for compiling my code.

Let the same file be test.cpp
I am using the following command

g++ -m64 test.cpp

but there are errors?
Do I need to install x64 libraries or I have to use cross compiler for building x64 target. correct me if I am absolutely wrong.

Regards
Amit
 
Old 07-17-2008, 08:37 AM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,755
Blog Entries: 1

Rep: Reputation: 238Reputation: 238Reputation: 238
Yes, you need a cross compiler to build code for a different architecture than the architecture you're building on.
 
Old 07-17-2008, 08:58 AM   #3
samitpmc
LQ Newbie
 
Registered: Jul 2008
Posts: 8

Original Poster
Rep: Reputation: 0
thanks for the help.

could you tell me how can I use cross compiler for building code.
1 from where will I get cross compiler.
2 How can I run cross compiler to build for dirrefernt architecture.
3 please give me some link to gather more information.

Regards
Amit
 
Old 07-17-2008, 01:29 PM   #4
samitpmc
LQ Newbie
 
Registered: Jul 2008
Posts: 8

Original Poster
Rep: Reputation: 0
can any body help me out? Thanks in advance.
 
Old 07-17-2008, 04:31 PM   #5
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,755
Blog Entries: 1

Rep: Reputation: 238Reputation: 238Reputation: 238
Let's start from the beginning. What errors are you getting when you attempt to compile your test program? Let's make sure it really is a cross-compilation issue.
 
Old 07-18-2008, 02:41 AM   #6
samitpmc
LQ Newbie
 
Registered: Jul 2008
Posts: 8

Original Poster
Rep: Reputation: 0
Hi

while compiling test.cpp I get the following error

/usr/bin/ld: skipping incompatible /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../libm.a when searching for -lm
/usr/bin/ld: skipping incompatible /usr/bin/../lib/libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/bin/../lib/libm.a when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/libm.a when searching for -lm
/usr/bin/ld: cannot find -lm
collect2: ld returned 1 exit status


content of test.cpp is
#include <iostream>

int main()
{
std::cout<<"Hello Amit";
return 0;
}

I am using the following command to compile
g++ -m64 test.cpp

Regards
Amit
 
Old 07-18-2008, 05:30 AM   #7
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,755
Blog Entries: 1

Rep: Reputation: 238Reputation: 238Reputation: 238
OK, you need a 64-bit version of libm. This is provided by glibc. So you need to find a 64-bit version of glibc and stick libm in /usr/lib64, then add /usr/lib64 to /etc/ld.so.conf.
 
Old 07-19-2008, 11:51 AM   #8
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2014.08, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 14,279

Rep: Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664
Ubuntu 7.04 Feisty : 'libc6-i386_2.5-0ubuntu14_amd64.deb' (= glibc)
http://packages.ubuntu.com/feisty/am...-i386/download

Included is 'libm.so.6' , required is 'libm.so', so a softlink will do
=> 'ln -s libm.so.6 ibm.so' (the "'.so' link" is in the '-dev' package
= > http://packages.ubuntu.com/feisty/am...6-dev/download )

It would be easier if you could install the whole package, but
identical filenames have identical locations, so it's not possible.

The method from #5 weibullguy should be followed.

Regards
 
Old 07-21-2008, 03:03 AM   #9
samitpmc
LQ Newbie
 
Registered: Jul 2008
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks a lot.

I dowloaded linux 64 bit libraries and now the program compiles.

But I have a confusion. if I can build x64 platform simply by downloading X64 libraries then why we require cross compiler?

do we need it for compiling program for other OS like windows.

to be precise in which case should I think of using cross compiler?

Regards
Amit
 
Old 07-21-2008, 05:53 AM   #10
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,755
Blog Entries: 1

Rep: Reputation: 238Reputation: 238Reputation: 238
If you are building on an ix86 machine for an x86_64 machine, you are cross compiling.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Compiling gcc without compiler? davuuud Linux - Software 6 02-03-2009 12:16 PM
Ubuntu 7.10 how do you install GCC v3.4.6 compiler and use it cctv Linux - Newbie 5 03-25-2008 08:57 PM
C or gcc compiler in Ubuntu alar Ubuntu 3 09-21-2006 12:08 AM
Solaris 10 x64/x86 driver wanted cstsang Solaris / OpenSolaris 3 11-01-2005 12:27 AM
Will C++ Application run in computer without gcc c-compiler srivembu Linux - General 4 09-03-2005 11:20 AM


All times are GMT -5. The time now is 04:45 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration