LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 07-17-2008, 07: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, 07:37 AM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
Yes, you need a cross compiler to build code for a different architecture than the architecture you're building on.
 
Old 07-17-2008, 07: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, 12: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, 03:31 PM   #5
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
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, 01: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, 04:30 AM   #7
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
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, 10:51 AM   #8
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
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, 02: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, 04:53 AM   #10
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

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


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

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

All times are GMT -5. The time now is 11:31 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
Open Source Consulting | Domain Registration