0

subject pretty much says it all:

  • I downloaded yaml-cpp version 0.6.3.
  • I need to compile on linux x86_64, target linux x86_32 (build on 64 bit, use result on 32-bit)
  • I have been trying to add a new "YAML_BUILD_32BIT" option - similar to the existing YAML_BUILD_SHARED_LIBS option.

When I detect YAML_BUILD_32BIT is set: I try to add "-m32" to a bunch of cmake variables. My problem is that this list of variables seems endless or not well defined.

  • "yaml_cxx_flags" are passed to the compile and link steps for the yaml-cpp library code...but not to build the google 'mock' code. Similarly, I found other variables that I can also set, so that google-mock is compiled with -m32 as well...but then the yaml-cpp mock tests do not see the flag...and so on and so on.

I think I am missing something very fundamental. I expect that there will be a single variable I need to update...maybe 2 or 3. I don't expect to keep finding more and more.

--

Adding more specifics:

To CMakeLists.txt:

  • added line (immediately after the similar line which creates the YAML_BUILD_SHARED_LIBS flag)
option(YAML_BUILD_32BIT "Build with '-m32'" OFF)
  • then a bit later (immediately after the YAML_BUILD_SHARED_LIBS if/else):
   if(YAML_BUILD_32BIT)
     # seem to need this one for the shared lib link of yaml-cpp lib
     #  CXX_FLAGS passed to both compile and link
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
     # seem to need this one, to get flag passed to gmock build
     set(FLAG_TESTED "${FLAG_TESTED} -m32")
     # this one passed to compile and link of testcase
     set(yaml_cxx_flags "${yaml_cxx_flags} -m32")
   endif()
  • and made "FLAG_TESTED" addive, on immediately following line:
    set(FLAG_TESTED "-Wextra -Wshadow -Weffc++ -pedantic -pedantic-errors ${FLAG_TESTED}")

Given the above, then configuring with:

  # using cmake/3.19.3
  cmake -G "Unix Makefiles" -DYAML_BUILD_SHARED_LIBS=ON -DYAML_BUILD_32BIT=ON"

... and then building with 'make VERBOSE=1', I see that 'gmock-all.cc.o' did not receive the -m32 flag. (gmock-all.cc.o is only the first such file in my log..there are others.) If I remove other of the lines in my CMakeLists.txt which attempted to add flags - then other compile commands or other link commands don't see -m32 and will fail.

As I said: I think there is something fundamental that I have misunderstood. I suspect that it is much easier to configure a 32-bit build than I am making it.

5
  • Have you checked that question about compiling 32bit binaries in the 64bit environment? None of its answers suggest to set "a bunch of cmake varaibles". Commented Feb 26, 2021 at 20:38
  • we have a lot of code that we build and test in 32-bit mode (as well as 64-bit mode)...so yes (or no?) My specific problem is how to set up the yaml-cpp configuration so that all of the objects (both code, test infrastructure, and testcases) compile with -m32, and all the shared libraries and executables link with -m32. Commented Feb 26, 2021 at 21:33
  • The second answer to the referenced question is a toolchain file, which is created outside of any CMake project. Have you tried that approach? Please, show (add to the question post) what exactly have you tried. Commented Feb 26, 2021 at 21:38
  • Just tested: Adding line set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") immediately after the line project(YAML_CPP VERSION 0.6.3 LANGUAGES CXX) adds -m32 to every compilation, even for gmock-all.cc.o. BTW, passing -DCMAKE_CXX_FLAGS=-m32 to cmake works even without modification of the project. Commented Feb 27, 2021 at 0:20
  • Thank you for your help..and your patience.Your CMakeLists.txt file seems to be different than mine - and to have different behavior. I downloaded the tarball found on the yaml-cpp-0.6.3 release tag page. That version's 'project' entry looks like: "project(YAML_CPP VERSION 0.6.3)" - which seems to be different than the line you see. I reverted all my changes and then tried to configure using 'cmake -G "Unix Makefiles" -DYAML_BUILD_SHARED_LIBS=ON -DCMAKE_CXX_FLAGS=-m32" - but see the same issue: at least files gtest-all.cpp.o and gmock-all.cc.o did not see the -m32 flag - so the build fails Commented Feb 27, 2021 at 12:21

1 Answer 1

1

With some help from a coworker, I ended up doing the following:

  • top-level CMakeLists.txt file (near line 28, immediately following definition of YAML_BUILD_SHARED_LIBS variable):
  option(YAML_BUILD_32BIT "Build with '-m32'" OFF)

  if(YAML_BUILD_32BIT)
     add_compile_options(-m32)
     add_link_options(-m32)
  endif()
  • in .../test/CMakeLists.txt (near line 10):
  if(YAML_BUILD_32BIT)
    set(GTEST_EXTRA_FLAGS "-DCMAKE_CXX_FLAGS=-m32")
  endif()
  • then add new flag to "ExternalProject_Add(..." call (near line .../test/CMakeLists.txt:22):
ExternalProject_Add(
        googletest_project
        SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.8.0"
        INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/prefix"
        CMAKE_ARGS
                -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
                -DBUILD_GMOCK=ON
                -Dgtest_force_shared_crt=ON
                ${GTEST_EXTRA_FLAGS}  # <- this line added
)

The above has the effect of passing the extra "-m32" flag the embedded gmocktest project.

Given the above changes, the cmake command line above generates something that will build successfully (at least on RHEL-7, with gcc/5.2.0)

Hope this can help somebody else.

Henry

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.