C++ Build 32bit binary on 64bit system

Multi tool use
Multi tool use












1















So I have a project that I want to be able to build as a 64bit binary as well as as a 32bit one.

My machine itself is 64bit and the 64bit compile works just fine.



I am using cake to build my project and I used the set_target_properties(clib PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") to force a 32bit build.



Whenever I try to build this the compiler throws an error, because I am including <iostream> in my main program. At first it complained that it couldn't find <bits/c++config.h> which gets included somewhere inside <iostream>.

I found a couple of things online which led me to install g++-multilib on my system. Now the previous error is gone but instead I am getting the error
/usr/include/linux/errno.h:1:10: fatal error: asm/errno.h: No such file or directory which also has its origins in the #include <iostream>.



I checked where this file is and I found it in /usr/include/x86_64-linux-gnu/asm/errno.h but (as before with the c++config.h the x86_64 folder appears to not be searched in a 32bit build (which kinda makes sense).

I also found it in /usr/include/linux/errno.h which is identical to the precious one, but as you can see it is not in the asm subfolder.

Obviously I could manually move it into that folder but I have the feeling that there is something generally wrong with my setup here.



So what else do I have to setup in order for me being able to compile my code (with a #include <iostream>) as a 32bit executable? Is there something like a 32bit-version of the std-library?



EDIT:

I am using Linux Mint 18.3 with g++ --version of g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 and cmake v.3.10.2










share|improve this question




















  • 1





    This should “just work” with g++-multilib and its dependencies (and obviously it doesn’t, I’m not questioning that). What distribution (including its version) are you using?

    – Stephen Kitt
    9 hours ago











  • @StephenKitt I added the information in the question - did I miss something?

    – Raven
    9 hours ago











  • Does it work if you build the problematic C++ file manually, without cmake? (This will help determine whether g++ is causing problems, or cmake.)

    – Stephen Kitt
    6 hours ago











  • @StephenKitt I just tried compiling it via g++ -m32 main.cpp but it resulted in the same error

    – Raven
    5 hours ago











  • Okay nvm- I found the issue

    – Raven
    5 hours ago
















1















So I have a project that I want to be able to build as a 64bit binary as well as as a 32bit one.

My machine itself is 64bit and the 64bit compile works just fine.



I am using cake to build my project and I used the set_target_properties(clib PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") to force a 32bit build.



Whenever I try to build this the compiler throws an error, because I am including <iostream> in my main program. At first it complained that it couldn't find <bits/c++config.h> which gets included somewhere inside <iostream>.

I found a couple of things online which led me to install g++-multilib on my system. Now the previous error is gone but instead I am getting the error
/usr/include/linux/errno.h:1:10: fatal error: asm/errno.h: No such file or directory which also has its origins in the #include <iostream>.



I checked where this file is and I found it in /usr/include/x86_64-linux-gnu/asm/errno.h but (as before with the c++config.h the x86_64 folder appears to not be searched in a 32bit build (which kinda makes sense).

I also found it in /usr/include/linux/errno.h which is identical to the precious one, but as you can see it is not in the asm subfolder.

Obviously I could manually move it into that folder but I have the feeling that there is something generally wrong with my setup here.



So what else do I have to setup in order for me being able to compile my code (with a #include <iostream>) as a 32bit executable? Is there something like a 32bit-version of the std-library?



EDIT:

I am using Linux Mint 18.3 with g++ --version of g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 and cmake v.3.10.2










share|improve this question




















  • 1





    This should “just work” with g++-multilib and its dependencies (and obviously it doesn’t, I’m not questioning that). What distribution (including its version) are you using?

    – Stephen Kitt
    9 hours ago











  • @StephenKitt I added the information in the question - did I miss something?

    – Raven
    9 hours ago











  • Does it work if you build the problematic C++ file manually, without cmake? (This will help determine whether g++ is causing problems, or cmake.)

    – Stephen Kitt
    6 hours ago











  • @StephenKitt I just tried compiling it via g++ -m32 main.cpp but it resulted in the same error

    – Raven
    5 hours ago











  • Okay nvm- I found the issue

    – Raven
    5 hours ago














1












1








1








So I have a project that I want to be able to build as a 64bit binary as well as as a 32bit one.

My machine itself is 64bit and the 64bit compile works just fine.



I am using cake to build my project and I used the set_target_properties(clib PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") to force a 32bit build.



Whenever I try to build this the compiler throws an error, because I am including <iostream> in my main program. At first it complained that it couldn't find <bits/c++config.h> which gets included somewhere inside <iostream>.

I found a couple of things online which led me to install g++-multilib on my system. Now the previous error is gone but instead I am getting the error
/usr/include/linux/errno.h:1:10: fatal error: asm/errno.h: No such file or directory which also has its origins in the #include <iostream>.



I checked where this file is and I found it in /usr/include/x86_64-linux-gnu/asm/errno.h but (as before with the c++config.h the x86_64 folder appears to not be searched in a 32bit build (which kinda makes sense).

I also found it in /usr/include/linux/errno.h which is identical to the precious one, but as you can see it is not in the asm subfolder.

Obviously I could manually move it into that folder but I have the feeling that there is something generally wrong with my setup here.



So what else do I have to setup in order for me being able to compile my code (with a #include <iostream>) as a 32bit executable? Is there something like a 32bit-version of the std-library?



EDIT:

I am using Linux Mint 18.3 with g++ --version of g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 and cmake v.3.10.2










share|improve this question
















So I have a project that I want to be able to build as a 64bit binary as well as as a 32bit one.

My machine itself is 64bit and the 64bit compile works just fine.



I am using cake to build my project and I used the set_target_properties(clib PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") to force a 32bit build.



Whenever I try to build this the compiler throws an error, because I am including <iostream> in my main program. At first it complained that it couldn't find <bits/c++config.h> which gets included somewhere inside <iostream>.

I found a couple of things online which led me to install g++-multilib on my system. Now the previous error is gone but instead I am getting the error
/usr/include/linux/errno.h:1:10: fatal error: asm/errno.h: No such file or directory which also has its origins in the #include <iostream>.



I checked where this file is and I found it in /usr/include/x86_64-linux-gnu/asm/errno.h but (as before with the c++config.h the x86_64 folder appears to not be searched in a 32bit build (which kinda makes sense).

I also found it in /usr/include/linux/errno.h which is identical to the precious one, but as you can see it is not in the asm subfolder.

Obviously I could manually move it into that folder but I have the feeling that there is something generally wrong with my setup here.



So what else do I have to setup in order for me being able to compile my code (with a #include <iostream>) as a 32bit executable? Is there something like a 32bit-version of the std-library?



EDIT:

I am using Linux Mint 18.3 with g++ --version of g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 and cmake v.3.10.2







c++ 32bit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 9 hours ago







Raven

















asked 9 hours ago









RavenRaven

241115




241115








  • 1





    This should “just work” with g++-multilib and its dependencies (and obviously it doesn’t, I’m not questioning that). What distribution (including its version) are you using?

    – Stephen Kitt
    9 hours ago











  • @StephenKitt I added the information in the question - did I miss something?

    – Raven
    9 hours ago











  • Does it work if you build the problematic C++ file manually, without cmake? (This will help determine whether g++ is causing problems, or cmake.)

    – Stephen Kitt
    6 hours ago











  • @StephenKitt I just tried compiling it via g++ -m32 main.cpp but it resulted in the same error

    – Raven
    5 hours ago











  • Okay nvm- I found the issue

    – Raven
    5 hours ago














  • 1





    This should “just work” with g++-multilib and its dependencies (and obviously it doesn’t, I’m not questioning that). What distribution (including its version) are you using?

    – Stephen Kitt
    9 hours ago











  • @StephenKitt I added the information in the question - did I miss something?

    – Raven
    9 hours ago











  • Does it work if you build the problematic C++ file manually, without cmake? (This will help determine whether g++ is causing problems, or cmake.)

    – Stephen Kitt
    6 hours ago











  • @StephenKitt I just tried compiling it via g++ -m32 main.cpp but it resulted in the same error

    – Raven
    5 hours ago











  • Okay nvm- I found the issue

    – Raven
    5 hours ago








1




1





This should “just work” with g++-multilib and its dependencies (and obviously it doesn’t, I’m not questioning that). What distribution (including its version) are you using?

– Stephen Kitt
9 hours ago





This should “just work” with g++-multilib and its dependencies (and obviously it doesn’t, I’m not questioning that). What distribution (including its version) are you using?

– Stephen Kitt
9 hours ago













@StephenKitt I added the information in the question - did I miss something?

– Raven
9 hours ago





@StephenKitt I added the information in the question - did I miss something?

– Raven
9 hours ago













Does it work if you build the problematic C++ file manually, without cmake? (This will help determine whether g++ is causing problems, or cmake.)

– Stephen Kitt
6 hours ago





Does it work if you build the problematic C++ file manually, without cmake? (This will help determine whether g++ is causing problems, or cmake.)

– Stephen Kitt
6 hours ago













@StephenKitt I just tried compiling it via g++ -m32 main.cpp but it resulted in the same error

– Raven
5 hours ago





@StephenKitt I just tried compiling it via g++ -m32 main.cpp but it resulted in the same error

– Raven
5 hours ago













Okay nvm- I found the issue

– Raven
5 hours ago





Okay nvm- I found the issue

– Raven
5 hours ago










1 Answer
1






active

oldest

votes


















1














Alright I found out what was the problem:

When I found out, I had to use g++-multilib I went ahead and searched for that in my package manager (synaptic in my case). That one listed a bunch of versions so I checked what version of g++ I had installed and then I installed the appropriate g++-multilib-package which in my case was the g++-7-multilib.



However what it didn't install was the gcc-multilib package which appears to be the troublemaker in my case. After having installed that one, it worked as expected.





Long story short: If I had installed the g++-multilib (without a version in the name) package to begin with, I wouldn't have had this problem.






share|improve this answer



















  • 2





    Hah, good one; given your question it would have been difficult to find the answer for you (since you say you installed g++-multilib).

    – Stephen Kitt
    5 hours ago











  • Yeah well - I thought I did xD

    – Raven
    5 hours ago






  • 1





    Indeed; I’m just glad you found the answer on your own ;-).

    – Stephen Kitt
    5 hours ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495227%2fc-build-32bit-binary-on-64bit-system%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Alright I found out what was the problem:

When I found out, I had to use g++-multilib I went ahead and searched for that in my package manager (synaptic in my case). That one listed a bunch of versions so I checked what version of g++ I had installed and then I installed the appropriate g++-multilib-package which in my case was the g++-7-multilib.



However what it didn't install was the gcc-multilib package which appears to be the troublemaker in my case. After having installed that one, it worked as expected.





Long story short: If I had installed the g++-multilib (without a version in the name) package to begin with, I wouldn't have had this problem.






share|improve this answer



















  • 2





    Hah, good one; given your question it would have been difficult to find the answer for you (since you say you installed g++-multilib).

    – Stephen Kitt
    5 hours ago











  • Yeah well - I thought I did xD

    – Raven
    5 hours ago






  • 1





    Indeed; I’m just glad you found the answer on your own ;-).

    – Stephen Kitt
    5 hours ago
















1














Alright I found out what was the problem:

When I found out, I had to use g++-multilib I went ahead and searched for that in my package manager (synaptic in my case). That one listed a bunch of versions so I checked what version of g++ I had installed and then I installed the appropriate g++-multilib-package which in my case was the g++-7-multilib.



However what it didn't install was the gcc-multilib package which appears to be the troublemaker in my case. After having installed that one, it worked as expected.





Long story short: If I had installed the g++-multilib (without a version in the name) package to begin with, I wouldn't have had this problem.






share|improve this answer



















  • 2





    Hah, good one; given your question it would have been difficult to find the answer for you (since you say you installed g++-multilib).

    – Stephen Kitt
    5 hours ago











  • Yeah well - I thought I did xD

    – Raven
    5 hours ago






  • 1





    Indeed; I’m just glad you found the answer on your own ;-).

    – Stephen Kitt
    5 hours ago














1












1








1







Alright I found out what was the problem:

When I found out, I had to use g++-multilib I went ahead and searched for that in my package manager (synaptic in my case). That one listed a bunch of versions so I checked what version of g++ I had installed and then I installed the appropriate g++-multilib-package which in my case was the g++-7-multilib.



However what it didn't install was the gcc-multilib package which appears to be the troublemaker in my case. After having installed that one, it worked as expected.





Long story short: If I had installed the g++-multilib (without a version in the name) package to begin with, I wouldn't have had this problem.






share|improve this answer













Alright I found out what was the problem:

When I found out, I had to use g++-multilib I went ahead and searched for that in my package manager (synaptic in my case). That one listed a bunch of versions so I checked what version of g++ I had installed and then I installed the appropriate g++-multilib-package which in my case was the g++-7-multilib.



However what it didn't install was the gcc-multilib package which appears to be the troublemaker in my case. After having installed that one, it worked as expected.





Long story short: If I had installed the g++-multilib (without a version in the name) package to begin with, I wouldn't have had this problem.







share|improve this answer












share|improve this answer



share|improve this answer










answered 5 hours ago









RavenRaven

241115




241115








  • 2





    Hah, good one; given your question it would have been difficult to find the answer for you (since you say you installed g++-multilib).

    – Stephen Kitt
    5 hours ago











  • Yeah well - I thought I did xD

    – Raven
    5 hours ago






  • 1





    Indeed; I’m just glad you found the answer on your own ;-).

    – Stephen Kitt
    5 hours ago














  • 2





    Hah, good one; given your question it would have been difficult to find the answer for you (since you say you installed g++-multilib).

    – Stephen Kitt
    5 hours ago











  • Yeah well - I thought I did xD

    – Raven
    5 hours ago






  • 1





    Indeed; I’m just glad you found the answer on your own ;-).

    – Stephen Kitt
    5 hours ago








2




2





Hah, good one; given your question it would have been difficult to find the answer for you (since you say you installed g++-multilib).

– Stephen Kitt
5 hours ago





Hah, good one; given your question it would have been difficult to find the answer for you (since you say you installed g++-multilib).

– Stephen Kitt
5 hours ago













Yeah well - I thought I did xD

– Raven
5 hours ago





Yeah well - I thought I did xD

– Raven
5 hours ago




1




1





Indeed; I’m just glad you found the answer on your own ;-).

– Stephen Kitt
5 hours ago





Indeed; I’m just glad you found the answer on your own ;-).

– Stephen Kitt
5 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495227%2fc-build-32bit-binary-on-64bit-system%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







40aypiAymL7RYSpGVfPnU9qimF9yCDQRNs8SFm0xUtmsb,68dDU,vf3T AJ,dnBZPQ1Q vRz2VApDx9u
oPqYCp6zBmN0Ea2C3CTAW3KdJ1sOujXDBhXRjirwYK

Popular posts from this blog

Mouloudia Club d'Alger (football)

ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux

Ueberstorf