Cross-Compiler Discussion (split from Linker Error Topic)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Cross-Compiler Discussion (split from Linker Error Topic)

Post by JamesM »

Combuster wrote:Nor are you using the GCC Cross-Compiler
I dislike people harping on about this. On most linux systems you *do not need to build an explicit cross compiler*. The packaged one works fine out of the box.

[Edit by AJ - topic split from http://forum.osdev.org/viewtopic.php?f= ... 05#p205995]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: moving code from c to C++ gives linker error

Post by Solar »

*Sigh* :roll:

It's been discussed to death. Can we please bury the subject, or at least discussing it on the appropriate Wiki discussion page instead of every other thread where this recommendation is mentioned, over and over again?
Every good solution is obvious once you've found it.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: moving code from c to C++ gives linker error

Post by JamesM »

Solar wrote:*Sigh* :roll:

It's been discussed to death. Can we please bury the subject, or at least discussing it on the appropriate Wiki discussion page instead of every other thread where this recommendation is mentioned, over and over again?
I've made a comment in the discussion page saying I completely disagree with all of you except Love4Boobies.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: moving code from c to C++ gives linker error

Post by Combuster »

Provided what the OP posted, his setup only works properly if he's specifically using 32-bit linux, and specifically not 64-bit ones. I give him 90% chance of failing later without either using the recommended toolchain or adding toolchain-specific compiler options to whatever he's using now.

Therefore the suggestion is legit and I consider your response slightly overreacted.

Heck, I just noticed he's sufficiently ignoring your tutorial to have introduced the typical strings-do-not-work bug. XenOS' suggestion might provide a free fix for that, but who knows.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: moving code from c to C++ gives linker error

Post by JamesM »

if he's specifically using 32-bit linux, and specifically not 64-bit ones.
-m32. Well that was hard...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: moving code from c to C++ gives linker error

Post by Combuster »

Quiz question for the OP: what does -m32 do?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: moving code from c to C++ gives linker error

Post by JamesM »

berkus wrote:I believe building one's own cross-compiler is a sufficient toolchain handling test for any OSdev wannabe. If one can do it - well, he's got himself a cross-compiler. If one can't - time to write some userspace code first.
... and yet, utterly pointless.
User avatar
brain
Member
Member
Posts: 234
Joined: Thu Nov 05, 2009 5:04 pm
Location: UK
Contact:

Re: moving code from c to C++ gives linker error

Post by brain »

berkus wrote:I believe building one's own cross-compiler is a sufficient toolchain handling test for any OSdev wannabe. If one can do it - well, he's got himself a cross-compiler. If one can't - time to write some userspace code first.

While I agree that having a cross compiler has definite proven uses in osdev, I don't see how it proves any level of experience in coding userland apps. gcc has a god-awful configure/build process that imho is fragile and prone to random failure. I have written some pretty large and complex userland apps and none have been so awful to build in a custom setup as gcc is. at best, building a gcc cross compiler is an exercise in patience at the crappiness of automake and the gnu toolchain friends, plus its only relevant if you're using gcc. I am but many others are not.

Personally I managed to get a very reasonable os up and running before needing a cross compiler at all, and then only to play with 64 bit kernels under qemu on a 32 bit system. so there's my 0.02p worth. :-)
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: moving code from c to C++ gives linker error

Post by JamesM »

berkus wrote:
JamesM wrote:
berkus wrote:I believe building one's own cross-compiler is a sufficient toolchain handling test for any OSdev wannabe. If one can do it - well, he's got himself a cross-compiler. If one can't - time to write some userspace code first.
... and yet, utterly pointless.
Not at all. Some host system stuff could be nasty if pulled into kernel code by accident. xcc prevents this by not having any host stuff.
so does -nostdlibinc -nostdlib. Not to mention -sysroot.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: moving code from c to C++ gives linker error

Post by Combuster »

JamesM wrote:so does -nostdlibinc -nostdlib.
Actually, my host gcc says no. It happily includes stdio.h but only complains about missing _start meaning you only fixed half the problem.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: moving code from c to C++ gives linker error

Post by bubach »

I realize it can have it's advantages, but I also realize that some people will be just as happy learning a few command line switches - so why force something down their throats?

What I would like to remind you of, is that building a cross-compiler has always been a recommendation. But nowadays it seems more and more like a obligation to even get a response on this forum other than "get a cross-compiler".
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: moving code from c to C++ gives linker error

Post by Brynet-Inc »

JamesM wrote:
Combuster wrote:Nor are you using the GCC Cross-Compiler
I dislike people harping on about this. On most linux systems you *do not need to build an explicit cross compiler*. The packaged one works fine out of the box.
Great, now you're relying on a vendor-supplied build.. it could contain special patches not contained in the vanilla sources, it may also be upgraded to a newer release.

I don't understand why people keep trying to avoid building a cross-compiler, you set the version that you've tested to work with your kernel.. and others can replicate your setup using a different Linux distribution or OS entirely.

It's about creating a reproducible known working environment, and not having to deal with compiler bugs across umpteen different versions that other users may be using.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: moving code from c to C++ gives linker error

Post by neon »

I have heard of the "reproducible environment" argument before and don't see the value in it. Software with a good build environment will be able to adopt to new toolchains with ease; maintaining compatibility and creating a standard build system. If that argument is targeted toward newcomers, I still don't see it: I never seen it used on this forum for the purpose of aid.

I don't use the cross compiler because its gcc specific. Tying the software to a specific toolchain because of the build environment is not necessary.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: moving code from c to C++ gives linker error

Post by JamesM »

Software with a good build environment will be able to adopt to new toolchains with ease
Exactly my argument. Fixing to one known version of a compiler guarantees that your code won't be portable.

EDIT: And I'm really not keen on the idea of a "test for OSDev entry" - it's a ridiculous idea on so many levels.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: moving code from c to C++ gives linker error

Post by Solar »

JamesM wrote:
Software with a good build environment will be able to adopt to new toolchains with ease
Exactly my argument. Fixing to one known version of a compiler guarantees that your code won't be portable.
The idea is not fixing yourself to one known version of a compiler, but to enable others to use the same version of the compiler, to rule out differences in compiler configuration as a source for dodgy problems. Or, to be able to fall back to a known version of the compiler if your package manager updated to (hypothetical) GCC 6.2 and your build doesn't work anymore. Not because you want to stay with the 5.x version, but to get the build working again, and then working towards 6.2 compatibility.

(Try installing yesterday's version of your system compiler through apt-get. Good luck.)
Every good solution is obvious once you've found it.
Post Reply