2

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

5
  • 2
    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? Jan 18, 2019 at 8:14
  • @StephenKitt I added the information in the question - did I miss something?
    – Raven
    Jan 18, 2019 at 8:19
  • Does it work if you build the problematic C++ file manually, without cmake? (This will help determine whether g++ is causing problems, or cmake.) Jan 18, 2019 at 11:02
  • @StephenKitt I just tried compiling it via g++ -m32 main.cpp but it resulted in the same error
    – Raven
    Jan 18, 2019 at 12:21
  • Okay nvm- I found the issue
    – Raven
    Jan 18, 2019 at 12:23

1 Answer 1

3

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.

3
  • 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). Jan 18, 2019 at 12:29
  • Yeah well - I thought I did xD
    – Raven
    Jan 18, 2019 at 12:38
  • 1
    Indeed; I’m just glad you found the answer on your own ;-). Jan 18, 2019 at 12:50

Not the answer you're looking for? Browse other questions tagged .